src/App.js
c6a95b0d
 import React, { PureComponent } from 'react';
22f488a7
 import Form from './components/Form';
c6a95b0d
 import Gantt from './components/Gantt';
 import { normalizeData } from './ganttUtils';
b681b265
 import algorithms from './algorithms';
 import { filter, flatten, identity, map, pluck, range, times } from 'rambda';
 import uuid from 'uuid/v4';
 import { selectAlgorithms, fastestResult, najneomeskanejsiResult } from './selectAlgorithm';
b49dd3ef
 
c6a95b0d
 class App extends PureComponent {
b681b265
   state = { ganttData: null };
 
8c7841d1
   onFormSubmit = ({ preempt, flowShop, rows }) => {
     const algorithmNames = selectAlgorithms(rows, preempt, flowShop == '1');
b681b265
 
     if (!algorithmNames) {
       alert('Pre zvolenú konfiguráciu sa nenašiel vhodný algoritmus');
       return;
     }
 
8c7841d1
     console.log(algorithmNames);
 
b681b265
     const results = map(algorithmName => {
       const algorithm = algorithms[algorithmName];
 
       let jobTimes;
 
       if (algorithmName === 'johnson' || algorithmName === 'palmer' || algorithmName === 'grupt' || algorithmName === 'campbel') {
         jobTimes = times(i => ({
           jobId: uuid(),
8c7841d1
           operations: map(j =>
             rows[j].jobs[i] ? {
               t: rows[j].jobs[i].t,
               name: rows[j].jobs[i].name
             } : undefined, range(0, rows.length)
           )
b681b265
         }), rows[0].jobs.length);
       } else if (algorithmName === 'mcnaught' || algorithmName === 'vahy') {
         jobTimes = flatten(pluck('jobs', rows));
         jobTimes = map(jobTime => ({
           ...jobTime,
           jobId: jobTime.id,
           anc: map(anc => anc.split(':')[1], jobTime.anc || []) }), jobTimes);
       } else {
         jobTimes = map(job => ({
           jobId: job.id,
           t: +job.t,
           d: +job.d,
           w: +job.w,
           name: job.name,
           anc: map(anc => anc.split(':')[1], job.anc || [])
         }), rows[0].jobs);
       }
 
       // console.log(jobTimes);
       // return;
 
       // console.log(rows[1].jobs);
 
       const result = algorithm(jobTimes, rows.length);
8c7841d1
       console.log(result);
b681b265
       return result;
     }, algorithmNames);
 
     const validResults = filter(identity, results);
     const fastestIndex = rows.length === 1
       ? najneomeskanejsiResult(validResults)
       : fastestResult(validResults);
 
     if (fastestIndex === -1) {
       alert('Nepodarilo sa násť rozvrh pre zvolenú konfiguráciu');
       return;
     }
 
     // console.log(fastestIndex, validResults);
 
     const ganttData = normalizeData(validResults[fastestIndex]);
 
8c7841d1
     // console.log(validResults[fastestIndex]);
b681b265
 
     this.setState({
       ganttData
     });
   };
 
b49dd3ef
   render() {
b681b265
     const { ganttData } = this.state;
 
b49dd3ef
     return (
c6a95b0d
       <div style={{ padding: 20 }}>
b681b265
         <Form onSubmit={this.onFormSubmit} />
         {ganttData && <Gantt data={ganttData}/>}
b49dd3ef
       </div>
     );
   }
 }
 
 export default App;