/usr/lib/nodejs/tilelive/lib/statistics.js is in node-tilelive 4.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | module.exports = Statistics;
function Statistics() {
this.history = [];
}
Statistics.unserialize = function(state) {
var statistics = Object.create(Statistics.prototype);
for (var key in state) statistics[key] = state[key];
return statistics;
};
Statistics.prototype = {
total: 0,
pending: 0,
unique: 0,
duplicate: 0,
failed: 0,
skipped: 0,
get remaining() {
return this.total - this.unique - this.duplicate - this.failed - this.skipped;
},
set remaining() {}, // read-only
get processed() {
return this.unique + this.duplicate + this.failed + this.skipped;
},
set processed() {}, // read-only
toJSON: function() {
return {
history: this.history,
total: this.total,
pending: 0,
unique: this.unique,
duplicate: this.duplicate,
failed: this.failed,
skipped: this.skipped
};
},
snapshot: function() {
var now = {
date: Date.now(),
total: this.total,
pending: this.pending,
unique: this.unique,
duplicate: this.duplicate,
failed: this.failed,
skipped: this.skipped,
remaining: this.remaining,
processed: this.processed,
speed: 0
};
// Keep a history of 10 seconds.
this.history.push(now);
while (this.history[0].date < now.date - 10000) this.history.shift();
if (this.history.length >= 2) {
var oldest = this.history[0];
if (now.date > oldest.date) {
now.speed = Math.round((now.processed - oldest.processed) / (now.date - oldest.date) * 1000);
}
}
return now;
}
};
|