Skip to content
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

remove the flag firstArrivingMeterValueIfMultiple and its usage #1423

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 @@ -16,40 +16,39 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.rwth.idsg.steve.repository.impl;

import de.rwth.idsg.steve.SteveException;
import de.rwth.idsg.steve.repository.TransactionRepository;
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.web.dto.TransactionQueryForm;
import jooq.steve.db.enums.TransactionStopEventActor;
import jooq.steve.db.tables.records.ConnectorMeterValueRecord;
import jooq.steve.db.tables.records.TransactionStartRecord;
import org.joda.time.DateTime;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.Record12;
import org.jooq.Record9;
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;

import java.io.Writer;
import java.util.List;

import static de.rwth.idsg.steve.utils.CustomDSL.date;

Check warning on line 45 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'de.rwth.idsg.steve.utils.CustomDSL.date'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 45 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'de.rwth.idsg.steve.utils.CustomDSL.date'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport
import static jooq.steve.db.tables.ChargeBox.CHARGE_BOX;

Check warning on line 46 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.ChargeBox.CHARGE_BOX'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 46 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.ChargeBox.CHARGE_BOX'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport
import static jooq.steve.db.tables.Connector.CONNECTOR;

Check warning on line 47 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.Connector.CONNECTOR'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 47 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.Connector.CONNECTOR'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport
import static jooq.steve.db.tables.ConnectorMeterValue.CONNECTOR_METER_VALUE;

Check warning on line 48 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.ConnectorMeterValue.CONNECTOR_METER_VALUE'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 48 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.ConnectorMeterValue.CONNECTOR_METER_VALUE'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport
import static jooq.steve.db.tables.OcppTag.OCPP_TAG;

Check warning on line 49 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.OcppTag.OCPP_TAG'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 49 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.OcppTag.OCPP_TAG'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport
import static jooq.steve.db.tables.Transaction.TRANSACTION;

Check warning on line 50 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.Transaction.TRANSACTION'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 50 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.Transaction.TRANSACTION'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport
import static jooq.steve.db.tables.TransactionStart.TRANSACTION_START;

Check warning on line 51 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.TransactionStart.TRANSACTION_START'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 51 in src/main/java/de/rwth/idsg/steve/repository/impl/TransactionRepositoryImpl.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'jooq.steve.db.tables.TransactionStart.TRANSACTION_START'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

/**
* @author Sevket Goekay <[email protected]>
Expand Down Expand Up @@ -89,7 +88,7 @@
}

@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 @@
//
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 @@
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 @@ -37,8 +37,8 @@
import java.util.Comparator;
import java.util.List;

import static de.rwth.idsg.steve.utils.TransactionStopServiceHelper.floatingStringToIntString;

Check warning on line 40 in src/main/java/de/rwth/idsg/steve/service/TransactionStopService.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'de.rwth.idsg.steve.utils.TransactionStopServiceHelper.floatingStringToIntString'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 40 in src/main/java/de/rwth/idsg/steve/service/TransactionStopService.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'de.rwth.idsg.steve.utils.TransactionStopServiceHelper.floatingStringToIntString'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport
import static de.rwth.idsg.steve.utils.TransactionStopServiceHelper.kWhStringToWhString;

Check warning on line 41 in src/main/java/de/rwth/idsg/steve/service/TransactionStopService.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'de.rwth.idsg.steve.utils.TransactionStopServiceHelper.kWhStringToWhString'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

Check warning on line 41 in src/main/java/de/rwth/idsg/steve/service/TransactionStopService.java

View workflow job for this annotation

GitHub Actions / pmd

Unused static import 'de.rwth.idsg.steve.utils.TransactionStopServiceHelper.kWhStringToWhString'

Reports import statements that can be removed. They are either unused, duplicated, or the members they import are already implicitly in scope, because they're in java.lang, or the current package. UnnecessaryImport (Priority: 4, Ruleset: Code Style) https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_java_codestyle.html#unnecessaryimport

/**
* @author Sevket Goekay <[email protected]>
Expand All @@ -57,7 +57,7 @@
}

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