Merge PR #779: Fix calculation of samples for months and years
This commit is contained in:
commit
b8729f6f5e
@ -141,7 +141,7 @@ StatsBase {
|
|||||||
var consumer = consumers.get(j)
|
var consumer = consumers.get(j)
|
||||||
graphEntry[consumer.id] = 0
|
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))
|
// print("Adding entry:", labelTime, config.toLabel(labelTime), JSON.stringify(graphEntry))
|
||||||
|
|||||||
@ -143,7 +143,7 @@ StatsBase {
|
|||||||
}
|
}
|
||||||
labelTime = entry.timestamp
|
labelTime = entry.timestamp
|
||||||
} else {
|
} 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))
|
// 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() {
|
function minutesStart() {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
d.setMinutes(d.getMinutes() - minutesCount + 1, 0, 0)
|
d.setMinutes(d.getMinutes() - minutesCount + 1, 0, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user