From e023def9dd0418c7fb5fdae7aab5156b6e3bb2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sevket=20G=C3=B6kay?= Date: Sat, 20 Jul 2024 18:00:50 +0200 Subject: [PATCH] transaction detail page shows only energy meter values (#1514) --- .../repository/impl/TransactionRepositoryImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java b/src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java index 0ba4b3b1a..0fea760ff 100644 --- a/src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java +++ b/src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java @@ -23,10 +23,12 @@ import de.rwth.idsg.steve.repository.dto.Transaction; import de.rwth.idsg.steve.repository.dto.TransactionDetails; import de.rwth.idsg.steve.utils.DateTimeUtils; +import de.rwth.idsg.steve.utils.TransactionStopServiceHelper; import de.rwth.idsg.steve.web.dto.TransactionQueryForm; import jooq.steve.db.enums.TransactionStopEventActor; import jooq.steve.db.tables.records.ConnectorMeterValueRecord; import jooq.steve.db.tables.records.TransactionStartRecord; +import ocpp.cs._2015._10.UnitOfMeasure; import org.joda.time.DateTime; import org.jooq.Condition; import org.jooq.DSLContext; @@ -149,11 +151,16 @@ public TransactionDetails getDetails(int transactionPk) { timestampCondition = CONNECTOR_METER_VALUE.VALUE_TIMESTAMP.between(startTimestamp, stopTimestamp); } + // https://github.com/steve-community/steve/issues/1514 + Condition unitCondition = CONNECTOR_METER_VALUE.UNIT.isNull() + .or(CONNECTOR_METER_VALUE.UNIT.in("", UnitOfMeasure.WH.value(), UnitOfMeasure.K_WH.value())); + // Case 1: Ideal and most accurate case. Station sends meter values with transaction id set. // SelectQuery transactionQuery = ctx.selectFrom(CONNECTOR_METER_VALUE) .where(CONNECTOR_METER_VALUE.TRANSACTION_PK.eq(transactionPk)) + .and(unitCondition) .getQuery(); // Case 2: Fall back to filtering according to time windows @@ -165,6 +172,7 @@ public TransactionDetails getDetails(int transactionPk) { .where(CONNECTOR.CHARGE_BOX_ID.eq(chargeBoxId)) .and(CONNECTOR.CONNECTOR_ID.eq(connectorId)))) .and(timestampCondition) + .and(unitCondition) .getQuery(); // Actually, either case 1 applies or 2. If we retrieved values using 1, case 2 is should not be @@ -199,7 +207,10 @@ public TransactionDetails getDetails(int transactionPk) { .location(r.value6()) .unit(r.value7()) .phase(r.value8()) - .build()); + .build()) + .stream() + .filter(TransactionStopServiceHelper::isEnergyValue) + .toList(); return new TransactionDetails(new TransactionMapper().map(transaction), values, nextTx); }