merge graph timestamps into single array, use seconds

This commit is contained in:
Nick Krecklow
2020-05-11 04:12:46 -05:00
parent ef0c41ee1d
commit 84004f22be
9 changed files with 64 additions and 100 deletions

View File

@ -20,7 +20,7 @@ class ServerRegistration {
this._pingHistory = []
}
handlePing (timestamp, resp, err, version) {
handlePing (timestamp, resp, err, version, updateHistoryGraph) {
// Use null to represent a failed ping
const playerCount = resp ? resp.players.online : null
@ -35,19 +35,21 @@ class ServerRegistration {
// Only notify the frontend to append to the historical graph
// if both the graphing behavior is enabled and the backend agrees
// that the ping is eligible for addition
let updateHistoryGraph = false
if (updateHistoryGraph) {
// FIXME: update schema, remove timestamp
this.graphData.push([timestamp, playerCount])
if (config.logToDatabase) {
if (this.addGraphPoint(playerCount, timestamp)) {
updateHistoryGraph = true
// Trim old graphPoints according to #getMaxGraphDataLength
if (this.graphData.length > TimeTracker.getMaxGraphDataLength()) {
this.graphData.shift()
}
}
// Delegate out update payload generation
return this.getUpdate(timestamp, resp, err, version, updateHistoryGraph)
return this.getUpdate(timestamp, resp, err, version)
}
getUpdate (timestamp, resp, err, version, updateHistoryGraph) {
getUpdate (timestamp, resp, err, version) {
const update = {}
if (resp) {
@ -59,7 +61,7 @@ class ServerRegistration {
if (config.logToDatabase && (!this.recordData || resp.players.online > this.recordData.playerCount)) {
this.recordData = {
playerCount: resp.players.online,
timestamp: timestamp
timestamp: Math.floor(timestamp / 1000)
}
// Append an updated recordData
@ -80,12 +82,6 @@ class ServerRegistration {
if (this.findNewGraphPeak()) {
update.graphPeakData = this.getGraphPeak()
}
// Handled inside logToDatabase to validate logic from #getUpdate call
// Only append when true since an undefined value == false
if (updateHistoryGraph) {
update.updateHistoryGraph = true
}
}
} else if (err) {
// Append a filtered copy of err
@ -155,18 +151,6 @@ class ServerRegistration {
}
}
addGraphPoint (playerCount, timestamp) {
// FIXME: update schema, remove timestamp
this.graphData.push([timestamp, playerCount])
// Trim old graphPoints according to #getMaxGraphDataLength
if (this.graphData.length > TimeTracker.getMaxGraphDataLength()) {
this.graphData.shift()
}
return true
}
findNewGraphPeak () {
let index = -1
for (let i = 0; i < this.graphData.length; i++) {
@ -192,7 +176,7 @@ class ServerRegistration {
const graphPeak = this.graphData[this._graphPeakIndex]
return {
playerCount: graphPeak[1],
timestamp: graphPeak[0]
timestamp: Math.floor(graphPeak[0] / 1000)
}
}