-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.stat.js
56 lines (47 loc) · 1.51 KB
/
util.stat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports.thing = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('util.stat');
* mod.thing == 'a thing'; // true
*/
var logger = require("screeps.logger");
logger = new logger("util.stat");
class stat {
constructor(shortWeight = .9, longWeight = .99) {
this.longAvg = false;
this.shortAvg = false;
this.min = false;
this.max = false;
this._current = 0;
this.shortWeight = shortWeight;
this.longWeight = longWeight;
}
get current() {
return this._current;
}
set current(value) {
this._current = value;
if (this.longAvg === false) {
this.longAvg = this._current;
}
if (this.shortAvg === false) {
this.shortAvg = this._current;
}
if (this.min === false) {
this.min = this._current;
}
if (this.max === false) {
this.max = this._current;
}
this.longAvg = this.longAvg * (this.longWeight) + this._current * (1 - this.longWeight);
this.shortAvg = this.shortAvg * (this.shortWeight) + this._current * (1 - this.shortWeight);
this.min = Math.min(this.min, this._current);
this.max = Math.max(this.max, this._current);
}
toString() {
return `sAvg:${this.shortAvg} lAvg:${this.longAvg} min:${this.min} max:${this.max}`;
}
}
module.exports = stat;