store pingHistory as player count directly
This commit is contained in:
parent
37a88677cf
commit
3491c73b89
@ -111,12 +111,12 @@ export class App {
|
||||
|
||||
serverRegistration.initServerStatus(payload)
|
||||
|
||||
// pingHistory is only defined when the backend has previous ping data
|
||||
// undefined pingHistory means this is a placeholder ping generated by the backend
|
||||
if (typeof payload.pingHistory !== 'undefined') {
|
||||
// playerCountHistory is only defined when the backend has previous ping data
|
||||
// undefined playerCountHistory means this is a placeholder ping generated by the backend
|
||||
if (typeof payload.playerCountHistory !== 'undefined') {
|
||||
// Push the historical data into the graph
|
||||
// This will trim and format the data so it is ready for the graph to render once init
|
||||
serverRegistration.addGraphPoints(payload.pingHistory, timestampPoints)
|
||||
serverRegistration.addGraphPoints(payload.playerCountHistory, timestampPoints)
|
||||
}
|
||||
|
||||
// Create the plot instance internally with the restructured and cleaned data
|
||||
|
@ -96,8 +96,7 @@ export class ServerRegistration {
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const point = points[i]
|
||||
const timestamp = timestampPoints[i]
|
||||
|
||||
this._graphData.push([timestamp, point.result ? point.result.players.online : 0])
|
||||
this._graphData.push([timestamp, point])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,8 @@ export class SocketManager {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(payload.servers)
|
||||
|
||||
payload.servers.forEach((serverPayload, serverId) => {
|
||||
this._app.addServer(serverId, serverPayload, payload.timestampPoints)
|
||||
})
|
||||
|
@ -16,8 +16,15 @@ class ServerRegistration {
|
||||
}
|
||||
|
||||
handlePing (timestamp, resp, err, version) {
|
||||
const playerCount = resp ? resp.players.online : 0
|
||||
|
||||
// Store into in-memory ping data
|
||||
this.addPing(resp)
|
||||
this._pingHistory.push(playerCount)
|
||||
|
||||
// Trim pingHistory to avoid memory leaks
|
||||
if (this._pingHistory.length > this._app.pingController.getMaxServerGraphDataLength()) {
|
||||
this._pingHistory.shift()
|
||||
}
|
||||
|
||||
// Only notify the frontend to append to the historical graph
|
||||
// if both the graphing behavior is enabled and the backend agrees
|
||||
@ -25,8 +32,6 @@ class ServerRegistration {
|
||||
let updateHistoryGraph = false
|
||||
|
||||
if (config.logToDatabase) {
|
||||
const playerCount = resp ? resp.players.online : 0
|
||||
|
||||
if (this.addGraphPoint(resp !== undefined, playerCount, timestamp)) {
|
||||
updateHistoryGraph = true
|
||||
}
|
||||
@ -90,27 +95,6 @@ class ServerRegistration {
|
||||
return update
|
||||
}
|
||||
|
||||
addPing (resp) {
|
||||
const ping = {}
|
||||
|
||||
if (resp) {
|
||||
// Append a result object
|
||||
// This filters out unwanted data from resp
|
||||
ping.result = {
|
||||
players: {
|
||||
online: resp.players.online
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._pingHistory.push(ping)
|
||||
|
||||
// Trim pingHistory to avoid memory leaks
|
||||
if (this._pingHistory.length > this._app.pingController.getMaxServerGraphDataLength()) {
|
||||
this._pingHistory.shift()
|
||||
}
|
||||
}
|
||||
|
||||
getPingHistory () {
|
||||
if (this._pingHistory.length > 0) {
|
||||
const payload = {
|
||||
@ -127,21 +111,19 @@ class ServerRegistration {
|
||||
payload.graphPeakData = graphPeakData
|
||||
}
|
||||
|
||||
// Insert the latest update manually into the array
|
||||
// This is a mutated copy of the last update to contain live metadata
|
||||
// The metadata is used by the frontend for rendering
|
||||
const lastPing = this._pingHistory[this._pingHistory.length - 1]
|
||||
|
||||
// Conditionally append to avoid defining fields with undefined values
|
||||
if (lastPing.result) {
|
||||
payload.result = lastPing.result
|
||||
} else if (lastPing.error) {
|
||||
payload.error = lastPing.error
|
||||
// Assume the ping was a success and define result
|
||||
// pingHistory does not keep error references, so its impossible to detect if this is an error
|
||||
// It is also pointless to store that data since it will be short lived
|
||||
payload.result = {
|
||||
players: {
|
||||
online: this._pingHistory[this._pingHistory.length - 1]
|
||||
}
|
||||
}
|
||||
|
||||
// Send a copy of pingHistory
|
||||
// Omit the last value since it is contained within payload
|
||||
payload.pingHistory = this._pingHistory.slice(0, this._pingHistory.length - 1)
|
||||
// Include the last value even though it is contained within payload
|
||||
// The frontend will only push to its graphData from playerCountHistory
|
||||
payload.playerCountHistory = this._pingHistory
|
||||
|
||||
return payload
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user