Skip to content

Commit c5d6ea7

Browse files
committed
Some improvements to providing the PSDM with LoadProfiles.
1 parent 478d57d commit c5d6ea7

File tree

7 files changed

+80
-73
lines changed

7 files changed

+80
-73
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ dependencies {
7272
implementation 'org.jgrapht:jgrapht-core:1.5.2'
7373

7474
// Statistics (for random load model)
75-
implementation 'de.lmu.ifi.dbs.elki:elki:0.7.5'
75+
implementation 'de.lmu.ifi.dbs.elki:elki-core-math:0.7.5'
7676

7777
// testing
7878
testImplementation "org.apache.groovy:groovy:$groovyBinaryVersion"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* © 2025. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
package edu.ie3.datamodel.io.provider;
7+
8+
import edu.ie3.datamodel.io.factory.timeseries.BdewLoadProfileFactory;
9+
import edu.ie3.datamodel.io.factory.timeseries.LoadProfileFactory;
10+
import edu.ie3.datamodel.io.factory.timeseries.RandomLoadProfileFactory;
11+
import edu.ie3.datamodel.models.profile.BdewStandardLoadProfile;
12+
import edu.ie3.datamodel.models.profile.LoadProfile;
13+
import edu.ie3.datamodel.models.profile.NbwTemperatureDependantLoadProfile;
14+
import java.util.*;
15+
import java.util.stream.Collectors;
16+
import java.util.stream.Stream;
17+
18+
/** Interface defining a provider for {@link LoadProfile}s and their {@link LoadProfileFactory}. */
19+
public interface LoadProfileProvider {
20+
21+
/** A list of all {@link LoadProfile}, that are known. */
22+
List<? extends LoadProfile> loadedProfiles =
23+
ServiceLoader.load(LoadProfileProvider.class).stream()
24+
.map(ServiceLoader.Provider::get)
25+
.map(LoadProfileProvider::getProfiles)
26+
.flatMap(Collection::stream)
27+
.toList();
28+
29+
/** A map of all known {@link LoadProfile} to their {@link LoadProfileFactory}. */
30+
Map<? extends LoadProfile, ? extends LoadProfileFactory<?, ?>> profileToFactories =
31+
ServiceLoader.load(LoadProfileProvider.class).stream()
32+
.map(ServiceLoader.Provider::get)
33+
.map(LoadProfileProvider::getFactories)
34+
.flatMap(map -> map.entrySet().stream())
35+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
36+
37+
/** Returns a list of {@link LoadProfile}s. */
38+
List<? extends LoadProfile> getProfiles();
39+
40+
/** Returns a map of {@link LoadProfile} to {@link LoadProfileFactory}. */
41+
Map<LoadProfile, LoadProfileFactory<?, ?>> getFactories();
42+
43+
/**
44+
* Default load profile provider. This class is used to provide the {@link LoadProfile}s defined
45+
* in the PSDM.
46+
*/
47+
final class DefaultLoadProfileProvider implements LoadProfileProvider {
48+
49+
@Override
50+
public List<? extends LoadProfile> getProfiles() {
51+
return Stream.of(
52+
BdewStandardLoadProfile.values(),
53+
NbwTemperatureDependantLoadProfile.values(),
54+
LoadProfile.RandomLoadProfile.values(),
55+
LoadProfile.DefaultLoadProfiles.values())
56+
.flatMap(Arrays::stream)
57+
.toList();
58+
}
59+
60+
@Override
61+
public Map<LoadProfile, LoadProfileFactory<?, ?>> getFactories() {
62+
BdewLoadProfileFactory bdewLoadProfileFactory = new BdewLoadProfileFactory();
63+
64+
Map<LoadProfile, LoadProfileFactory<?, ?>> factories = new HashMap<>();
65+
66+
Arrays.stream(BdewStandardLoadProfile.values())
67+
.forEach(profile -> factories.put(profile, bdewLoadProfileFactory));
68+
69+
factories.put(
70+
LoadProfile.RandomLoadProfile.RANDOM_LOAD_PROFILE, new RandomLoadProfileFactory());
71+
72+
return factories;
73+
}
74+
}
75+
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
package edu.ie3.datamodel.models.profile;
77

88
import edu.ie3.datamodel.exceptions.ParsingException;
9+
import edu.ie3.datamodel.io.provider.LoadProfileProvider;
910
import java.io.Serializable;
1011
import java.util.Arrays;
11-
import java.util.Collection;
12-
import java.util.ServiceLoader;
1312
import java.util.stream.Collectors;
1413

1514
public interface LoadProfile extends Serializable {
@@ -34,11 +33,7 @@ static LoadProfile parse(String key) throws ParsingException {
3433
* {@link LoadProfileProvider}.
3534
*/
3635
static LoadProfile[] getAllProfiles() {
37-
return ServiceLoader.load(LoadProfileProvider.class).stream()
38-
.map(ServiceLoader.Provider::get)
39-
.map(LoadProfileProvider::getProfiles)
40-
.flatMap(Collection::stream)
41-
.toArray(LoadProfile[]::new);
36+
return LoadProfileProvider.loadedProfiles.toArray(LoadProfile[]::new);
4237
}
4338

4439
/**

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

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main/java/module-info.java

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edu.ie3.datamodel.io.provider.LoadProfileProvider$DefaultLoadProfileProvider

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,6 @@ class LoadProfileTest extends Specification {
187187

188188
then:
189189
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"
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, No load profile assigned"
191191
}
192192
}

0 commit comments

Comments
 (0)