Better job requests

This commit is contained in:
Robert Bendun 2021-04-26 21:37:29 +02:00
parent 62a761d270
commit d00a867f5f

View File

@ -19,7 +19,7 @@ class Products {
gridProductsAmountColumn.push(''); gridProductsAmountColumn.push('');
} }
} }
this.gridProducts.push(gridProductsColumn); this.gridProducts.push(gridProductsColumn);
this.gridProductsAmount.push(gridProductsAmountColumn); this.gridProductsAmount.push(gridProductsAmountColumn);
} }
@ -34,7 +34,7 @@ class Products {
setCanvasSize (canvas) { setCanvasSize (canvas) {
canvas.width = 2000; canvas.width = 2000;
canvas.height = 900; canvas.height = 900;
} }
update(){ update(){
this.clearCanvas(); this.clearCanvas();
@ -46,7 +46,7 @@ class Products {
for (let [y, type] of line.entries()) { for (let [y, type] of line.entries()) {
if (type === GRID_FIELD_TYPE.SHELF) { if (type === GRID_FIELD_TYPE.SHELF) {
let v = this.drawValue(x, y); let v = this.drawValue(x, y);
this.product(x * 100, y * 100, v, x, y); this.product(x * 100, y * 100, v, x, y);
} }
} }
} }
@ -66,7 +66,7 @@ class Products {
let fontSize = 40; let fontSize = 40;
this.ctx.font = `900 ${fontSize}px "Font Awesome 5 Free"`; this.ctx.font = `900 ${fontSize}px "Font Awesome 5 Free"`;
this.ctx.textAlign = "center"; this.ctx.textAlign = "center";
// make color of icon on white -> red spectrum, where // make color of icon on white -> red spectrum, where
// white - full shelf // white - full shelf
// red - empty shelf // red - empty shelf
@ -74,7 +74,7 @@ class Products {
let color = Math.floor(t(v / 50) * 255).toString(16) let color = Math.floor(t(v / 50) * 255).toString(16)
if (color.length == 1) if (color.length == 1)
color = "0" + color color = "0" + color
this.ctx.fillStyle = `#ff${color}${color}`; this.ctx.fillStyle = `#ff${color}${color}`;
let productsColumn = this.gridProducts[productsKey]; let productsColumn = this.gridProducts[productsKey];
let prdct = productsColumn[productsValue]; let prdct = productsColumn[productsValue];
@ -82,11 +82,11 @@ class Products {
this.ctx.textAlign = 'center'; this.ctx.textAlign = 'center';
this.ctx.fillText(prdct.icon, x+50, y+60); this.ctx.fillText(prdct.icon, x+50, y+60);
} }
clearCanvas() { clearCanvas() {
this.ctx.clearRect(0, 0, 2000, 900); this.ctx.clearRect(0, 0, 2000, 900);
} }
getProductAt(x, y) { getProductAt(x, y) {
return { return {
item: this.gridProducts[x][y], item: this.gridProducts[x][y],
@ -95,9 +95,9 @@ class Products {
} }
/** /**
* *
* @param {(product: Product, amount: number, i: number, j: number, end: () => bool) => bool} filter * @param {(product: Product, amount: number, i: number, j: number, end: () => bool) => bool} filter
* @returns * @returns
*/ */
filter(filter) { filter(filter) {
const list = [] const list = []
@ -108,7 +108,7 @@ class Products {
const product = this.gridProducts[i][j] const product = this.gridProducts[i][j]
const amount = this.gridProductsAmount[i][j] const amount = this.gridProductsAmount[i][j]
if (typeof(product) !== 'string' if (typeof(product) !== 'string'
&& filter(product, amount, i, j, end)) { && filter(product, amount, i, j, end)) {
list.push({ product, amount: Number(amount), x: i, y: j }) list.push({ product, amount: Number(amount), x: i, y: j })
} }
@ -121,8 +121,8 @@ class Products {
} }
/** /**
* @param {Product} incomingProduct * @param {Product} incomingProduct
* @param {number} incomingAmount * @param {number} incomingAmount
* @returns {{product: Product; amount: number} | null } Old shelf content * @returns {{product: Product; amount: number} | null } Old shelf content
*/ */
exchange(x, y, incomingProduct, incomingAmount) { exchange(x, y, incomingProduct, incomingAmount) {
@ -151,11 +151,14 @@ class Products {
} }
getJobRequest() { getJobRequest() {
const maybeProduct = this.filter((_product, amount, _i, _j, end) => amount < 50 && end(true)) const maybeProduct = this.filter((_product, amount, _i, _j, end) => amount < 50).sort((a, b) => {
return a.amount - b.amount
})
console.log(maybeProduct);
return maybeProduct.length === 0 ? null : maybeProduct[0] return maybeProduct.length === 0 ? null : maybeProduct[0]
} }
findAvailableLocationsFor(product) { findAvailableLocationsFor(product) {
return this.filter((p, amount) => product.equals(p) && amount < 50) return this.filter((p, amount) => product.equals(p) && amount < 50)
} }
} }