Skip to content

Commit 90f4c16

Browse files
committed
Adding support for custom load profiles.
1 parent 7e14215 commit 90f4c16

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
- Extend Validation to EnergyManagement Systems. [#1356](https://github.com/ie3-institute/PowerSystemDataModel/issues/1356)
11+
- Added support for custom load profiles [#1362](https://github.com/ie3-institute/PowerSystemDataModel/issues/1362)
1112

1213
### Fixed
1314
- Fixed handling of `CongestionResult.InputModelType` in `EntityProcessor` [#1325](https://github.com/ie3-institute/PowerSystemDataModel/issues/1325)

src/main/java/edu/ie3/datamodel/io/factory/input/participant/LoadInputFactory.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package edu.ie3.datamodel.io.factory.input.participant;
77

8-
import edu.ie3.datamodel.exceptions.ParsingException;
98
import edu.ie3.datamodel.models.OperationTime;
109
import edu.ie3.datamodel.models.StandardUnits;
1110
import edu.ie3.datamodel.models.input.EmInput;
@@ -17,13 +16,10 @@
1716
import java.util.UUID;
1817
import javax.measure.quantity.Energy;
1918
import javax.measure.quantity.Power;
20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
2219
import tech.units.indriya.ComparableQuantity;
2320

2421
public class LoadInputFactory
2522
extends SystemParticipantInputEntityFactory<LoadInput, SystemParticipantEntityData> {
26-
private static final Logger logger = LoggerFactory.getLogger(LoadInputFactory.class);
2723

2824
private static final String LOAD_PROFILE = "loadProfile";
2925
private static final String E_CONS_ANNUAL = "eConsAnnual";
@@ -48,16 +44,8 @@ protected LoadInput buildModel(
4844
ReactivePowerCharacteristic qCharacteristics,
4945
OperatorInput operator,
5046
OperationTime operationTime) {
51-
LoadProfile loadProfile;
52-
try {
53-
loadProfile = LoadProfile.parse(data.getField(LOAD_PROFILE));
54-
} catch (ParsingException e) {
55-
logger.warn(
56-
"Cannot parse the standard load profile \"{}\" of load \"{}\". Assign no load profile instead.",
57-
data.getField(LOAD_PROFILE),
58-
id);
59-
loadProfile = LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE;
60-
}
47+
LoadProfile loadProfile = LoadProfile.parse(data.getField(LOAD_PROFILE));
48+
6149
final EmInput em = data.getControllingEm().orElse(null);
6250

6351
final ComparableQuantity<Energy> eConsAnnual =

src/main/java/edu/ie3/datamodel/models/profile/LoadProfile.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
*/
66
package edu.ie3.datamodel.models.profile;
77

8-
import edu.ie3.datamodel.exceptions.ParsingException;
98
import java.io.Serializable;
109
import java.util.Arrays;
11-
import java.util.stream.Collectors;
1210
import java.util.stream.Stream;
1311

1412
public interface LoadProfile extends Serializable {
@@ -20,9 +18,8 @@ public interface LoadProfile extends Serializable {
2018
*
2119
* @param key Key to parse
2220
* @return Matching {@link StandardLoadProfile}
23-
* @throws ParsingException If key cannot be parsed
2421
*/
25-
static LoadProfile parse(String key) throws ParsingException {
22+
static LoadProfile parse(String key) {
2623
if (key == null || key.isEmpty()) return LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE;
2724

2825
return LoadProfile.getProfile(getAllProfiles(), key);
@@ -38,25 +35,21 @@ static LoadProfile[] getAllProfiles() {
3835
}
3936

4037
/**
41-
* Looks for load profile with given key and returns it.
38+
* Looks for load profile with given key and returns it. If no suitable profile is found, a {@link
39+
* CustomLoadProfile} with the given key is returned.
4240
*
4341
* @param profiles we search within
4442
* @param key to look for
4543
* @return the matching load profile
4644
*/
47-
static <T extends LoadProfile> T getProfile(T[] profiles, String key) throws ParsingException {
45+
@SuppressWarnings("unchecked")
46+
static <T extends LoadProfile> T getProfile(T[] profiles, String key) {
47+
String uniformKey = getUniformKey(key);
48+
4849
return Arrays.stream(profiles)
49-
.filter(loadProfile -> loadProfile.getKey().equalsIgnoreCase(getUniformKey(key)))
50+
.filter(loadProfile -> loadProfile.getKey().equalsIgnoreCase(uniformKey))
5051
.findFirst()
51-
.orElseThrow(
52-
() ->
53-
new ParsingException(
54-
"No predefined load profile with key '"
55-
+ key
56-
+ "' found. Please provide one of the following keys: "
57-
+ Arrays.stream(profiles)
58-
.map(LoadProfile::getKey)
59-
.collect(Collectors.joining(", "))));
52+
.orElseGet(() -> (T) new CustomLoadProfile(uniformKey));
6053
}
6154

6255
private static String getUniformKey(String key) {
@@ -72,6 +65,13 @@ public String getKey() {
7265
}
7366
}
7467

68+
record CustomLoadProfile(String key) implements LoadProfile {
69+
@Override
70+
public String getKey() {
71+
return key;
72+
}
73+
}
74+
7575
enum RandomLoadProfile implements LoadProfile {
7676
RANDOM_LOAD_PROFILE;
7777

src/test/groovy/edu/ie3/datamodel/models/profile/LoadProfileTest.groovy

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package edu.ie3.datamodel.models.profile
77

88
import static edu.ie3.datamodel.models.profile.LoadProfile.RandomLoadProfile.RANDOM_LOAD_PROFILE
99

10-
import edu.ie3.datamodel.exceptions.ParsingException
1110
import spock.lang.Specification
1211

1312
class LoadProfileTest extends Specification {
@@ -181,12 +180,19 @@ class LoadProfileTest extends Specification {
181180
"ez_2" || NbwTemperatureDependantLoadProfile.EZ2
182181
}
183182

184-
def "Throws an exception when encountering an unknown key"() {
183+
def "Return a custom load profile when encountering an unknown key"() {
185184
when:
186-
LoadProfile.parse("not_a_key")
185+
def custom = LoadProfile.parse("not_a_key")
187186

188187
then:
189-
def e = thrown(ParsingException)
190-
e.message == "No predefined load profile with key 'not_a_key' found. Please provide one of the following keys: h0, l0, l1, l2, g0, g1, g2, g3, g4, g5, g6, ep1, ez2, random"
188+
custom == new LoadProfile.CustomLoadProfile("notakey")
189+
}
190+
191+
def "Return nothing when encountering an empty key"() {
192+
when:
193+
def actual = LoadProfile.parse(null)
194+
195+
then:
196+
actual == LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE
191197
}
192198
}

0 commit comments

Comments
 (0)