mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 15:33:12 +09:00
Fix indents
Fix incorrectly indented code as detected by ESLint.
This commit is contained in:
1 parent
703fda43ad
commit
3e4f0b6b5e
6 files changed
+90
-94
No files matched your search
@@ -189,11 +189,7 @@ JavaScript template literals may also be used where appropriate.
|
|||||||
|
|
||||||
### Indenting
|
### Indenting
|
||||||
|
|
||||||
JavaScript code should be indented with tabs. There are places in the
|
JavaScript code should be indented with tabs.
|
||||||
codebase that are mixing tabs and spaces or uses only spaces for
|
|
||||||
indents. Should you be modifiying such code that is mixing spaces and
|
|
||||||
tabs as indending you should update the indenting to use tabs _on the
|
|
||||||
code you change_ while leaving the rest of the code untouched.
|
|
||||||
|
|
||||||
Lua code should be indented with 4 spaces.
|
Lua code should be indented with 4 spaces.
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const fileOps = require("lib/fileOps");
|
|||||||
|
|
||||||
|
|
||||||
function ellipse(str, max){
|
function ellipse(str, max){
|
||||||
return str.length > (max - 3) ? str.substring(0,max-3) + "..." : str;
|
return str.length > (max - 3) ? str.substring(0,max-3) + "..." : str;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
|
// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
|
||||||
|
|||||||
@@ -17,28 +17,28 @@ const prometheusDoleFactorGauge = new prometheus.Gauge(
|
|||||||
|
|
||||||
class neuralDole {
|
class neuralDole {
|
||||||
|
|
||||||
getRequestStats(itemname,samples)
|
getRequestStats(itemname,samples)
|
||||||
{
|
{
|
||||||
var sum=0;
|
var sum=0;
|
||||||
samples=Math.min(samples,(this.stats[itemname] || []).length-1);
|
samples=Math.min(samples,(this.stats[itemname] || []).length-1);
|
||||||
if (samples<1) return 0.1;
|
if (samples<1) return 0.1;
|
||||||
for (var i = 1; i <= samples; i++) {
|
for (var i = 1; i <= samples; i++) {
|
||||||
sum+=this.stats[itemname][i].req;
|
sum+=this.stats[itemname][i].req;
|
||||||
}
|
}
|
||||||
if (sum==0) return 0.1;
|
if (sum==0) return 0.1;
|
||||||
return sum/samples;
|
return sum/samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
items
|
items
|
||||||
}){
|
}){
|
||||||
// Set some storage variables for the dole divider
|
// Set some storage variables for the dole divider
|
||||||
this.items = items;
|
this.items = items;
|
||||||
this.itemsLastTick = new Map(items._items);
|
this.itemsLastTick = new Map(items._items);
|
||||||
this.dole = {};
|
this.dole = {};
|
||||||
this.carry = {};
|
this.carry = {};
|
||||||
this.lastRequest = {};
|
this.lastRequest = {};
|
||||||
this.stats=[];
|
this.stats=[];
|
||||||
this.debt= {};
|
this.debt= {};
|
||||||
}
|
}
|
||||||
doMagic() {
|
doMagic() {
|
||||||
@@ -58,74 +58,74 @@ class neuralDole {
|
|||||||
prometheusNNDoleGauge.labels(name).set(magicData[1] || 0);
|
prometheusNNDoleGauge.labels(name).set(magicData[1] || 0);
|
||||||
}
|
}
|
||||||
this.itemsLastTick = new Map(this.items._items);
|
this.itemsLastTick = new Map(this.items._items);
|
||||||
}
|
}
|
||||||
divider(object) {
|
divider(object) {
|
||||||
let magicData = doleNN.Dose(
|
let magicData = doleNN.Dose(
|
||||||
object.count, // numReq
|
object.count, // numReq
|
||||||
this.items.getItemCount(object.name),
|
this.items.getItemCount(object.name),
|
||||||
this.itemsLastTick.get(object.name) || 0,
|
this.itemsLastTick.get(object.name) || 0,
|
||||||
this.dole[object.name],
|
this.dole[object.name],
|
||||||
this.carry[object.name+" "+object.instanceID] || 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.getRequestStats(object.name,5),
|
this.getRequestStats(object.name,5),
|
||||||
this.debt[object.name+" "+object.instanceID] || 0
|
this.debt[object.name+" "+object.instanceID] || 0
|
||||||
);
|
);
|
||||||
if ((this.stats[object.name] || []).length>0)
|
if ((this.stats[object.name] || []).length>0)
|
||||||
{
|
{
|
||||||
this.stats[object.name][0].req+=Number(object.count);
|
this.stats[object.name][0].req+=Number(object.count);
|
||||||
this.stats[object.name][0].given+=Number(magicData[0]);
|
this.stats[object.name][0].given+=Number(magicData[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+" "+object.instanceID] = magicData[2];
|
this.carry[object.name+" "+object.instanceID] = magicData[2];
|
||||||
this.debt[object.name+" "+object.instanceID] = magicData[3];
|
this.debt[object.name+" "+object.instanceID] = magicData[3];
|
||||||
|
|
||||||
// Remove item from DB and send it
|
// Remove item from DB and send it
|
||||||
this.items.removeItem(object.name, magicData[0]);
|
this.items.removeItem(object.name, magicData[0]);
|
||||||
|
|
||||||
return magicData[0];
|
return magicData[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the server regularly can't fulfill requests, this number grows until it can. Then it slowly shrinks back down.
|
// If the server regularly can't fulfill requests, this number grows until it can. Then it slowly shrinks back down.
|
||||||
let _doleDivisionFactor = {};
|
let _doleDivisionFactor = {};
|
||||||
function doleDivider({
|
function doleDivider({
|
||||||
object,
|
object,
|
||||||
items,
|
items,
|
||||||
logItemTransfers,
|
logItemTransfers,
|
||||||
}){
|
}){
|
||||||
let itemCount = items.getItemCount(object.name);
|
let itemCount = items.getItemCount(object.name);
|
||||||
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;
|
||||||
object.count /= ((_doleDivisionFactor[object.name]||0)+doleDivisionRetardation)/doleDivisionRetardation;
|
object.count /= ((_doleDivisionFactor[object.name]||0)+doleDivisionRetardation)/doleDivisionRetardation;
|
||||||
object.count = Math.round(object.count);
|
object.count = Math.round(object.count);
|
||||||
if (logItemTransfers) {
|
if (logItemTransfers) {
|
||||||
console.info(`Serving ${object.count}/${originalCount} ${object.name} from ${itemCount} ${object.name} with dole division factor ${(_doleDivisionFactor[object.name]||0)} (real=${((_doleDivisionFactor[object.name]||0)+doleDivisionRetardation)/doleDivisionRetardation}), item is ${itemCount > object.count?"stocked":"short"}.`);
|
console.info(`Serving ${object.count}/${originalCount} ${object.name} from ${itemCount} ${object.name} with dole division factor ${(_doleDivisionFactor[object.name]||0)} (real=${((_doleDivisionFactor[object.name]||0)+doleDivisionRetardation)/doleDivisionRetardation}), item is ${itemCount > object.count?"stocked":"short"}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update existing items if item name already exists
|
// Update existing items if item name already exists
|
||||||
if (itemCount > object.count) {
|
if (itemCount > object.count) {
|
||||||
//If successful, increase dole
|
//If successful, increase dole
|
||||||
_doleDivisionFactor[object.name] = Math.max((_doleDivisionFactor[object.name]||0)||1, 1) - 1;
|
_doleDivisionFactor[object.name] = Math.max((_doleDivisionFactor[object.name]||0)||1, 1) - 1;
|
||||||
items.removeItem(object.name, object.count);
|
items.removeItem(object.name, object.count);
|
||||||
|
|
||||||
prometheusDoleFactorGauge.labels(object.name).set(_doleDivisionFactor[object.name] || 0);
|
prometheusDoleFactorGauge.labels(object.name).set(_doleDivisionFactor[object.name] || 0);
|
||||||
return object.count;
|
return object.count;
|
||||||
} else {
|
} else {
|
||||||
// if we didn't have enough, attempt giving out a smaller amount next time
|
// if we didn't have enough, attempt giving out a smaller amount next time
|
||||||
_doleDivisionFactor[object.name] = Math.min(maxDoleDivision, Math.max((_doleDivisionFactor[object.name]||0)||1, 1) * 2);
|
_doleDivisionFactor[object.name] = Math.min(maxDoleDivision, Math.max((_doleDivisionFactor[object.name]||0)||1, 1) * 2);
|
||||||
prometheusDoleFactorGauge.labels(object.name).set(_doleDivisionFactor[object.name] || 0);
|
prometheusDoleFactorGauge.labels(object.name).set(_doleDivisionFactor[object.name] || 0);
|
||||||
return 0;
|
return 0;
|
||||||
//console.log('failure out of ' + object.name + " | " + object.count + " from " + object.instanceID + " ("+object.instanceName+")");
|
//console.log('failure out of ' + object.name + " | " + object.count + " from " + object.instanceID + " ("+object.instanceName+")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
doleDivider,
|
doleDivider,
|
||||||
neuralDole
|
neuralDole
|
||||||
};
|
};
|
||||||
@@ -56,12 +56,12 @@ function Dose(numreq,instore,store_last_tick,dole,carry,prev_req,numreq_total_ad
|
|||||||
var outputs=[0,0,0,0];
|
var outputs=[0,0,0,0];
|
||||||
//NN: Please don't touch :), code is generated
|
//NN: Please don't touch :), code is generated
|
||||||
|
|
||||||
outputs[0]=inputs[7]*0.8058582544;
|
outputs[0]=inputs[7]*0.8058582544;
|
||||||
outputs[0]=sigmoid2(outputs[0]);
|
outputs[0]=sigmoid2(outputs[0]);
|
||||||
outputs[1]=sigmoid0(outputs[1]);
|
outputs[1]=sigmoid0(outputs[1]);
|
||||||
outputs[2]=sigmoid0(outputs[2]);
|
outputs[2]=sigmoid0(outputs[2]);
|
||||||
outputs[3]=inputs[6]*0.2294657379;
|
outputs[3]=inputs[6]*0.2294657379;
|
||||||
outputs[3]=sigmoid0(outputs[3]);
|
outputs[3]=sigmoid0(outputs[3]);
|
||||||
|
|
||||||
debt=debt || 0;
|
debt=debt || 0;
|
||||||
if (outputs[0]>0.99) outputs[0]=1.0;
|
if (outputs[0]>0.99) outputs[0]=1.0;
|
||||||
@@ -103,11 +103,11 @@ function Tick(instore,dole,store_last_tick,numreq_total_adj)
|
|||||||
var outputs=[0,0];
|
var outputs=[0,0];
|
||||||
//NN: Please don't touch :), code is generated
|
//NN: Please don't touch :), code is generated
|
||||||
|
|
||||||
outputs[0]=inputs[3]*0.9364774823;
|
outputs[0]=inputs[3]*0.9364774823;
|
||||||
outputs[0]=outputs[0]*1.0*0.4590721726;
|
outputs[0]=outputs[0]*1.0*0.4590721726;
|
||||||
outputs[0]=sigmoid2(outputs[0]);
|
outputs[0]=sigmoid2(outputs[0]);
|
||||||
outputs[1]=outputs[0]*1.828422785;
|
outputs[1]=outputs[0]*1.828422785;
|
||||||
outputs[1]=sigmoid3(outputs[1]);
|
outputs[1]=sigmoid3(outputs[1]);
|
||||||
|
|
||||||
avg=outputs[1];
|
avg=outputs[1];
|
||||||
if (numreq_total_adj<0.11) avg=1;//When no item's are requested, result is 0.1 ; In that case there is no deficit, so return 1 = 100% demand fulfilled
|
if (numreq_total_adj<0.11) avg=1;//When no item's are requested, result is 0.1 ; In that case there is no deficit, so return 1 = 100% demand fulfilled
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ function drawcontents(data) {
|
|||||||
data = data || _lastData; //Cache data so we can drawcontents without waiting for the server, for the search box.
|
data = data || _lastData; //Cache data so we can drawcontents without waiting for the server, for the search box.
|
||||||
_lastData = data;
|
_lastData = data;
|
||||||
|
|
||||||
// allow searching for multiple criteria separated by space
|
// allow searching for multiple criteria separated by space
|
||||||
var searchArgs = document.querySelector("#search").value;
|
var searchArgs = document.querySelector("#search").value;
|
||||||
searchArgs = searchArgs.trim();
|
searchArgs = searchArgs.trim();
|
||||||
searchArgs = "(" + searchArgs.replace(/ +/g,")|(") + ")";
|
searchArgs = "(" + searchArgs.replace(/ +/g,")|(") + ")";
|
||||||
const search = new RegExp(searchArgs, "i");
|
const search = new RegExp(searchArgs, "i");
|
||||||
data = data.filter(function(item) {
|
data = data.filter(function(item) {
|
||||||
return search.test(item.name);
|
return search.test(item.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -89,9 +89,9 @@ if(JSON.parse(localStorage.settings)["Periodically update storage screen"]) {
|
|||||||
|
|
||||||
// function to sort arrays of objects after a keys value
|
// function to sort arrays of objects after a keys value
|
||||||
function sortByKey(array, key) {
|
function sortByKey(array, key) {
|
||||||
array.sort(function(a, b) {
|
array.sort(function(a, b) {
|
||||||
return b[key] - a[key];
|
return b[key] - a[key];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector("#search").addEventListener("input", function() {
|
document.querySelector("#search").addEventListener("input", function() {
|
||||||
|
|||||||
+10
-10
@@ -5,14 +5,14 @@ const helpers = require("lib/helpers");
|
|||||||
|
|
||||||
|
|
||||||
describe("lib/helpers", function() {
|
describe("lib/helpers", function() {
|
||||||
describe("basicType()", function() {
|
describe("basicType()", function() {
|
||||||
it("should return the expected values", function() {
|
it("should return the expected values", function() {
|
||||||
assert.equal(helpers.basicType("s"), "string");
|
assert.equal(helpers.basicType("s"), "string");
|
||||||
assert.equal(helpers.basicType(null), "null");
|
assert.equal(helpers.basicType(null), "null");
|
||||||
assert.equal(helpers.basicType(undefined), "undefined");
|
assert.equal(helpers.basicType(undefined), "undefined");
|
||||||
assert.equal(helpers.basicType([1, 2]), "array");
|
assert.equal(helpers.basicType([1, 2]), "array");
|
||||||
assert.equal(helpers.basicType(7), "number");
|
assert.equal(helpers.basicType(7), "number");
|
||||||
assert.equal(helpers.basicType({ a: 1 }), "object");
|
assert.equal(helpers.basicType({ a: 1 }), "object");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user