2020-05-08 07:56:39 +00:00
|
|
|
const config = require('../config.json')
|
|
|
|
|
2020-05-08 06:22:07 +00:00
|
|
|
class TimeTracker {
|
2020-05-08 06:54:04 +00:00
|
|
|
constructor (app) {
|
|
|
|
this._app = app
|
2020-05-08 06:22:07 +00:00
|
|
|
this._points = []
|
|
|
|
}
|
|
|
|
|
|
|
|
newTimestamp () {
|
|
|
|
const timestamp = new Date().getTime()
|
|
|
|
|
|
|
|
this._points.push(timestamp)
|
|
|
|
|
2020-05-08 07:56:39 +00:00
|
|
|
if (this._points.length > TimeTracker.getMaxServerGraphDataLength()) {
|
2020-05-08 06:22:07 +00:00
|
|
|
this._points.shift()
|
|
|
|
}
|
|
|
|
|
|
|
|
return timestamp
|
|
|
|
}
|
|
|
|
|
2020-05-11 09:12:46 +00:00
|
|
|
getPointsSeconds () {
|
|
|
|
return this._points.map(value => Math.floor(value / 1000))
|
2020-05-08 06:22:07 +00:00
|
|
|
}
|
2020-05-08 07:56:39 +00:00
|
|
|
|
|
|
|
static getMaxServerGraphDataLength () {
|
|
|
|
return Math.ceil(config.serverGraphDuration / config.rates.pingAll)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getMaxGraphDataLength () {
|
|
|
|
return Math.ceil(config.graphDuration / config.rates.pingAll)
|
|
|
|
}
|
2020-05-08 06:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = TimeTracker
|