123 lines
3.1 KiB
JavaScript
123 lines
3.1 KiB
JavaScript
/** @import DBTypes from "./types.d.ts" */
|
|
import DB from "./db.js";
|
|
|
|
/** @type {DBTypes.Builder} */
|
|
function DBBuilder(params)
|
|
{
|
|
return {
|
|
list:{},
|
|
load(){
|
|
const l = this.list;
|
|
const loader =(id, data)=>l[id] = data;
|
|
return DB(import.meta.resolve(params.path), params.cols, (...args)=>{
|
|
|
|
params.load(loader, ...args);
|
|
});
|
|
},
|
|
save(){},
|
|
};
|
|
}
|
|
|
|
const parts = DBBuilder({
|
|
path:"./db_part.csv",
|
|
cols:2,
|
|
load:(commit, id, name)=>commit(id, {name}),
|
|
save:(commit, params)=> commit("a", params.name)
|
|
});
|
|
|
|
await parts.load();
|
|
console.log(parts.list);
|
|
|
|
|
|
|
|
// // 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);
|