Skip to content

Commit

Permalink
Adding EvcsLocationType to EcsInput, adapting factories and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-peter committed Aug 17, 2021
1 parent dcc200d commit 9216532
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import edu.ie3.datamodel.exceptions.ChargingPointTypeException;
import edu.ie3.datamodel.exceptions.FactoryException;
import edu.ie3.datamodel.exceptions.ParsingException;
import edu.ie3.datamodel.io.factory.input.NodeAssetInputEntityData;
import edu.ie3.datamodel.models.OperationTime;
import edu.ie3.datamodel.models.input.NodeInput;
Expand All @@ -15,6 +16,8 @@
import edu.ie3.datamodel.models.input.system.characteristic.ReactivePowerCharacteristic;
import edu.ie3.datamodel.models.input.system.type.chargingpoint.ChargingPointType;
import edu.ie3.datamodel.models.input.system.type.chargingpoint.ChargingPointTypeUtils;
import edu.ie3.datamodel.models.input.system.type.evcslocation.EvcsLocationType;
import edu.ie3.datamodel.models.input.system.type.evcslocation.EvcsLocationTypeUtils;

/**
* Factory to create instances of {@link EvcsInput}s based on {@link NodeAssetInputEntityData} and
Expand All @@ -29,14 +32,15 @@ public class EvcsInputFactory
private static final String TYPE = "type";
private static final String CHARGING_POINTS = "chargingpoints";
private static final String COS_PHI_RATED = "cosphirated";
private static final String LOCATION_TYPE = "locationtype";

public EvcsInputFactory() {
super(EvcsInput.class);
}

@Override
protected String[] getAdditionalFields() {
return new String[] {TYPE, CHARGING_POINTS, COS_PHI_RATED};
return new String[] {TYPE, CHARGING_POINTS, COS_PHI_RATED, LOCATION_TYPE};
}

@Override
Expand All @@ -62,7 +66,27 @@ protected EvcsInput buildModel(
final int chargingPoints = data.getInt(CHARGING_POINTS);
final double cosPhi = data.getDouble(COS_PHI_RATED);

final EvcsLocationType locationType;
try {
locationType = EvcsLocationTypeUtils.parse(data.getField(LOCATION_TYPE));
} catch (ParsingException e) {
throw new FactoryException(
String.format(
"Exception while trying to parse field \"%s\" with supposed int value \"%s\"",
LOCATION_TYPE, data.getField(LOCATION_TYPE)),
e);
}

return new EvcsInput(
uuid, id, operator, operationTime, node, qCharacteristics, type, chargingPoints, cosPhi);
uuid,
id,
operator,
operationTime,
node,
qCharacteristics,
type,
chargingPoints,
cosPhi,
locationType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ protected String processMethodResult(Object methodReturnObject, Method method, S
case "String":
case "DayOfWeek":
case "ChargingPointType":
case "EvcsLocationType":
resultStringBuilder.append(methodReturnObject.toString());
break;
case "Quantity":
Expand Down
57 changes: 48 additions & 9 deletions src/main/java/edu/ie3/datamodel/models/input/system/EvcsInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.ie3.datamodel.models.input.OperatorInput;
import edu.ie3.datamodel.models.input.system.characteristic.ReactivePowerCharacteristic;
import edu.ie3.datamodel.models.input.system.type.chargingpoint.ChargingPointType;
import edu.ie3.datamodel.models.input.system.type.evcslocation.EvcsLocationType;
import java.util.Objects;
import java.util.UUID;

Expand All @@ -24,6 +25,9 @@ public class EvcsInput extends SystemParticipantInput {
/** Rated power factor */
private final double cosPhiRated;

/** Evcs location type */
private final EvcsLocationType locationType;

/**
* @param uuid Unique identifier
* @param id Human readable identifier
Expand All @@ -34,6 +38,7 @@ public class EvcsInput extends SystemParticipantInput {
* @param type type of the charging points available to this charging station
* @param chargingPoints number of charging points available at this charging station
* @param cosPhiRated rated cos phi
* @param locationType the location type
*/
public EvcsInput(
UUID uuid,
Expand All @@ -44,11 +49,13 @@ public EvcsInput(
ReactivePowerCharacteristic qCharacteristics,
ChargingPointType type,
int chargingPoints,
double cosPhiRated) {
double cosPhiRated,
EvcsLocationType locationType) {
super(uuid, id, operator, operationTime, node, qCharacteristics);
this.type = type;
this.chargingPoints = chargingPoints;
this.cosPhiRated = cosPhiRated;
this.locationType = locationType;
}

/**
Expand All @@ -60,6 +67,7 @@ public EvcsInput(
* @param qCharacteristics Description of a reactive power characteristic
* @param type type of the charging points available to this charging station
* @param cosPhiRated rated cos phi
* @param locationType the location type
*/
public EvcsInput(
UUID uuid,
Expand All @@ -69,8 +77,19 @@ public EvcsInput(
NodeInput node,
ReactivePowerCharacteristic qCharacteristics,
ChargingPointType type,
double cosPhiRated) {
this(uuid, id, operator, operationTime, node, qCharacteristics, type, 1, cosPhiRated);
double cosPhiRated,
EvcsLocationType locationType) {
this(
uuid,
id,
operator,
operationTime,
node,
qCharacteristics,
type,
1,
cosPhiRated,
locationType);
}
/**
* @param uuid Unique identifier
Expand All @@ -80,6 +99,7 @@ public EvcsInput(
* @param type type of the charging points available to this charging station
* @param chargingPoints number of charging points available at this charging station
* @param cosPhiRated rated cos phi
* @param locationType the location type
*/
public EvcsInput(
UUID uuid,
Expand All @@ -88,11 +108,13 @@ public EvcsInput(
ReactivePowerCharacteristic qCharacteristics,
ChargingPointType type,
int chargingPoints,
double cosPhiRated) {
double cosPhiRated,
EvcsLocationType locationType) {
super(uuid, id, node, qCharacteristics);
this.type = type;
this.chargingPoints = chargingPoints;
this.cosPhiRated = cosPhiRated;
this.locationType = locationType;
}

/**
Expand All @@ -102,15 +124,17 @@ public EvcsInput(
* @param qCharacteristics Description of a reactive power characteristic
* @param type type of the charging points available to this charging station
* @param cosPhiRated rated cos phi
* @param locationType the location type
*/
public EvcsInput(
UUID uuid,
String id,
NodeInput node,
ReactivePowerCharacteristic qCharacteristics,
ChargingPointType type,
double cosPhiRated) {
this(uuid, id, node, qCharacteristics, type, 1, cosPhiRated);
double cosPhiRated,
EvcsLocationType locationType) {
this(uuid, id, node, qCharacteristics, type, 1, cosPhiRated, locationType);
}

public ChargingPointType getType() {
Expand All @@ -125,6 +149,10 @@ public double getCosPhiRated() {
return cosPhiRated;
}

public EvcsLocationType getLocationType() {
return locationType;
}

@Override
public EvcsInputCopyBuilder copy() {
return new EvcsInputCopyBuilder(this);
Expand All @@ -138,12 +166,13 @@ public boolean equals(Object o) {
EvcsInput evcsInput = (EvcsInput) o;
return chargingPoints == evcsInput.chargingPoints
&& Double.compare(evcsInput.cosPhiRated, cosPhiRated) == 0
&& type.equals(evcsInput.type);
&& type.equals(evcsInput.type)
&& locationType.equals(evcsInput.locationType);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), type, chargingPoints, cosPhiRated);
return Objects.hash(super.hashCode(), type, chargingPoints, cosPhiRated, locationType);
}

@Override
Expand All @@ -160,6 +189,8 @@ public String toString() {
+ chargingPoints
+ ", cosPhiRated="
+ cosPhiRated
+ ", locationType="
+ locationType
+ ", node="
+ getNode()
+ "} "
Expand All @@ -179,12 +210,14 @@ public static class EvcsInputCopyBuilder
private ChargingPointType type;
private int chargingPoints;
private double cosPhiRated;
private EvcsLocationType locationType;

public EvcsInputCopyBuilder(EvcsInput entity) {
super(entity);
this.type = entity.type;
this.chargingPoints = entity.chargingPoints;
this.cosPhiRated = entity.cosPhiRated;
this.locationType = entity.locationType;
}

public EvcsInputCopyBuilder type(ChargingPointType type) {
Expand All @@ -202,6 +235,11 @@ public EvcsInputCopyBuilder cosPhiRated(double cosPhiRated) {
return this;
}

public EvcsInputCopyBuilder locationType(EvcsLocationType locationType) {
this.locationType = locationType;
return this;
}

@Override
public EvcsInput build() {
return new EvcsInput(
Expand All @@ -213,7 +251,8 @@ public EvcsInput build() {
getqCharacteristics(),
type,
chargingPoints,
cosPhiRated);
cosPhiRated,
locationType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.models.input.system.type.evcslocation;

public enum EvcsLocationType {
HOME,
WORK,
CUSTOMER_PARKING,
STREET,
CHARGING_HUB_TOWN,
CHARGING_HUB_HIGHWAY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.models.input.system.type.evcslocation;

import edu.ie3.datamodel.exceptions.ParsingException;
import java.util.HashMap;

public class EvcsLocationTypeUtils {

private static final HashMap<String, EvcsLocationType> nameToType = initMap();

private static HashMap<String, EvcsLocationType> initMap() {
final HashMap<String, EvcsLocationType> map = new HashMap<>(EvcsLocationType.values().length);
for (EvcsLocationType type : EvcsLocationType.values()) map.put(type.name(), type);

return map;
}

private EvcsLocationTypeUtils() {
throw new IllegalStateException("This is a factory class. Don't try to instantiate it.");
}

public static EvcsLocationType parse(String parsableString) throws ParsingException {
if (nameToType.containsKey(parsableString)) return nameToType.get(parsableString);
else throw new ParsingException("EvcsLocationType '" + parsableString + "' does not exist.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import edu.ie3.datamodel.models.input.OperatorInput
import edu.ie3.datamodel.models.input.system.EvcsInput
import edu.ie3.datamodel.models.input.system.characteristic.CharacteristicPoint
import edu.ie3.datamodel.models.input.system.type.chargingpoint.ChargingPointTypeUtils
import edu.ie3.datamodel.models.input.system.type.evcslocation.EvcsLocationType
import edu.ie3.test.helper.FactoryTestHelper
import edu.ie3.util.quantities.PowerSystemUnits
import spock.lang.Specification
Expand Down Expand Up @@ -46,6 +47,7 @@ class EvcsInputFactoryTest extends Specification implements FactoryTestHelper {
"type" : "Household",
"chargingpoints" : "4",
"cosphirated" : "0.95",
"locationtype" : "CHARGING_HUB_TOWN"
]
def inputClass = EvcsInput
def nodeInput = Mock(NodeInput)
Expand Down Expand Up @@ -76,6 +78,7 @@ class EvcsInputFactoryTest extends Specification implements FactoryTestHelper {
assert type == ChargingPointTypeUtils.HouseholdSocket
assert chargingPoints == Integer.parseInt(parameter["chargingpoints"])
assert cosPhiRated == Double.parseDouble(parameter["cosphirated"])
assert locationType == EvcsLocationType.CHARGING_HUB_TOWN
}
}

Expand All @@ -91,6 +94,34 @@ class EvcsInputFactoryTest extends Specification implements FactoryTestHelper {
"type" : "-- invalid --",
"chargingpoints" : "4",
"cosphirated" : "0.95",
"locationtype" : "CHARGING_HUB_TOWN"
]
def inputClass = EvcsInput
def nodeInput = Mock(NodeInput)
def operatorInput = Mock(OperatorInput)

when:
Optional<EvcsInput> input = inputFactory.get(
new NodeAssetInputEntityData(parameter, inputClass, operatorInput, nodeInput))

then:
// FactoryException is caught in Factory.java. We get an empty Option back
!input.present
}

def "A EvcsInputFactory should fail when passing an invalid EvcsLocationType"() {
given: "a system participant input type factory and model data"
def inputFactory = new EvcsInputFactory()
Map<String, String> parameter = [
"uuid" : "91ec3bcf-1777-4d38-af67-0bf7c9fa73c7",
"operatesfrom" : "2019-01-01T00:00:00+01:00[Europe/Berlin]",
"operatesuntil" : "2019-12-31T23:59:00+01:00[Europe/Berlin]",
"id" : "TestID",
"qcharacteristics": "cosPhiFixed:{(0.0,1.0)}",
"type" : "Household",
"chargingpoints" : "4",
"cosphirated" : "0.95",
"locationType" : "-- invalid --"
]
def inputClass = EvcsInput
def nodeInput = Mock(NodeInput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import edu.ie3.test.common.TypeTestData
import spock.lang.Specification
import tech.units.indriya.quantity.Quantities

import java.time.ZoneId
import java.time.ZonedDateTime

import static edu.ie3.util.quantities.PowerSystemUnits.PU
Expand Down Expand Up @@ -279,7 +278,8 @@ class InputEntityProcessorTest extends Specification {
"qCharacteristics": SystemParticipantTestData.cosPhiFixedDeSerialized,
"type" : SystemParticipantTestData.evcsInput.type.toString(),
"cosPhiRated" : SystemParticipantTestData.evcsInput.cosPhiRated.toString(),
"chargingPoints" : SystemParticipantTestData.evcsInput.chargingPoints.toString()
"chargingPoints" : SystemParticipantTestData.evcsInput.chargingPoints.toString(),
"locationType" : SystemParticipantTestData.evcsInput.locationType.name()
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat

where:
nodes | operators || resultingSize || resultingSet
[sptd.evcsInput.node]| [sptd.evcsInput.operator]|| 1 || [sptd.evcsInput]
[sptd.evcsInput.node]| []|| 1 || [
new EvcsInput(sptd.evcsInput.uuid, sptd.evcsInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.evcsInput.operationTime, sptd.evcsInput.node, sptd.evcsInput.qCharacteristics, sptd.evcsInput.type, sptd.evcsInput.chargingPoints, sptd.evcsInput.cosPhiRated)
[sptd.evcsInput.node] | [sptd.evcsInput.operator] || 1 || [sptd.evcsInput]
[sptd.evcsInput.node] | [] || 1 || [
new EvcsInput(sptd.evcsInput.uuid, sptd.evcsInput.id, OperatorInput.NO_OPERATOR_ASSIGNED, sptd.evcsInput.operationTime, sptd.evcsInput.node, sptd.evcsInput.qCharacteristics, sptd.evcsInput.type, sptd.evcsInput.chargingPoints, sptd.evcsInput.cosPhiRated, sptd.evcsInput.locationType)
]
[]| [sptd.evcsInput.operator]|| 0 || []
[]| []|| 0 || []
Expand Down

0 comments on commit 9216532

Please sign in to comment.