share a single timestamp array between all graphData objects
This commit is contained in:
37
lib/time.js
37
lib/time.js
@ -4,9 +4,10 @@ class TimeTracker {
|
||||
constructor (app) {
|
||||
this._app = app
|
||||
this._points = []
|
||||
this._historicalTimestamps = []
|
||||
}
|
||||
|
||||
newTimestamp () {
|
||||
newPingTimestamp () {
|
||||
const timestamp = new Date().getTime()
|
||||
|
||||
this._points.push(timestamp)
|
||||
@ -15,10 +16,40 @@ class TimeTracker {
|
||||
this._points.shift()
|
||||
}
|
||||
|
||||
return timestamp
|
||||
// Flag each group as history graph additions each minute
|
||||
// This is sent to the frontend for graph updates
|
||||
const updateHistoryGraph = config.logToDatabase && (!this._lastHistoryGraphUpdate || timestamp - this._lastHistoryGraphUpdate >= 60 * 1000)
|
||||
|
||||
if (updateHistoryGraph) {
|
||||
this._lastHistoryGraphUpdate = timestamp
|
||||
|
||||
// Push into timestamps array to update backend state
|
||||
this._historicalTimestamps.push(timestamp)
|
||||
|
||||
if (this._historicalTimestamps.length > TimeTracker.getMaxGraphDataLength()) {
|
||||
this._historicalTimestamps.shift()
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
timestamp,
|
||||
updateHistoryGraph
|
||||
}
|
||||
}
|
||||
|
||||
getPointsSeconds () {
|
||||
loadHistoricalTimestamps (timestamps) {
|
||||
this._historicalTimestamps = timestamps
|
||||
}
|
||||
|
||||
getHistoricalPointsSeconds () {
|
||||
return this._historicalTimestamps.map(value => Math.floor(value / 1000))
|
||||
}
|
||||
|
||||
getHistoricalPointSeconds (index) {
|
||||
return Math.floor(this._historicalTimestamps[index] / 1000)
|
||||
}
|
||||
|
||||
getServerPointsSeconds () {
|
||||
return this._points.map(value => Math.floor(value / 1000))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user