Optimize loading performance of the energy history charts
This commit is contained in:
parent
089b0079e9
commit
c92d8ffe9c
@ -376,6 +376,8 @@ Item {
|
|||||||
property AreaSeries series: null
|
property AreaSeries series: null
|
||||||
|
|
||||||
property QHash valueCache: QHash {}
|
property QHash valueCache: QHash {}
|
||||||
|
property LineSeries lowerSeries: null
|
||||||
|
property LineSeries upperSeries: null
|
||||||
|
|
||||||
function calculateBaseValue(timestamp) {
|
function calculateBaseValue(timestamp) {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
@ -407,19 +409,25 @@ Item {
|
|||||||
// print("inserting entry for", thing.name, entry.timestamp)
|
// print("inserting entry for", thing.name, entry.timestamp)
|
||||||
|
|
||||||
var baseValue = calculateBaseValue(entry.timestamp);
|
var baseValue = calculateBaseValue(entry.timestamp);
|
||||||
series.lowerSeries.insert(idx, entry.timestamp.getTime(), baseValue)
|
lowerSeries.insert(idx, entry.timestamp.getTime(), baseValue)
|
||||||
series.upperSeries.insert(idx, entry.timestamp.getTime(), baseValue + entry.currentPower)
|
upperSeries.insert(idx, entry.timestamp.getTime(), baseValue + entry.currentPower)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addEntries(index, count) {
|
function addEntries(index, count) {
|
||||||
// print("adding entries for", thing.name)
|
// print("adding entries for", thing.name)
|
||||||
// Remove the leading 0-value entry
|
series.lowerSeries = null;
|
||||||
series.lowerSeries.removePoints(0, 1);
|
series.upperSeries = null;
|
||||||
series.upperSeries.removePoints(0, 1);
|
|
||||||
|
|
||||||
var oldestTimestamp = null
|
var oldestTimestamp = null
|
||||||
var newestTimestamp = null
|
var newestTimestamp = null
|
||||||
|
|
||||||
|
|
||||||
|
// Remove the leading 0-value entry
|
||||||
|
lowerSeries.removePoints(0, 1);
|
||||||
|
upperSeries.removePoints(0, 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var entry = logs.get(index + i)
|
var entry = logs.get(index + i)
|
||||||
// print("got thing entry", thing.name, entry.timestamp, entry.currentPower, index + i)
|
// print("got thing entry", thing.name, entry.timestamp, entry.currentPower, index + i)
|
||||||
@ -444,8 +452,11 @@ Item {
|
|||||||
zeroSeries.ensureValue(newestTimestamp)
|
zeroSeries.ensureValue(newestTimestamp)
|
||||||
|
|
||||||
// Add the leading 0-value entry back
|
// Add the leading 0-value entry back
|
||||||
series.lowerSeries.insert(0, series.upperSeries.at(0).x, 0)
|
lowerSeries.insert(0, upperSeries.at(0).x, 0)
|
||||||
series.upperSeries.insert(0, series.upperSeries.at(0).x, 0)
|
upperSeries.insert(0, upperSeries.at(0).x, 0)
|
||||||
|
|
||||||
|
series.upperSeries = upperSeries;
|
||||||
|
series.lowerSeries = lowerSeries;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property ThingPowerLogs logs: ThingPowerLogs {
|
readonly property ThingPowerLogs logs: ThingPowerLogs {
|
||||||
@ -462,15 +473,15 @@ Item {
|
|||||||
|
|
||||||
onEntriesRemoved: {
|
onEntriesRemoved: {
|
||||||
// Remove the leading 0-value entry
|
// Remove the leading 0-value entry
|
||||||
consumerDelegate.series.lowerSeries.removePoints(0, 1);
|
consumerDelegate.lowerSeries.removePoints(0, 1);
|
||||||
consumerDelegate.series.upperSeries.removePoints(0, 1);
|
consumerDelegate.upperSeries.removePoints(0, 1);
|
||||||
|
|
||||||
consumerDelegate.series.lowerSeries.removePoints(index, count)
|
consumerDelegate.lowerSeries.removePoints(index, count)
|
||||||
consumerDelegate.series.upperSeries.removePoints(index, count)
|
consumerDelegate.upperSeries.removePoints(index, count)
|
||||||
|
|
||||||
// Add the leading 0-value entry back
|
// Add the leading 0-value entry back
|
||||||
consumerDelegate.series.lowerSeries.insert(0, consumerDelegate.series.upperSeries.at(0).x, 0)
|
consumerDelegate.lowerSeries.insert(0, consumerDelegate.series.upperSeries.at(0).x, 0)
|
||||||
consumerDelegate.series.upperSeries.insert(0, consumerDelegate.series.upperSeries.at(0).x, 0)
|
consumerDelegate.upperSeries.insert(0, consumerDelegate.series.upperSeries.at(0).x, 0)
|
||||||
|
|
||||||
zeroSeries.shrink()
|
zeroSeries.shrink()
|
||||||
}
|
}
|
||||||
@ -493,8 +504,8 @@ Item {
|
|||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
series = chartView.createSeries(ChartView.SeriesTypeArea, thing.name, dateTimeAxis, valueAxis)
|
series = chartView.createSeries(ChartView.SeriesTypeArea, thing.name, dateTimeAxis, valueAxis)
|
||||||
series.lowerSeries = lineSeriesComponent.createObject(series)
|
lowerSeries = lineSeriesComponent.createObject(series)
|
||||||
series.upperSeries = lineSeriesComponent.createObject(series)
|
upperSeries = lineSeriesComponent.createObject(series)
|
||||||
series.color = NymeaUtils.generateColor(Style.generationBaseColor, index)
|
series.color = NymeaUtils.generateColor(Style.generationBaseColor, index)
|
||||||
series.opacity = Qt.binding(function() {
|
series.opacity = Qt.binding(function() {
|
||||||
return d.selectedSeries == null || d.selectedSeries == series ? 1 : 0.3
|
return d.selectedSeries == null || d.selectedSeries == series ? 1 : 0.3
|
||||||
@ -503,8 +514,8 @@ Item {
|
|||||||
series.borderColor = series.color
|
series.borderColor = series.color
|
||||||
|
|
||||||
// Add a first point at 0 value
|
// Add a first point at 0 value
|
||||||
series.lowerSeries.insert(0, new Date().getTime(), 0)
|
lowerSeries.insert(0, new Date().getTime(), 0)
|
||||||
series.upperSeries.insert(0, new Date().getTime(), 0)
|
upperSeries.insert(0, new Date().getTime(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onDestruction: {
|
Component.onDestruction: {
|
||||||
|
|||||||
@ -82,14 +82,25 @@ Item {
|
|||||||
|
|
||||||
onEntriesAddedIdx: {
|
onEntriesAddedIdx: {
|
||||||
// print("entries added", index, count)
|
// print("entries added", index, count)
|
||||||
|
selfProductionConsumptionSeries.upperSeries = null
|
||||||
|
selfProductionConsumptionSeries.lowerSeries = null
|
||||||
|
toStorageSeries.upperSeries = null
|
||||||
|
toStorageSeries.lowerSeries = null
|
||||||
|
fromStorageSeries.upperSeries = null
|
||||||
|
fromStorageSeries.lowerSeries = null
|
||||||
|
returnSeries.upperSeries = null
|
||||||
|
returnSeries.lowerSeries = null
|
||||||
|
acquisitionSeries.upperSeries = null
|
||||||
|
acquisitionSeries.lowerSeries = null
|
||||||
|
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var entry = powerBalanceLogs.get(index + i)
|
var entry = powerBalanceLogs.get(index + i)
|
||||||
// print("got entry", entry.timestamp)
|
// print("got entry", entry.timestamp)
|
||||||
|
|
||||||
zeroSeries.ensureValue(entry.timestamp)
|
zeroSeries.ensureValue(entry.timestamp)
|
||||||
// For debugging, to see if the other maths line up with the plain production graph
|
|
||||||
productionSeries.insertEntry(index + i, entry)
|
productionSeries.insertEntry(index + i, entry)
|
||||||
consumptionSeries.insertEntry(index + i, entry)
|
// For debugging, to see if the other maths line up with the plain production graph
|
||||||
|
// consumptionSeries.insertEntry(index + i, entry)
|
||||||
selfProductionConsumptionSeries.insertEntry(index + i, entry)
|
selfProductionConsumptionSeries.insertEntry(index + i, entry)
|
||||||
toStorageSeries.insertEntry(index + i, entry)
|
toStorageSeries.insertEntry(index + i, entry)
|
||||||
fromStorageSeries.insertEntry(index + i, entry)
|
fromStorageSeries.insertEntry(index + i, entry)
|
||||||
@ -99,6 +110,16 @@ Item {
|
|||||||
d.now = entry.timestamp
|
d.now = entry.timestamp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
selfProductionConsumptionSeries.upperSeries = selfProductionConsumptionUpperSeries
|
||||||
|
selfProductionConsumptionSeries.lowerSeries = zeroSeries
|
||||||
|
toStorageSeries.upperSeries = toStorageUpperSeries
|
||||||
|
toStorageSeries.lowerSeries = selfProductionConsumptionUpperSeries
|
||||||
|
fromStorageSeries.upperSeries = fromStorageUpperSeries
|
||||||
|
fromStorageSeries.lowerSeries = selfProductionConsumptionUpperSeries
|
||||||
|
returnSeries.upperSeries = returnUpperSeries
|
||||||
|
returnSeries.lowerSeries = toStorageUpperSeries
|
||||||
|
acquisitionSeries.upperSeries = acquisitionUpperSeries
|
||||||
|
acquisitionSeries.lowerSeries = fromStorageUpperSeries
|
||||||
}
|
}
|
||||||
|
|
||||||
onEntriesRemoved: {
|
onEntriesRemoved: {
|
||||||
@ -108,7 +129,7 @@ Item {
|
|||||||
toStorageUpperSeries.removePoints(index, count)
|
toStorageUpperSeries.removePoints(index, count)
|
||||||
selfProductionConsumptionUpperSeries.removePoints(index, count)
|
selfProductionConsumptionUpperSeries.removePoints(index, count)
|
||||||
productionSeries.removePoints(index, count)
|
productionSeries.removePoints(index, count)
|
||||||
consumptionSeries.removePoints(index, count)
|
// consumptionSeries.removePoints(index, count)
|
||||||
zeroSeries.shrink()
|
zeroSeries.shrink()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user