Adjust energy view layouts

This commit is contained in:
Michael Zanetti 2021-11-25 01:08:53 +01:00
parent e7af535914
commit c56e18e288
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 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 oldest = 0;
int newest = rowCount() - 1; int newest = rowCount() - 1;
EnergyLogEntry *entry = nullptr; EnergyLogEntry *entry = nullptr;
@ -131,7 +131,7 @@ EnergyLogEntry *PowerBalanceLogs::find(const QDateTime &timestamp) const
EnergyLogEntry *newestEntry = get(newest); EnergyLogEntry *newestEntry = get(newest);
int middle = (newest - oldest) / 2 + oldest; int middle = (newest - oldest) / 2 + oldest;
EnergyLogEntry *middleEntry = get(middle); 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()) { if (timestamp <= oldestEntry->timestamp()) {
return oldestEntry; return oldestEntry;
} }
@ -172,6 +172,8 @@ void PowerBalanceLogs::logEntriesReceived(const QVariantMap &params)
double totalAcquisition = map.value("totalAcquisition").toDouble(); double totalAcquisition = map.value("totalAcquisition").toDouble();
double totalReturn = map.value("totalReturn").toDouble(); double totalReturn = map.value("totalReturn").toDouble();
PowerBalanceLogEntry *entry = new PowerBalanceLogEntry(timestamp, consumption, production, acquisition, storage, totalConsumption, totalProduction, totalAcquisition, totalReturn, this); PowerBalanceLogEntry *entry = new PowerBalanceLogEntry(timestamp, consumption, production, acquisition, storage, totalConsumption, totalProduction, totalAcquisition, totalReturn, this);
qCritical() << "Adding entry:" << entry->timestamp() << entry->totalConsumption();
addEntry(entry); addEntry(entry);
} }
} }

View File

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

View File

@ -8,10 +8,10 @@ ChartView {
id: root id: root
backgroundColor: "transparent" backgroundColor: "transparent"
legend.alignment: Qt.AlignBottom legend.alignment: Qt.AlignBottom
legend.labelColor: Style.foregroundColor
legend.font: Style.extraSmallFont 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.right: 0
margins.bottom: 0 margins.bottom: 0
margins.top: 0 margins.top: 0
@ -129,6 +129,7 @@ ChartView {
text: ((valueAxis.max - (index * valueAxis.max / (valueAxis.tickCount - 1)))).toFixed(0) + "kWh" text: ((valueAxis.max - (index * valueAxis.max / (valueAxis.tickCount - 1)))).toFixed(0) + "kWh"
verticalAlignment: Text.AlignTop verticalAlignment: Text.AlignTop
font: Style.extraSmallFont font: Style.extraSmallFont
color: !powerLogs.fetchingData && powerLogs.count > 0 ? Style.foregroundColor : Style.gray
} }
} }
} }
@ -138,7 +139,7 @@ ChartView {
axisX: BarCategoryAxis { axisX: BarCategoryAxis {
id: categoryAxis id: categoryAxis
categories: daysListNames categories: daysListNames
labelsColor: Style.foregroundColor labelsColor: !powerLogs.fetchingData && powerLogs.count > 0 ? Style.foregroundColor : Style.gray
labelsFont: Style.extraSmallFont labelsFont: Style.extraSmallFont
gridVisible: false gridVisible: false
gridLineColor: Style.tileOverlayColor 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 font: Style.extraSmallFont
} }
} }
} }
DateTimeAxis { DateTimeAxis {

View File

@ -9,9 +9,9 @@ ChartView {
backgroundColor: "transparent" backgroundColor: "transparent"
legend.alignment: Qt.AlignBottom legend.alignment: Qt.AlignBottom
legend.font: Style.extraSmallFont 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.right: 0
margins.bottom: 0 margins.bottom: 0
margins.top: 0 margins.top: 0
@ -66,7 +66,7 @@ ChartView {
} }
PowerBalanceLogs { PowerBalanceLogs {
id: yearLogs id: powerBalanceLogs
engine: _engine engine: _engine
sampleRate: EnergyLogs.SampleRate1Day sampleRate: EnergyLogs.SampleRate1Day
startTime: root.yearStart; startTime: root.yearStart;
@ -74,15 +74,16 @@ ChartView {
onFetchingDataChanged: { onFetchingDataChanged: {
if (!fetchingData) { if (!fetchingData) {
for (var i = 0; i < daysList.length; i++) { 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; var end = null;
if (i+1 < daysList.length) { 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 print("** stats for", daysList[i], new Date(daysList[i]), start.timestamp, start.totalConsumption)
var productionValue = (end != null ? end.totalProduction : root.energyManager.totalProduction) - start.totalProduction var consumptionValue = (end != null ? end.totalConsumption : root.energyManager.totalConsumption) - (start ? start.totalConsumption : 0)
var acquisitionValue = (end != null ? end.totalAcquisition : root.energyManager.totalAcquisition) - start.totalAcquisition var productionValue = (end != null ? end.totalProduction : root.energyManager.totalProduction) - (start ? start.totalProduction : 0)
var returnValue = (end != null ? end.totalReturn : root.energyManager.totalReturn) - start.totalReturn 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) consumptionSeries.append(consumptionValue)
productionSeries.append(productionValue) productionSeries.append(productionValue)
acquisitionSeries.append(acquisitionValue) acquisitionSeries.append(acquisitionValue)
@ -103,6 +104,8 @@ ChartView {
y: root.plotArea.y y: root.plotArea.y
height: root.plotArea.height height: root.plotArea.height
width: plotArea.x - x width: plotArea.x - x
enabled: !powerBalanceLogs.fetchingData && powerBalanceLogs.count > 0
Repeater { Repeater {
model: valueAxis.tickCount model: valueAxis.tickCount
delegate: Label { delegate: Label {
@ -120,7 +123,8 @@ ChartView {
axisX: BarCategoryAxis { axisX: BarCategoryAxis {
id: categoryAxis id: categoryAxis
categories: daysListNames categories: daysListNames
labelsColor: Style.foregroundColor labelsColor: !powerBalanceLogs.fetchingData && powerBalanceLogs.count > 0 ? Style.foregroundColor : Style.gray
labelsFont: Style.extraSmallFont labelsFont: Style.extraSmallFont
gridVisible: false gridVisible: false
gridLineColor: Style.tileOverlayColor gridLineColor: Style.tileOverlayColor
@ -174,4 +178,16 @@ ChartView {
borderColor: color 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 { ValueAxis {
id: valueAxis id: valueAxis
min: 0 min: 0
max: -Math.ceil(powerBalanceLogs.minValue / 1000) * 1000 max: Math.ceil(-powerBalanceLogs.minValue / 1000) * 1000
labelFormat: "" labelFormat: ""
gridLineColor: Style.tileOverlayColor gridLineColor: Style.tileOverlayColor
labelsVisible: false labelsVisible: false
lineVisible: false lineVisible: false
titleVisible: false titleVisible: false
shadesVisible: false shadesVisible: false
// visible: false
} }
Item { Item {