cleanup
This commit is contained in:
parent
8fde0f73c5
commit
39c9ccdf01
210
app.js
210
app.js
@ -1,123 +1,105 @@
|
|||||||
/** @import DBTypes from "./types.d.ts" */
|
|
||||||
import DB from "./db.js";
|
import DB from "./db.js";
|
||||||
|
|
||||||
/** @type {DBTypes.Builder} */
|
/** @typedef {{name:string, time:number, work:WorkData[], need:string[], make:string[]}} PartData */
|
||||||
function DBBuilder(params)
|
const Part = DB({
|
||||||
{
|
|
||||||
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",
|
path:"./db_part.csv",
|
||||||
cols:2,
|
cols:2,
|
||||||
load:(commit, id, name)=>commit(id, {name}),
|
load:(_i, id, name)=>[id, /**@type{PartData}*/({
|
||||||
save:(commit, params)=> commit("a", params.name)
|
name,
|
||||||
|
time:0,
|
||||||
|
work:[],
|
||||||
|
need:[],
|
||||||
|
make:[]
|
||||||
|
})],
|
||||||
});
|
});
|
||||||
|
|
||||||
await parts.load();
|
/**@typedef {{part:string, user:string, time:number, data:string}} WorkData*/
|
||||||
console.log(parts.list);
|
const Work = DB({
|
||||||
|
path:"./db_work.csv",
|
||||||
|
cols:4,
|
||||||
|
load(_i, part, user, time, data)
|
||||||
|
{
|
||||||
|
const parsedTime = parseInt(time);
|
||||||
|
/** @type {WorkData} */
|
||||||
|
const workObj = {part, user, time:parsedTime, data};
|
||||||
|
const partObj = Part.list[part];
|
||||||
|
if(parsedTime > partObj.time)
|
||||||
|
{
|
||||||
|
partObj.time = parsedTime;
|
||||||
|
partObj.work.unshift(workObj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
partObj.work.push(workObj);
|
||||||
|
}
|
||||||
|
return ["", workObj];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @typedef {"all"|"one"} DeskMode*/
|
||||||
|
/** @typedef {[need:Record<string, number>, make:string[], ...role:string[]]} DeskJSON */
|
||||||
|
/** @typedef {{name:string, mode:DeskMode, need:Record<string, number>, make:string[], role:string[]}} DeskData */
|
||||||
|
/** @type {(desk:DeskData)=>[dirtyNeed:string[], dirtyMake:string[]]} */
|
||||||
|
const Scan =(desk)=>
|
||||||
|
{
|
||||||
|
const need = Object.keys(desk.need);
|
||||||
|
const make = desk.make;
|
||||||
|
|
||||||
|
const dirtyNeed = [];
|
||||||
|
const dirtyMake = [];
|
||||||
|
|
||||||
// // build parts
|
let makeMin = Infinity;
|
||||||
// const Part = {};
|
let needMax = -Infinity;
|
||||||
// function CreatePart(id, name)
|
|
||||||
// {
|
for(let i=0; i<need.length; i++)
|
||||||
// const part = {name, _:{id, time:0, work:[], need:[], make:[]}};
|
{
|
||||||
// Part[id] = part;
|
const id = need[i];
|
||||||
// return part;
|
const part = Part.find(id);
|
||||||
// }
|
if(part.time > needMax) needMax = part.time;
|
||||||
// await DB(import.meta.resolve('./db_part.csv'), 2, CreatePart);
|
}
|
||||||
//
|
|
||||||
//
|
for(let i=0; i<make.length; i++)
|
||||||
// // then build work
|
{
|
||||||
// const Work = [];
|
const id = make[i];
|
||||||
// function CreateWork(partId, user, time, data)
|
const part = Part.find(make[i]);
|
||||||
// {
|
if(part.time < makeMin) makeMin = part.time;
|
||||||
// const part = Part[partId];
|
if(part.time < needMax)
|
||||||
// const work = {user: user, time, data}
|
{
|
||||||
// part._.work.push(work);
|
dirtyMake.push(id);
|
||||||
// if(time > part._.time)
|
}
|
||||||
// {
|
}
|
||||||
// part._.time = time;
|
|
||||||
// }
|
for(let i=0; i<need.length; i++)
|
||||||
// Work.push(work);
|
{
|
||||||
// return work;
|
const id = need[i];
|
||||||
// }
|
const part = Part.find(id);
|
||||||
// await DB(import.meta.resolve('./db_work.csv'), 3, CreateWork);
|
if(part.time > makeMin)
|
||||||
//
|
{
|
||||||
//
|
dirtyNeed.push(id);
|
||||||
// // then build desks
|
}
|
||||||
// const Desk = {};
|
}
|
||||||
// /** @type {(need:string[], make:string[])=>[dirtyNeed:string[], dirtyMake:string[], needMax:number, needMin:number]} */
|
|
||||||
// const Range =(need, make)=>
|
return [dirtyNeed, dirtyMake];
|
||||||
// {
|
};
|
||||||
// const dirtyNeed = [];
|
const Desk = DB({
|
||||||
// const dirtyMake = [];
|
path:"./db_desk.csv",
|
||||||
//
|
cols:4,
|
||||||
// let makeMin = Infinity;
|
load(_i, id, name, /** @type {DeskMode}*/mode, data)
|
||||||
// let needMax = -Infinity;
|
{
|
||||||
// need.forEach(partId => {
|
/**@type {DeskJSON} */
|
||||||
// const part = Part[partId];
|
const [need, make, ...role] = JSON.parse(data);
|
||||||
// if(part._.time > needMax) needMax = part._.time;
|
const deskObj = { name, mode, need, make, role };
|
||||||
// });
|
|
||||||
//
|
make.forEach(partId=>Part.find(partId).make.push(id));
|
||||||
// make.forEach(partId => {
|
Object.keys(need).forEach(partId=>Part.find(partId).need.push(id));
|
||||||
// const part = Part[partId];
|
|
||||||
// if(part._.time < makeMin) makeMin = part._.time;
|
const check = Scan(deskObj);
|
||||||
// if(part._.time < needMax)
|
console.log(check);
|
||||||
// {
|
|
||||||
// dirtyMake.push(partId);
|
return [id, deskObj];
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// need.forEach(partId => {
|
await Part.load();
|
||||||
// const part = Part[partId];
|
await Work.load();
|
||||||
// if(part._.time > makeMin)
|
await Desk.load();
|
||||||
// {
|
|
||||||
// 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);
|
|
||||||
|
|||||||
26
db.js
26
db.js
@ -12,7 +12,7 @@ function createCSVScanner(onRow, cols) {
|
|||||||
let start = 0;
|
let start = 0;
|
||||||
let col = 0;
|
let col = 0;
|
||||||
for (let i = 0; i < line.length; i++) {
|
for (let i = 0; i < line.length; i++) {
|
||||||
if (line[i] === ',' && col < cols) {
|
if (line[i] === ',' && col < cols-1) {
|
||||||
fields.push(line.slice(start, i));
|
fields.push(line.slice(start, i));
|
||||||
start = i + 1;
|
start = i + 1;
|
||||||
col++;
|
col++;
|
||||||
@ -25,7 +25,7 @@ function createCSVScanner(onRow, cols) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function(url, nonJsonCols, onRow) {
|
async function DB(url, cols, onRow) {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@ -35,7 +35,7 @@ export default async function(url, nonJsonCols, onRow) {
|
|||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
const decoder = new TextDecoder("utf-8");
|
const decoder = new TextDecoder("utf-8");
|
||||||
|
|
||||||
const scanner = createCSVScanner(onRow, nonJsonCols);
|
const scanner = createCSVScanner(onRow, cols);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -45,3 +45,23 @@ export default async function(url, nonJsonCols, onRow) {
|
|||||||
scanner(chunk);
|
scanner(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @import DBTypes from "./types.d.ts" */
|
||||||
|
/** @type {DBTypes.Builder} */
|
||||||
|
export default function(params)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
list:{},
|
||||||
|
load(){
|
||||||
|
let index = 0;
|
||||||
|
this.list = {};
|
||||||
|
return DB(import.meta.resolve(params.path), params.cols, (...args)=>{
|
||||||
|
const [id, data] = params.load(index, ...args);
|
||||||
|
id && (this.list[id] = data);
|
||||||
|
index++;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
find(id){return this.list[id];},
|
||||||
|
save(){},
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -1 +1 @@
|
|||||||
d1,Desk One,[{"p1":1, "p2":1}, ["p3"], "all", ["r1"]]
|
d1,Desk One,all,[{"p1":1, "p2":1},["p3"],"r1"]
|
||||||
|
|||||||
|
Can't render this file because it contains an unexpected character in line 1 and column 15.
|
5
types.d.ts
vendored
5
types.d.ts
vendored
@ -6,10 +6,11 @@ export type Builder = <Count extends number, Loaded, Sized extends Row<Count>>(p
|
|||||||
{
|
{
|
||||||
path:string,
|
path:string,
|
||||||
cols:Count,
|
cols:Count,
|
||||||
load:(commitLoad:(id:string, data:Loaded)=>Sized, ...args:Sized)=>[id:string, data:Loaded],
|
load:(index:number, ...args:Sized)=>[id:string, data:Loaded],
|
||||||
save:(commitSave:(...args:Sized)=>Sized, internal:Loaded) => Sized
|
//save:(commitSave:(...args:Sized)=>Sized, id:string, data:Loaded) => Sized
|
||||||
}) => {
|
}) => {
|
||||||
list:Record<string, Loaded>,
|
list:Record<string, Loaded>,
|
||||||
|
find:(id:string)=>Loaded,
|
||||||
load:()=>Promise<void>,
|
load:()=>Promise<void>,
|
||||||
save:()=>Promise<void>
|
save:()=>Promise<void>
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user