Skip to content

remove the flag firstArrivingMeterValueIfMultiple and its usage #1423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -36,7 +36,6 @@
import org.jooq.RecordMapper;
import org.jooq.SelectQuery;
import org.jooq.Table;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -89,7 +88,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 +175,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 +188,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