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