mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 07:33:12 +09:00
Update remove.js
This commit is contained in:
1 parent
abf4b5d926
commit
fddafaec09
1 file changed
+21
-8
+21
-8
@@ -4,14 +4,17 @@ const doleNN = require("./../../lib/dole_nn_base.js")
|
|||||||
|
|
||||||
class neuralDole {
|
class neuralDole {
|
||||||
constructor({
|
constructor({
|
||||||
items,
|
items, gauge
|
||||||
}){
|
}){
|
||||||
// Set some storage variables for the dole divider
|
// Set some storage variables for the dole divider
|
||||||
|
this.prometheusDoleFactorGauge = gauge
|
||||||
this.items = items
|
this.items = items
|
||||||
this.itemsLastTick = JSON.parse(JSON.stringify(items))
|
this.itemsLastTick = JSON.parse(JSON.stringify(items))
|
||||||
this.dole = {}
|
this.dole = {}
|
||||||
this.carry = {}
|
this.carry = {}
|
||||||
this.lastRequest = {}
|
this.lastRequest = {}
|
||||||
|
this.doleinfo_last = {}
|
||||||
|
this.doleinfo_new = {}
|
||||||
|
|
||||||
setInterval(()=>{
|
setInterval(()=>{
|
||||||
for(let name in this.items){
|
for(let name in this.items){
|
||||||
@@ -22,10 +25,15 @@ class neuralDole {
|
|||||||
let magicData = doleNN.Tick(
|
let magicData = doleNN.Tick(
|
||||||
count,
|
count,
|
||||||
this.dole[name],
|
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]
|
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))
|
this.itemsLastTick = JSON.parse(JSON.stringify(this.items))
|
||||||
}, 1000)
|
}, 1000)
|
||||||
@@ -42,15 +50,20 @@ class neuralDole {
|
|||||||
this.items[object.name],
|
this.items[object.name],
|
||||||
this.itemsLastTick[object.name] || 0,
|
this.itemsLastTick[object.name] || 0,
|
||||||
this.dole[object.name],
|
this.dole[object.name],
|
||||||
this.carry[object.name] || 0,
|
this.carry[object.name+" "+object.instanceID] || 0,
|
||||||
this.lastRequest[object.name+"_"+object.instanceID+"_"+object.instanceName] || 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
|
this.lastRequest[object.name+"_"+object.instanceID+"_"+object.instanceName] = object.count
|
||||||
//0.Number of items to give in that dose
|
//0.Number of items to give in that dose
|
||||||
//1.New dole for item X
|
//1.New dole for item X
|
||||||
//2.New carry for item X slave Y
|
//2.New carry for item X slave Y
|
||||||
this.dole[object.name] = magicData[1]
|
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
|
// Remove item from DB and send it
|
||||||
if(this.items.removeItem({count: magicData[0], name: object.name})){
|
if(this.items.removeItem({count: magicData[0], name: object.name})){
|
||||||
if(config.logItemTransfers){
|
if(config.logItemTransfers){
|
||||||
@@ -96,7 +109,7 @@ function doleDivider({
|
|||||||
prometheusImportGauge,
|
prometheusImportGauge,
|
||||||
req,res,
|
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 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;
|
const originalCount = Number(object.count) || 0;
|
||||||
@@ -143,4 +156,4 @@ function doleDivider({
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
doleDivider,
|
doleDivider,
|
||||||
neuralDole
|
neuralDole
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user