Merge PR #707: Adjust energy view layouts

This commit is contained in:
Jenkins nymea 2021-11-25 01:10:50 +01:00
commit b08a92b2ac
6 changed files with 86 additions and 58 deletions

View File

@ -121,7 +121,7 @@ void PowerBalanceLogs::addEntry(PowerBalanceLogEntry *entry)
EnergyLogEntry *PowerBalanceLogs::find(const QDateTime &timestamp) const
{
// qWarning() << "Finding log entry for timestamp:" << timestamp;
qWarning() << "Finding log entry for timestamp:" << timestamp;
int oldest = 0;
int newest = rowCount() - 1;
EnergyLogEntry *entry = nullptr;
@ -131,7 +131,7 @@ EnergyLogEntry *PowerBalanceLogs::find(const QDateTime &timestamp) const
EnergyLogEntry *newestEntry = get(newest);
int middle = (newest - oldest) / 2 + oldest;
EnergyLogEntry *middleEntry = get(middle);
// qWarning() << "Oldest:" << oldestEntry->timestamp().toString() << "Middle:" << middleEntry->timestamp().toString() << "Newest:" << newestEntry->timestamp().toString() << ":" << (newest - oldest);
qWarning() << "Oldest:" << oldestEntry->timestamp().toString() << "Middle:" << middleEntry->timestamp().toString() << "Newest:" << newestEntry->timestamp().toString() << ":" << (newest - oldest);
if (timestamp <= oldestEntry->timestamp()) {
return oldestEntry;
}
@ -172,6 +172,8 @@ void PowerBalanceLogs::logEntriesReceived(const QVariantMap &params)
double totalAcquisition = map.value("totalAcquisition").toDouble();
double totalReturn = map.value("totalReturn").toDouble();
PowerBalanceLogEntry *entry = new PowerBalanceLogEntry(timestamp, consumption, production, acquisition, storage, totalConsumption, totalProduction, totalAcquisition, totalReturn, this);
qCritical() << "Adding entry:" << entry->timestamp() << entry->totalConsumption();
addEntry(entry);
}
}

View File

@ -97,54 +97,54 @@ MainViewBase {
columnSpacing: 0
CurrentConsumptionBalancePieChart {
Layout.fillWidth: true
Layout.preferredHeight: width
energyManager: energyManager
visible: producers.count > 0
}
CurrentProductionBalancePieChart {
Layout.fillWidth: true
Layout.preferredHeight: width
energyManager: energyManager
visible: producers.count > 0
}
// CurrentConsumptionBalancePieChart {
// Layout.fillWidth: true
// Layout.preferredHeight: width
// energyManager: energyManager
// visible: producers.count > 0
// }
// CurrentProductionBalancePieChart {
// Layout.fillWidth: true
// Layout.preferredHeight: width
// energyManager: energyManager
// visible: producers.count > 0
// }
PowerConsumptionBalanceHistory {
Layout.fillWidth: true
Layout.preferredHeight: width
visible: producers.count > 0
}
// PowerConsumptionBalanceHistory {
// Layout.fillWidth: true
// Layout.preferredHeight: width
// visible: producers.count > 0
// }
PowerProductionBalanceHistory {
Layout.fillWidth: true
Layout.preferredHeight: width
visible: producers.count > 0
}
// PowerProductionBalanceHistory {
// Layout.fillWidth: true
// Layout.preferredHeight: width
// visible: producers.count > 0
// }
ConsumersBarChart {
Layout.fillWidth: true
Layout.preferredHeight: width
energyManager: energyManager
visible: consumers.count > 0
}
ConsumersHistory {
Layout.fillWidth: true
Layout.preferredHeight: width
visible: consumers.count > 0
}
// ConsumersBarChart {
// Layout.fillWidth: true
// Layout.preferredHeight: width
// energyManager: energyManager
// visible: consumers.count > 0
// }
// ConsumersHistory {
// Layout.fillWidth: true
// Layout.preferredHeight: width
// visible: consumers.count > 0
// }
PowerBalanceStats {
Layout.fillWidth: true
Layout.preferredHeight: width
energyManager: energyManager
}
ConsumerStats {
Layout.fillWidth: true
Layout.preferredHeight: width
energyManager: energyManager
visible: consumers.count > 0
}
// ConsumerStats {
// Layout.fillWidth: true
// Layout.preferredHeight: width
// energyManager: energyManager
// visible: consumers.count > 0
// }
}
}

View File

@ -8,10 +8,10 @@ ChartView {
id: root
backgroundColor: "transparent"
legend.alignment: Qt.AlignBottom
legend.labelColor: Style.foregroundColor
legend.font: Style.extraSmallFont
legend.labelColor: !powerLogs.fetchingData && powerLogs.count > 0 ? Style.foregroundColor : Style.gray
margins.left: 0
// margins.left: 0
margins.right: 0
margins.bottom: 0
margins.top: 0
@ -129,6 +129,7 @@ ChartView {
text: ((valueAxis.max - (index * valueAxis.max / (valueAxis.tickCount - 1)))).toFixed(0) + "kWh"
verticalAlignment: Text.AlignTop
font: Style.extraSmallFont
color: !powerLogs.fetchingData && powerLogs.count > 0 ? Style.foregroundColor : Style.gray
}
}
}
@ -138,7 +139,7 @@ ChartView {
axisX: BarCategoryAxis {
id: categoryAxis
categories: daysListNames
labelsColor: Style.foregroundColor
labelsColor: !powerLogs.fetchingData && powerLogs.count > 0 ? Style.foregroundColor : Style.gray
labelsFont: Style.extraSmallFont
gridVisible: false
gridLineColor: Style.tileOverlayColor
@ -165,4 +166,16 @@ ChartView {
}
}
}
Label {
x: root.plotArea.x
y: root.plotArea.y
width: root.plotArea.width
height: root.plotArea.height
wrapMode: Text.WordWrap
text: qsTr("No data available")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
visible: !powerLogs.fetchingData && powerLogs.count == 0
}
}

View File

@ -169,7 +169,6 @@ ChartView {
font: Style.extraSmallFont
}
}
}
DateTimeAxis {

View File

@ -9,9 +9,9 @@ ChartView {
backgroundColor: "transparent"
legend.alignment: Qt.AlignBottom
legend.font: Style.extraSmallFont
legend.labelColor: Style.foregroundColor
legend.labelColor: !powerBalanceLogs.fetchingData && powerBalanceLogs.count > 0 ? Style.foregroundColor : Style.gray
margins.left: 0
// margins.left: 0
margins.right: 0
margins.bottom: 0
margins.top: 0
@ -66,7 +66,7 @@ ChartView {
}
PowerBalanceLogs {
id: yearLogs
id: powerBalanceLogs
engine: _engine
sampleRate: EnergyLogs.SampleRate1Day
startTime: root.yearStart;
@ -74,15 +74,16 @@ ChartView {
onFetchingDataChanged: {
if (!fetchingData) {
for (var i = 0; i < daysList.length; i++) {
var start = yearLogs.find(new Date(daysList[i]))
var start = powerBalanceLogs.find(new Date(daysList[i]))
var end = null;
if (i+1 < daysList.length) {
end = yearLogs.find(new Date(daysList[i+1]))
end = powerBalanceLogs.find(new Date(daysList[i+1]))
}
var consumptionValue = (end != null ? end.totalConsumption : root.energyManager.totalConsumption) - start.totalConsumption
var productionValue = (end != null ? end.totalProduction : root.energyManager.totalProduction) - start.totalProduction
var acquisitionValue = (end != null ? end.totalAcquisition : root.energyManager.totalAcquisition) - start.totalAcquisition
var returnValue = (end != null ? end.totalReturn : root.energyManager.totalReturn) - start.totalReturn
print("** stats for", daysList[i], new Date(daysList[i]), start.timestamp, start.totalConsumption)
var consumptionValue = (end != null ? end.totalConsumption : root.energyManager.totalConsumption) - (start ? start.totalConsumption : 0)
var productionValue = (end != null ? end.totalProduction : root.energyManager.totalProduction) - (start ? start.totalProduction : 0)
var acquisitionValue = (end != null ? end.totalAcquisition : root.energyManager.totalAcquisition) - (start ? start.totalAcquisition : 0)
var returnValue = (end != null ? end.totalReturn : root.energyManager.totalReturn) - (start ? start.totalReturn : 0)
consumptionSeries.append(consumptionValue)
productionSeries.append(productionValue)
acquisitionSeries.append(acquisitionValue)
@ -103,6 +104,8 @@ ChartView {
y: root.plotArea.y
height: root.plotArea.height
width: plotArea.x - x
enabled: !powerBalanceLogs.fetchingData && powerBalanceLogs.count > 0
Repeater {
model: valueAxis.tickCount
delegate: Label {
@ -120,7 +123,8 @@ ChartView {
axisX: BarCategoryAxis {
id: categoryAxis
categories: daysListNames
labelsColor: Style.foregroundColor
labelsColor: !powerBalanceLogs.fetchingData && powerBalanceLogs.count > 0 ? Style.foregroundColor : Style.gray
labelsFont: Style.extraSmallFont
gridVisible: false
gridLineColor: Style.tileOverlayColor
@ -174,4 +178,16 @@ ChartView {
borderColor: color
}
}
Label {
x: root.plotArea.x
y: root.plotArea.y
width: root.plotArea.width
height: root.plotArea.height
wrapMode: Text.WordWrap
text: qsTr("No data available")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
visible: !powerBalanceLogs.fetchingData && powerBalanceLogs.count == 0
}
}

View File

@ -65,15 +65,13 @@ ChartView {
ValueAxis {
id: valueAxis
min: 0
max: -Math.ceil(powerBalanceLogs.minValue / 1000) * 1000
max: Math.ceil(-powerBalanceLogs.minValue / 1000) * 1000
labelFormat: ""
gridLineColor: Style.tileOverlayColor
labelsVisible: false
lineVisible: false
titleVisible: false
shadesVisible: false
// visible: false
}
Item {