Fix calculation of samples for months and years
This commit is contained in:
parent
3beafeaec6
commit
549ee557de
@ -141,7 +141,7 @@ StatsBase {
|
||||
var consumer = consumers.get(j)
|
||||
graphEntry[consumer.id] = 0
|
||||
}
|
||||
labelTime = new Date(newestLogTimestamp.getTime() - config.sampleRate * i * 60000)
|
||||
labelTime = calculateSampleStart(newestLogTimestamp, config.sampleRate, i)
|
||||
}
|
||||
|
||||
// print("Adding entry:", labelTime, config.toLabel(labelTime), JSON.stringify(graphEntry))
|
||||
|
||||
@ -143,7 +143,7 @@ StatsBase {
|
||||
}
|
||||
labelTime = entry.timestamp
|
||||
} else {
|
||||
labelTime = new Date(newestLogTimestamp.getTime() - config.sampleRate * i * 60000)
|
||||
labelTime = calculateSampleStart(newestLogTimestamp, config.sampleRate, i)
|
||||
}
|
||||
|
||||
// print("Adding entry:", labelTime, graphEntry.consumption, config.toLabel(labelTime))
|
||||
|
||||
@ -56,6 +56,21 @@ Item {
|
||||
}
|
||||
})
|
||||
|
||||
function calculateSampleStart(sampleEnd, sampleRate, sampleCount) {
|
||||
if (sampleCount === undefined) {
|
||||
sampleCount = 1
|
||||
}
|
||||
var sampleStart = new Date(sampleEnd)
|
||||
if (sampleRate === EnergyLogs.SampleRate1Month) {
|
||||
sampleStart.setMonth(sampleEnd.getMonth() - sampleCount)
|
||||
} else if (sampleRate === EnergyLogs.SampleRate1Year) {
|
||||
sampleStart.setFullYear(sampleEnd.getFullYear() - sampleCount)
|
||||
} else {
|
||||
sampleStart.setTime(sampleEnd.getTime() - (sampleRate * 60000 * sampleCount))
|
||||
}
|
||||
return sampleStart
|
||||
}
|
||||
|
||||
function minutesStart() {
|
||||
var d = new Date();
|
||||
d.setMinutes(d.getMinutes() - minutesCount + 1, 0, 0)
|
||||
|
||||
Reference in New Issue
Block a user