Skip to content

Commit f581aa5

Browse files
committed
Enhancing load profile source.
1 parent a089adb commit f581aa5

File tree

14 files changed

+120
-41
lines changed

14 files changed

+120
-41
lines changed

CHANGELOG.md

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

1313
### Changed
1414
- Replaced `return this` with `return thisInstance` in CopyBuilders [#1250](https://github.com/ie3-institute/PowerSystemDataModel/issues/1250)
15+
- Enhancing load profile source [#1294](https://github.com/ie3-institute/PowerSystemDataModel/issues/1294)
1516

1617
## [6.0.0] - 2025-02-27
1718

src/main/java/edu/ie3/datamodel/io/factory/timeseries/BdewLoadProfileFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import edu.ie3.datamodel.models.timeseries.repetitive.BdewLoadProfileTimeSeries;
1616
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileEntry;
1717
import edu.ie3.datamodel.models.value.load.BdewLoadValues;
18+
import edu.ie3.datamodel.models.value.load.LoadValues;
19+
import java.time.ZonedDateTime;
1820
import java.util.*;
1921
import java.util.function.Function;
2022
import java.util.stream.Stream;
@@ -98,6 +100,12 @@ public BdewStandardLoadProfile parseProfile(String profile) {
98100
}
99101
}
100102

103+
@Override
104+
public LoadValues.Provider buildProvider(
105+
BdewLoadValues loadValue, ZonedDateTime time, BdewStandardLoadProfile loadProfile) {
106+
return last -> loadValue.getValue(time, loadProfile);
107+
}
108+
101109
@Override
102110
public ComparableQuantity<Power> calculateMaxPower(
103111
BdewStandardLoadProfile loadProfile, Set<LoadProfileEntry<BdewLoadValues>> entries) {

src/main/java/edu/ie3/datamodel/io/factory/timeseries/LoadProfileFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileTimeSeries;
1313
import edu.ie3.datamodel.models.value.load.LoadValues;
1414
import edu.ie3.util.quantities.PowerSystemUnits;
15+
import java.time.ZonedDateTime;
1516
import java.util.Set;
1617
import javax.measure.quantity.Energy;
1718
import javax.measure.quantity.Power;
@@ -37,6 +38,16 @@ public abstract LoadProfileTimeSeries<V> build(
3738

3839
public abstract P parseProfile(String profile);
3940

41+
/**
42+
* Method to build a {@link LoadValues.Provider}.
43+
*
44+
* @param loadValue used for the provider
45+
* @param time used for the provider
46+
* @param loadProfile used for the provider
47+
* @return a value provider
48+
*/
49+
public abstract LoadValues.Provider buildProvider(V loadValue, ZonedDateTime time, P loadProfile);
50+
4051
/**
4152
* Calculates the maximum average power consumption per quarter-hour for a given calculated over
4253
* all seasons and weekday types of given load profile

src/main/java/edu/ie3/datamodel/io/factory/timeseries/RandomLoadProfileFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import edu.ie3.datamodel.models.profile.LoadProfile.RandomLoadProfile;
1313
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileEntry;
1414
import edu.ie3.datamodel.models.timeseries.repetitive.RandomLoadProfileTimeSeries;
15+
import edu.ie3.datamodel.models.value.load.LoadValues;
1516
import edu.ie3.datamodel.models.value.load.RandomLoadValues;
1617
import edu.ie3.util.quantities.PowerSystemUnits;
18+
import java.time.ZonedDateTime;
1719
import java.util.List;
1820
import java.util.Set;
1921
import javax.measure.quantity.Energy;
@@ -88,6 +90,12 @@ public RandomLoadProfile parseProfile(String profile) {
8890
return RANDOM_LOAD_PROFILE;
8991
}
9092

93+
@Override
94+
public LoadValues.Provider buildProvider(
95+
RandomLoadValues loadValue, ZonedDateTime time, RandomLoadProfile loadProfile) {
96+
return last -> loadValue.sample(time);
97+
}
98+
9199
/**
92100
* This is the 95 % quantile resulting from 10,000 evaluations of the year 2019. It is only
93101
* needed, when the load is meant to be scaled to rated active power.

src/main/java/edu/ie3/datamodel/io/source/LoadProfileSource.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileEntry;
2222
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileTimeSeries;
2323
import edu.ie3.datamodel.models.timeseries.repetitive.RandomLoadProfileTimeSeries;
24-
import edu.ie3.datamodel.models.value.PValue;
25-
import edu.ie3.datamodel.models.value.Value;
2624
import edu.ie3.datamodel.models.value.load.BdewLoadValues;
2725
import edu.ie3.datamodel.models.value.load.LoadValues;
2826
import edu.ie3.datamodel.models.value.load.RandomLoadValues;
@@ -48,8 +46,7 @@ protected LoadProfileSource(Class<V> entryClass, LoadProfileFactory<P, V> entryF
4846
}
4947

5048
/**
51-
* Build a list of type {@code E}, whereas the underlying {@link Value} does not need any
52-
* additional information.
49+
* Build a {@link LoadProfileEntry} of type {@code V}.
5350
*
5451
* @param fieldToValues Mapping from field id to values
5552
* @return {@link Try} of simple time based value
@@ -77,7 +74,7 @@ protected Try<LoadProfileEntry<V>, FactoryException> createEntries(
7774
* @return an optional
7875
* @throws SourceException if an exception occurred
7976
*/
80-
public abstract Optional<PValue> getValue(ZonedDateTime time) throws SourceException;
77+
public abstract Optional<LoadValues.Provider> getValue(ZonedDateTime time) throws SourceException;
8178

8279
/** Returns the load profile of this source. */
8380
public abstract P getLoadProfile();

src/main/java/edu/ie3/datamodel/io/source/csv/CsvLoadProfileSource.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import edu.ie3.datamodel.models.profile.LoadProfile;
1515
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileEntry;
1616
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileTimeSeries;
17-
import edu.ie3.datamodel.models.value.PValue;
1817
import edu.ie3.datamodel.models.value.load.LoadValues;
1918
import edu.ie3.datamodel.utils.Try;
2019
import java.nio.file.Path;
2120
import java.time.ZonedDateTime;
22-
import java.util.*;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.Optional;
24+
import java.util.Set;
2325
import java.util.function.Function;
2426
import java.util.stream.Collectors;
2527
import javax.measure.quantity.Energy;
@@ -72,7 +74,7 @@ public List<ZonedDateTime> getTimeKeysAfter(ZonedDateTime time) {
7274
}
7375

7476
@Override
75-
public Optional<PValue> getValue(ZonedDateTime time) throws SourceException {
77+
public Optional<LoadValues.Provider> getValue(ZonedDateTime time) throws SourceException {
7678
return loadProfileTimeSeries.getValue(time);
7779
}
7880

src/main/java/edu/ie3/datamodel/io/source/sql/SqlLoadProfileSource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import edu.ie3.datamodel.models.profile.LoadProfile;
1818
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileEntry;
1919
import edu.ie3.datamodel.models.timeseries.repetitive.LoadProfileTimeSeries;
20-
import edu.ie3.datamodel.models.value.PValue;
2120
import edu.ie3.datamodel.models.value.Value;
2221
import edu.ie3.datamodel.models.value.load.LoadValues;
2322
import edu.ie3.datamodel.utils.TimeSeriesUtils;
@@ -112,12 +111,14 @@ public List<ZonedDateTime> getTimeKeysAfter(ZonedDateTime time) {
112111
}
113112

114113
@Override
115-
public Optional<PValue> getValue(ZonedDateTime time) throws SourceException {
114+
public Optional<LoadValues.Provider> getValue(ZonedDateTime time) throws SourceException {
116115
Set<LoadProfileEntry<V>> entries =
117116
getEntries(queryTime, ps -> ps.setInt(1, TimeSeriesUtils.calculateQuarterHourOfDay(time)));
118117
if (entries.isEmpty()) return Optional.empty();
119118
if (entries.size() > 1) log.warn("Retrieved more than one result value, using the first");
120-
return Optional.of(entries.stream().toList().get(0).getValue().getValue(time, loadProfile));
119+
120+
V loadValue = entries.stream().toList().get(0).getValue();
121+
return Optional.of(entryFactory.buildProvider(loadValue, time, loadProfile));
121122
}
122123

123124
@Override

src/main/java/edu/ie3/datamodel/models/timeseries/repetitive/BdewLoadProfileTimeSeries.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import edu.ie3.datamodel.models.profile.BdewStandardLoadProfile;
99
import edu.ie3.datamodel.models.value.load.BdewLoadValues;
10+
import edu.ie3.datamodel.models.value.load.LoadValues;
11+
import java.time.ZonedDateTime;
1012
import java.util.Objects;
1113
import java.util.Set;
1214
import java.util.UUID;
@@ -29,6 +31,11 @@ public BdewLoadProfileTimeSeries(
2931
super(uuid, loadProfile, values, maxPower, profileEnergyScaling);
3032
}
3133

34+
@Override
35+
protected LoadValues.Provider buildFunction(BdewLoadValues loadValue, ZonedDateTime time) {
36+
return last -> loadValue.getValue(time, (BdewStandardLoadProfile) loadProfile);
37+
}
38+
3239
@Override
3340
public BdewStandardLoadProfile getLoadProfile() {
3441
return (BdewStandardLoadProfile) super.getLoadProfile();

src/main/java/edu/ie3/datamodel/models/timeseries/repetitive/LoadProfileTimeSeries.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package edu.ie3.datamodel.models.timeseries.repetitive;
77

88
import edu.ie3.datamodel.models.profile.LoadProfile;
9-
import edu.ie3.datamodel.models.value.PValue;
109
import edu.ie3.datamodel.models.value.load.LoadValues;
1110
import edu.ie3.datamodel.utils.TimeSeriesUtils;
1211
import java.time.ZonedDateTime;
@@ -18,10 +17,12 @@
1817

1918
/**
2019
* Describes a load profile time series with repetitive values that can be calculated from a pattern
20+
*
21+
* @param <V> type of {@link LoadValues} used in this time series.
2122
*/
22-
public class LoadProfileTimeSeries<V extends LoadValues>
23-
extends RepetitiveTimeSeries<LoadProfileEntry<V>, V, PValue> {
24-
private final LoadProfile loadProfile;
23+
public abstract class LoadProfileTimeSeries<V extends LoadValues>
24+
extends RepetitiveTimeSeries<LoadProfileEntry<V>, V, LoadValues.Provider> {
25+
protected final LoadProfile loadProfile;
2526
private final Map<Integer, V> valueMapping;
2627

2728
/**
@@ -33,7 +34,7 @@ public class LoadProfileTimeSeries<V extends LoadValues>
3334
/** The profile energy scaling in kWh. */
3435
private final ComparableQuantity<Energy> profileEnergyScaling;
3536

36-
public LoadProfileTimeSeries(
37+
protected LoadProfileTimeSeries(
3738
UUID uuid,
3839
LoadProfile loadProfile,
3940
Set<LoadProfileEntry<V>> entries,
@@ -50,6 +51,21 @@ public LoadProfileTimeSeries(
5051
this.profileEnergyScaling = profileEnergyScaling;
5152
}
5253

54+
@Override
55+
protected LoadValues.Provider calc(ZonedDateTime time) {
56+
int quarterHour = TimeSeriesUtils.calculateQuarterHourOfDay(time);
57+
return buildFunction(valueMapping.get(quarterHour), time);
58+
}
59+
60+
/**
61+
* Method to build a {@link LoadValues.Provider} for the given {@link LoadValues} and time.
62+
*
63+
* @param loadValue used for the provider
64+
* @param time used for the provider
65+
* @return a {@link LoadValues.Provider}
66+
*/
67+
protected abstract LoadValues.Provider buildFunction(V loadValue, ZonedDateTime time);
68+
5369
/**
5470
* Returns the maximum average power consumption per quarter-hour calculated over all seasons and
5571
* weekday types of given load profile in Watt.
@@ -97,12 +113,6 @@ protected Map<Integer, V> getValueMapping() {
97113
return valueMapping;
98114
}
99115

100-
@Override
101-
protected PValue calc(ZonedDateTime time) {
102-
int quarterHour = TimeSeriesUtils.calculateQuarterHourOfDay(time);
103-
return valueMapping.get(quarterHour).getValue(time, loadProfile);
104-
}
105-
106116
@Override
107117
public boolean equals(Object o) {
108118
if (this == o) return true;

src/main/java/edu/ie3/datamodel/models/timeseries/repetitive/RandomLoadProfileTimeSeries.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import de.lmu.ifi.dbs.elki.math.statistics.distribution.GeneralizedExtremeValueDistribution;
99
import edu.ie3.datamodel.models.profile.LoadProfile;
10+
import edu.ie3.datamodel.models.value.load.LoadValues;
1011
import edu.ie3.datamodel.models.value.load.RandomLoadValues;
12+
import java.time.ZonedDateTime;
1113
import java.util.Set;
1214
import java.util.UUID;
1315
import javax.measure.quantity.Energy;
@@ -29,6 +31,11 @@ public RandomLoadProfileTimeSeries(
2931
super(uuid, loadProfile, entries, maxPower, profileEnergyScaling);
3032
}
3133

34+
@Override
35+
protected LoadValues.Provider buildFunction(RandomLoadValues loadValue, ZonedDateTime time) {
36+
return last -> loadValue.sample(time);
37+
}
38+
3239
@Override
3340
public LoadProfile.RandomLoadProfile getLoadProfile() {
3441
return (LoadProfile.RandomLoadProfile) super.getLoadProfile();

0 commit comments

Comments
 (0)