make getMaxGraphDataLength/getMaxServerGraphDataLength methods static
This commit is contained in:
parent
3491c73b89
commit
024e605a41
@ -69,8 +69,8 @@ class App {
|
||||
// Send configuration data for rendering the page
|
||||
return {
|
||||
graphDurationLabel: config.graphDurationLabel || (Math.floor(config.graphDuration / (60 * 60 * 1000)) + 'h'),
|
||||
graphMaxLength: this.pingController.getMaxGraphDataLength(),
|
||||
serverGraphMaxLength: this.pingController.getMaxServerGraphDataLength(),
|
||||
graphMaxLength: TimeTracker.getMaxGraphDataLength(),
|
||||
serverGraphMaxLength: TimeTracker.getMaxServerGraphDataLength(),
|
||||
servers: this.serverRegistrations.map(serverRegistration => serverRegistration.data),
|
||||
minecraftVersions: minecraftVersionNames,
|
||||
isGraphVisible: config.logToDatabase
|
||||
|
@ -151,14 +151,6 @@ class PingController {
|
||||
}, version.protocolId)
|
||||
}
|
||||
}
|
||||
|
||||
getMaxServerGraphDataLength () {
|
||||
return Math.ceil(config.serverGraphDuration / config.rates.pingAll)
|
||||
}
|
||||
|
||||
getMaxGraphDataLength () {
|
||||
return Math.ceil(config.graphDuration / config.rates.pingAll)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PingController
|
||||
|
@ -1,3 +1,5 @@
|
||||
const TimeTracker = require('./time')
|
||||
|
||||
const config = require('../config')
|
||||
const minecraftVersions = require('../minecraft_versions')
|
||||
|
||||
@ -8,8 +10,7 @@ class ServerRegistration {
|
||||
recordData
|
||||
graphData = []
|
||||
|
||||
constructor (app, serverId, data) {
|
||||
this._app = app
|
||||
constructor (serverId, data) {
|
||||
this.serverId = serverId
|
||||
this.data = data
|
||||
this._pingHistory = []
|
||||
@ -22,7 +23,7 @@ class ServerRegistration {
|
||||
this._pingHistory.push(playerCount)
|
||||
|
||||
// Trim pingHistory to avoid memory leaks
|
||||
if (this._pingHistory.length > this._app.pingController.getMaxServerGraphDataLength()) {
|
||||
if (this._pingHistory.length > TimeTracker.getMaxServerGraphDataLength()) {
|
||||
this._pingHistory.shift()
|
||||
}
|
||||
|
||||
@ -178,7 +179,7 @@ class ServerRegistration {
|
||||
this._lastGraphDataPush = timestamp
|
||||
|
||||
// Trim old graphPoints according to #getMaxGraphDataLength
|
||||
if (this.graphData.length > this._app.pingController.getMaxGraphDataLength()) {
|
||||
if (this.graphData.length > TimeTracker.getMaxGraphDataLength()) {
|
||||
this.graphData.shift()
|
||||
}
|
||||
|
||||
|
12
lib/time.js
12
lib/time.js
@ -1,3 +1,5 @@
|
||||
const config = require('../config.json')
|
||||
|
||||
class TimeTracker {
|
||||
constructor (app) {
|
||||
this._app = app
|
||||
@ -9,7 +11,7 @@ class TimeTracker {
|
||||
|
||||
this._points.push(timestamp)
|
||||
|
||||
if (this._points.length > this._app.pingController.getMaxServerGraphDataLength()) {
|
||||
if (this._points.length > TimeTracker.getMaxServerGraphDataLength()) {
|
||||
this._points.shift()
|
||||
}
|
||||
|
||||
@ -19,6 +21,14 @@ class TimeTracker {
|
||||
getPoints () {
|
||||
return this._points
|
||||
}
|
||||
|
||||
static getMaxServerGraphDataLength () {
|
||||
return Math.ceil(config.serverGraphDuration / config.rates.pingAll)
|
||||
}
|
||||
|
||||
static getMaxGraphDataLength () {
|
||||
return Math.ceil(config.graphDuration / config.rates.pingAll)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TimeTracker
|
||||
|
2
main.js
2
main.js
@ -22,7 +22,7 @@ servers.forEach((server, serverId) => {
|
||||
}
|
||||
|
||||
// Init a ServerRegistration instance of each entry in servers.json
|
||||
app.serverRegistrations.push(new ServerRegistration(app, serverId, server))
|
||||
app.serverRegistrations.push(new ServerRegistration(serverId, server))
|
||||
})
|
||||
|
||||
if (!config.serverGraphDuration) {
|
||||
|
Loading…
Reference in New Issue
Block a user