unify TimeTracker code, explicitly mark nullable playerCounts as unsafe

This commit is contained in:
Nick Krecklow
2020-05-11 18:29:26 -05:00
parent 7136851123
commit 903343fbdf
6 changed files with 62 additions and 44 deletions

View File

@ -1,5 +1,7 @@
const sqlite = require('sqlite3')
const TimeTracker = require('./time')
class Database {
constructor (app) {
this._app = app
@ -58,23 +60,7 @@ class Database {
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)
this._app.timeTracker.loadGraphPoints(startTime, timestamps)
}
callback()
@ -94,7 +80,7 @@ class Database {
this.getRecord(serverRegistration.data.ip, (playerCount, timestamp) => {
serverRegistration.recordData = {
playerCount,
timestamp: Math.floor(timestamp / 1000)
timestamp: TimeTracker.toSeconds(timestamp)
}
// Check if completedTasks hit the finish value
@ -119,9 +105,9 @@ class Database {
], (_, data) => callback(data[0]['MAX(playerCount)'], data[0].timestamp))
}
insertPing (ip, timestamp, playerCount) {
insertPing (ip, timestamp, unsafePlayerCount) {
const statement = this._sql.prepare('INSERT INTO pings (timestamp, ip, playerCount) VALUES (?, ?, ?)')
statement.run(timestamp, ip, playerCount)
statement.run(timestamp, ip, unsafePlayerCount)
statement.finalize()
}
}