From fddafaec09a19beb5643a2245cd4f78eae3929f3 Mon Sep 17 00:00:00 2001 From: axapaxa123 <49201376+axapaxa123@users.noreply.github.com> Date: Wed, 3 Apr 2019 14:39:29 +0200 Subject: [PATCH] Update remove.js --- routes/api/remove.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/routes/api/remove.js b/routes/api/remove.js index 23476749..83f334b2 100644 --- a/routes/api/remove.js +++ b/routes/api/remove.js @@ -4,14 +4,17 @@ const doleNN = require("./../../lib/dole_nn_base.js") class neuralDole { constructor({ - items, + items, gauge }){ // Set some storage variables for the dole divider + this.prometheusDoleFactorGauge = gauge this.items = items this.itemsLastTick = JSON.parse(JSON.stringify(items)) this.dole = {} this.carry = {} this.lastRequest = {} + this.doleinfo_last = {} + this.doleinfo_new = {} setInterval(()=>{ for(let name in this.items){ @@ -22,10 +25,15 @@ class neuralDole { let magicData = doleNN.Tick( count, this.dole[name], - this.itemsLastTick[name] + this.itemsLastTick[name], + this.doleinfo_last[name] || {numreq:0 , numslave:0}, + this.doleinfo_new[name] || {numreq:0 , numslave:0} ) this.dole[name] = magicData[0] - // TODO handle magicData[1] for graphing for our users + // DONE handle magicData[1] for graphing for our users + this.prometheusDoleFactorGauge.labels(name).set(magicData[1] || 0); + this.doleinfo_last[name]=this.doleinfo_new[name] + this.doleinfo_new[name]={numreq:0 , numslave:0} } this.itemsLastTick = JSON.parse(JSON.stringify(this.items)) }, 1000) @@ -42,15 +50,20 @@ class neuralDole { this.items[object.name], this.itemsLastTick[object.name] || 0, this.dole[object.name], - this.carry[object.name] || 0, - this.lastRequest[object.name+"_"+object.instanceID+"_"+object.instanceName] || 0 + this.carry[object.name+" "+object.instanceID] || 0, + this.lastRequest[object.name+"_"+object.instanceID+"_"+object.instanceName] || 0, + this.doleinfo_last[object.name] || {numreq:0 , numslave:0} ) this.lastRequest[object.name+"_"+object.instanceID+"_"+object.instanceName] = object.count //0.Number of items to give in that dose //1.New dole for item X //2.New carry for item X slave Y this.dole[object.name] = magicData[1] - this.carry[object.name] = magicData[2] + this.carry[object.name+" "+object.instanceID] = magicData[2] + + this.doleinfo_new[object.name].numreq=magicData[0] + (this.doleinfo_new[object.name].numreq || 0) + this.doleinfo_new[object.name].numslave=1 + (this.doleinfo_new[object.name].numslave || 0) + // Remove item from DB and send it if(this.items.removeItem({count: magicData[0], name: object.name})){ if(config.logItemTransfers){ @@ -96,7 +109,7 @@ function doleDivider({ prometheusImportGauge, req,res, }){ - const doleDivisionRetardation = 10; //lower rates will equal more dramatic swings + const doleDivisionRetardation = 10; //lower rates will equal more dramatic swings const maxDoleDivision = 250; //a higher cap will divide the store more ways, but will take longer to recover as supplies increase const originalCount = Number(object.count) || 0; @@ -143,4 +156,4 @@ function doleDivider({ module.exports = { doleDivider, neuralDole -} \ No newline at end of file +}