share a single timestamp array between all graphData objects

This commit is contained in:
Nick Krecklow
2020-05-11 18:12:29 -05:00
parent 59ec7d151f
commit c2f6d04e72
10 changed files with 100 additions and 52 deletions

View File

@ -14,7 +14,8 @@ class ServerRegistration {
recordData
graphData = []
constructor (serverId, data) {
constructor (app, serverId, data) {
this._app = app
this.serverId = serverId
this.data = data
this._pingHistory = []
@ -36,8 +37,7 @@ class ServerRegistration {
// if both the graphing behavior is enabled and the backend agrees
// that the ping is eligible for addition
if (updateHistoryGraph) {
// FIXME: update schema, remove timestamp
this.graphData.push([timestamp, playerCount])
this.graphData.push(playerCount)
// Trim old graphPoints according to #getMaxGraphDataLength
if (this.graphData.length > TimeTracker.getMaxGraphDataLength()) {
@ -131,31 +131,26 @@ class ServerRegistration {
}
}
loadGraphPoints (points) {
loadGraphPoints (startTime, timestamps, points) {
// Filter pings so each result is a minute apart
const minutePoints = []
let lastTimestamp = 0
let lastTimestamp = startTime
for (const point of points) {
// 0 is the index of the timestamp
if (point[0] - lastTimestamp >= 60 * 1000) {
lastTimestamp = point[0]
for (let i = 0; i < timestamps.length; i++) {
const timestamp = timestamps[i]
// FIXME: update schema, remove timestamp
minutePoints.push(point)
if (timestamp - lastTimestamp >= 60 * 1000) {
lastTimestamp = timestamp
this.graphData.push(points[i])
}
}
if (minutePoints.length > 0) {
this.graphData = minutePoints
}
}
findNewGraphPeak () {
let index = -1
for (let i = 0; i < this.graphData.length; i++) {
const point = this.graphData[i]
if (index === -1 || point[1] > this.graphData[index][1]) {
if (index === -1 || point > this.graphData[index]) {
index = i
}
}
@ -173,10 +168,9 @@ class ServerRegistration {
if (this._graphPeakIndex === undefined) {
return
}
const graphPeak = this.graphData[this._graphPeakIndex]
return {
playerCount: graphPeak[1],
timestamp: Math.floor(graphPeak[0] / 1000)
playerCount: this.graphData[this._graphPeakIndex],
timestamp: this._app.timeTracker.getHistoricalPointSeconds(this._graphPeakIndex)
}
}