Skip to content

Commit

Permalink
remove the flag firstArrivingMeterValueIfMultiple and its usage (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
goekay committed Mar 26, 2024
1 parent c64d3bf commit ff17fe9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,5 @@ public interface TransactionRepository {

List<Integer> getActiveTransactionIds(String chargeBoxId);

TransactionDetails getDetails(int transactionPk, boolean firstArrivingMeterValueIfMultiple);

default TransactionDetails getDetails(int transactionPk) {
return getDetails(transactionPk, true);
}
TransactionDetails getDetails(int transactionPk);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public List<Integer> getActiveTransactionIds(String chargeBoxId) {
}

@Override
public TransactionDetails getDetails(int transactionPk, boolean firstArrivingMeterValueIfMultiple) {
public TransactionDetails getDetails(int transactionPk) {

// -------------------------------------------------------------------------
// Step 1: Collect general data about transaction
Expand Down Expand Up @@ -176,20 +176,7 @@ public TransactionDetails getDetails(int transactionPk, boolean firstArrivingMet
//
Table<ConnectorMeterValueRecord> t1 = transactionQuery.union(timestampQuery).asTable("t1");

// -------------------------------------------------------------------------
// Step 3: Charging station might send meter vales at fixed intervals (e.g.
// every 15 min) regardless of the fact that connector's meter value did not
// change (e.g. vehicle is fully charged, but cable is still connected). This
// yields multiple entries in db with the same value but different timestamp.
// We are only interested in the first (or last) arriving entry.
// -------------------------------------------------------------------------

Field<DateTime> dateTimeField;
if (firstArrivingMeterValueIfMultiple) {
dateTimeField = DSL.min(t1.field(2, DateTime.class)).as("min");
} else {
dateTimeField = DSL.max(t1.field(2, DateTime.class)).as("max");
}
Field<DateTime> dateTimeField = t1.field(2, DateTime.class);

List<TransactionDetails.MeterValues> values =
ctx.select(
Expand All @@ -202,14 +189,6 @@ public TransactionDetails getDetails(int transactionPk, boolean firstArrivingMet
t1.field(8, String.class),
t1.field(9, String.class))
.from(t1)
.groupBy(
t1.field(3),
t1.field(4),
t1.field(5),
t1.field(6),
t1.field(7),
t1.field(8),
t1.field(9))
.orderBy(dateTimeField)
.fetch()
.map(r -> TransactionDetails.MeterValues.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void stop(List<Integer> transactionPkList) {
}

public void stop(Integer transactionPk) {
TransactionDetails thisTxDetails = transactionRepository.getDetails(transactionPk, false);
TransactionDetails thisTxDetails = transactionRepository.getDetails(transactionPk);
Transaction thisTx = thisTxDetails.getTransaction();

// early exit, if transaction is already stopped
Expand Down

0 comments on commit ff17fe9

Please sign in to comment.