Skip to content

Commit 0ec4ad8

Browse files
committed
Refactor calculation of max power for BdewLoadValues.
1 parent c3c38f7 commit 0ec4ad8

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.List;
2424
import java.util.Set;
2525
import java.util.function.Function;
26-
import java.util.stream.Stream;
2726
import javax.measure.quantity.Energy;
2827
import javax.measure.quantity.Power;
2928
import tech.units.indriya.ComparableQuantity;
@@ -93,19 +92,19 @@ public BdewStandardLoadProfile parseProfile(String profile) {
9392
@Override
9493
public ComparableQuantity<Power> calculateMaxPower(
9594
BdewStandardLoadProfile loadProfile, Set<LoadProfileEntry<BdewLoadValues>> entries) {
96-
Function<BdewLoadValues, Stream<Double>> valueExtractor =
95+
Function<BdewLoadValues, Double> valueExtractor =
9796
switch (loadProfile) {
9897
case H0, H25, P25, S25 ->
9998
// maximum dynamization factor is on day 366 (leap year) or day 365 (regular year).
10099
// The difference between day 365 and day 366 is negligible, thus pick 366
101-
v -> v.lastDayOfYearValues().map(p -> BdewLoadValues.dynamization(p, 366));
102-
default -> BdewLoadValues::values;
100+
v -> BdewLoadValues.dynamization(v.getMaxValue(true), 366);
101+
default -> v -> v.getMaxValue(false);
103102
};
104103

105104
double maxPower =
106105
entries.stream()
107106
.map(TimeSeriesEntry::getValue)
108-
.flatMap(valueExtractor)
107+
.map(valueExtractor)
109108
.max(Comparator.naturalOrder())
110109
.orElse(0d);
111110

src/main/java/edu/ie3/datamodel/models/value/load/BdewLoadValues.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,35 @@ public double get(BdewKey key) {
7070
return values.get(key);
7171
}
7272

73-
/** Returns the values, that may contain the last day of the year, as a stream. */
74-
public Stream<Double> lastDayOfYearValues() {
75-
Stream<BdewKey> keys =
76-
switch (scheme) {
77-
case BDEW1999 -> Stream.of(
78-
new Bdew1999Key(WINTER, DayType.SATURDAY),
79-
new Bdew1999Key(WINTER, DayType.SUNDAY),
80-
new Bdew1999Key(WINTER, DayType.WEEKDAY));
81-
case BDEW2025 -> Stream.of(
82-
new Bdew2025Key(DECEMBER, DayType.SATURDAY),
83-
new Bdew2025Key(DECEMBER, DayType.SUNDAY),
84-
new Bdew2025Key(DECEMBER, DayType.WEEKDAY));
85-
};
86-
87-
return keys.map(values::get);
88-
}
73+
/**
74+
* Method to calculate the maximal value contained in this {@link BdewLoadValues}.
75+
*
76+
* @param lastDayOfYear if true, only the values, that could occur at the last day of a year, are
77+
* considered
78+
* @return the maximal value
79+
*/
80+
public double getMaxValue(boolean lastDayOfYear) {
81+
Stream<Double> stream;
82+
83+
if (lastDayOfYear) {
84+
Stream<BdewKey> keys =
85+
switch (scheme) {
86+
case BDEW1999 -> Stream.of(
87+
new Bdew1999Key(WINTER, DayType.SATURDAY),
88+
new Bdew1999Key(WINTER, DayType.SUNDAY),
89+
new Bdew1999Key(WINTER, DayType.WEEKDAY));
90+
case BDEW2025 -> Stream.of(
91+
new Bdew2025Key(DECEMBER, DayType.SATURDAY),
92+
new Bdew2025Key(DECEMBER, DayType.SUNDAY),
93+
new Bdew2025Key(DECEMBER, DayType.WEEKDAY));
94+
};
95+
96+
stream = keys.map(values::get);
97+
} else {
98+
stream = values.values().stream();
99+
}
89100

90-
/** Returns the values as a stream. */
91-
public Stream<Double> values() {
92-
return values.values().stream();
101+
return stream.max(Comparator.naturalOrder()).orElse(0.0);
93102
}
94103

95104
@Override

0 commit comments

Comments
 (0)