share a single timestamp array between all graphData objects
This commit is contained in:
@ -20,33 +20,63 @@ class Database {
|
||||
const startTime = endTime - graphDuration
|
||||
|
||||
this.getRecentPings(startTime, endTime, pingData => {
|
||||
const graphPointsByIp = []
|
||||
const relativeGraphData = []
|
||||
|
||||
for (const row of pingData) {
|
||||
// Load into temporary array
|
||||
// This will be culled prior to being pushed to the serverRegistration
|
||||
let graphPoints = graphPointsByIp[row.ip]
|
||||
if (!graphPoints) {
|
||||
graphPoints = graphPointsByIp[row.ip] = []
|
||||
let graphData = relativeGraphData[row.ip]
|
||||
if (!graphData) {
|
||||
relativeGraphData[row.ip] = graphData = [[], []]
|
||||
}
|
||||
|
||||
graphPoints.push([row.timestamp, row.playerCount])
|
||||
// DANGER!
|
||||
// This will pull the timestamp from each row into memory
|
||||
// This is built under the assumption that each round of pings shares the same timestamp
|
||||
// This enables all timestamp arrays to have consistent point selection and graph correctly
|
||||
graphData[0].push(row.timestamp)
|
||||
graphData[1].push(row.playerCount)
|
||||
}
|
||||
|
||||
Object.keys(graphPointsByIp).forEach(ip => {
|
||||
Object.keys(relativeGraphData).forEach(ip => {
|
||||
// Match IPs to serverRegistration object
|
||||
for (const serverRegistration of this._app.serverRegistrations) {
|
||||
if (serverRegistration.data.ip === ip) {
|
||||
const graphPoints = graphPointsByIp[ip]
|
||||
const graphData = relativeGraphData[ip]
|
||||
|
||||
// Push the data into the instance and cull if needed
|
||||
serverRegistration.loadGraphPoints(graphPoints)
|
||||
serverRegistration.loadGraphPoints(startTime, graphData[0], graphData[1])
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Since all timestamps are shared, use the array from the first ServerRegistration
|
||||
// This is very dangerous and can break if data is out of sync
|
||||
if (Object.keys(relativeGraphData).length > 0) {
|
||||
const serverIp = Object.keys(relativeGraphData)[0]
|
||||
const timestamps = relativeGraphData[serverIp][0]
|
||||
|
||||
// This is a copy of ServerRegistration#loadGraphPoints
|
||||
// relativeGraphData contains original timestamp data and needs to be filtered into minutes
|
||||
const sharedTimestamps = []
|
||||
|
||||
let lastTimestamp = startTime
|
||||
|
||||
for (let i = 0; i < timestamps.length; i++) {
|
||||
const timestamp = timestamps[i]
|
||||
|
||||
if (timestamp - lastTimestamp >= 60 * 1000) {
|
||||
lastTimestamp = timestamp
|
||||
|
||||
sharedTimestamps.push(timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
this._app.timeTracker.loadHistoricalTimestamps(sharedTimestamps)
|
||||
}
|
||||
|
||||
callback()
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user