Skip to content

Commit

Permalink
Merge pull request #1515 from steve-community/1514-transaction-detail…
Browse files Browse the repository at this point in the history
…-page-should-only-show-relevant-meter-values

transaction detail page shows only energy meter values (#1514)
  • Loading branch information
goekay authored Jul 25, 2024
2 parents 8a61977 + e023def commit 24fbb57
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ConnectorMeterValueRecord> 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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 24fbb57

Please sign in to comment.