93 lines
2.3 KiB
JavaScript
93 lines
2.3 KiB
JavaScript
import DB from "./db.js";
|
|
|
|
// build parts
|
|
const Part = {};
|
|
function CreatePart(id, name)
|
|
{
|
|
const part = {name, _:{id, time:0, work:[], need:[], make:[]}};
|
|
Part[id] = part;
|
|
return part;
|
|
}
|
|
await DB(import.meta.resolve('./db_part.csv'), 2, CreatePart);
|
|
|
|
|
|
// then build work
|
|
const Work = [];
|
|
function CreateWork(partId, user, time, data)
|
|
{
|
|
const part = Part[partId];
|
|
const work = {user: user, time, data}
|
|
part._.work.push(work);
|
|
if(time > part._.time)
|
|
{
|
|
part._.time = time;
|
|
}
|
|
Work.push(work);
|
|
return work;
|
|
}
|
|
await DB(import.meta.resolve('./db_work.csv'), 3, CreateWork);
|
|
|
|
|
|
// then build desks
|
|
const Desk = {};
|
|
/** @type {(need:string[], make:string[])=>[dirtyNeed:string[], dirtyMake:string[], needMax:number, needMin:number]} */
|
|
const Range =(need, make)=>
|
|
{
|
|
const dirtyNeed = [];
|
|
const dirtyMake = [];
|
|
|
|
let makeMin = Infinity;
|
|
let needMax = -Infinity;
|
|
need.forEach(partId => {
|
|
const part = Part[partId];
|
|
if(part._.time > needMax) needMax = part._.time;
|
|
});
|
|
|
|
make.forEach(partId => {
|
|
const part = Part[partId];
|
|
if(part._.time < makeMin) makeMin = part._.time;
|
|
if(part._.time < needMax)
|
|
{
|
|
dirtyMake.push(partId);
|
|
}
|
|
});
|
|
|
|
need.forEach(partId => {
|
|
const part = Part[partId];
|
|
if(part._.time > makeMin)
|
|
{
|
|
dirtyNeed.push(partId);
|
|
}
|
|
});
|
|
|
|
return [dirtyNeed, dirtyMake, needMax, makeMin];
|
|
};
|
|
|
|
/** @typedef {[need:Record<string, number]>, make:string[], mode:"one"|"all", role:string[]} StoredDesk */
|
|
|
|
/** @type {(id:string, name:string, data:StoredDesk)=>void} */
|
|
function CreateDesk(id, name, data, role, need, time, make, mode="one")
|
|
{
|
|
const need = Object.keys(data[0])
|
|
const time = Object.values(data[0]);
|
|
const desk = {name, need, time, make, role, _:{id}};
|
|
Desk[id] = desk;
|
|
need.forEach(partId => Part[partId]._.need.push(desk));
|
|
make.forEach(partId => Part[partId]._.make.push(desk));
|
|
|
|
const check = Range(need, make);
|
|
console.log(check);
|
|
|
|
return desk;
|
|
}
|
|
|
|
await DB(import.meta.resolve('./db_work.csv'), 3, (id, name, /**@type{StoredDesk}*/data)=>{
|
|
|
|
const need = Object.keys(data[0])
|
|
CreateDesk(id, name, need, data[1], );
|
|
});
|
|
|
|
|
|
|
|
console.log(Part);
|
|
console.log(Desk); |