Skip to content

Commit 42e8599

Browse files
Optional
1 parent e80cb33 commit 42e8599

File tree

4 files changed

+36
-39
lines changed

4 files changed

+36
-39
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.time.format.DateTimeFormatter;
1616
import java.util.Arrays;
1717
import java.util.List;
18+
import java.util.Optional;
1819
import java.util.Set;
1920
import javax.measure.quantity.Angle;
2021
import javax.measure.quantity.Speed;
@@ -32,8 +33,8 @@ public class CosmoTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFact
3233
private static final String TEMPERATURE = "temperature";
3334
private static final String WIND_DIRECTION = "windDirection";
3435
private static final String WIND_VELOCITY = "windVelocity";
35-
private static final String GROUND_TEMPERATURE_0CM = "groundTemperature0cm";
36-
private static final String GROUND_TEMPERATURE_80CM = "groundTemperature80cm";
36+
private static final String GROUND_TEMPERATURE_VALUE_ONE = "groundTemperature0cm";
37+
private static final String GROUND_TEMPERATURE_VALUE_TWO = "groundTemperature80cm";
3738

3839
public CosmoTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
3940
super(timeUtil);
@@ -59,7 +60,7 @@ protected List<Set<String>> getFields(Class<?> entityClass) {
5960
WIND_VELOCITY);
6061

6162
Set<String> withGroundTemp =
62-
expandSet(minConstructorParams, GROUND_TEMPERATURE_0CM, GROUND_TEMPERATURE_80CM);
63+
expandSet(minConstructorParams, GROUND_TEMPERATURE_VALUE_ONE, GROUND_TEMPERATURE_VALUE_TWO);
6364

6465
return Arrays.asList(minConstructorParams, withGroundTemp);
6566
}
@@ -78,11 +79,10 @@ protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data
7879
data.getQuantity(WIND_DIRECTION, StandardUnits.WIND_DIRECTION);
7980
ComparableQuantity<Speed> windVelocity =
8081
data.getQuantity(WIND_VELOCITY, StandardUnits.WIND_VELOCITY);
81-
ComparableQuantity<Temperature> groundTemp0cm =
82-
data.getQuantityOptional(GROUND_TEMPERATURE_0CM, StandardUnits.TEMPERATURE).orElse(null);
83-
ComparableQuantity<Temperature> groundTemp80cm =
84-
data.getQuantityOptional(GROUND_TEMPERATURE_80CM, StandardUnits.TEMPERATURE).orElse(null);
85-
82+
Optional<ComparableQuantity<Temperature>> groundTempValOne =
83+
data.getQuantityOptional(GROUND_TEMPERATURE_VALUE_ONE, StandardUnits.TEMPERATURE);
84+
Optional<ComparableQuantity<Temperature>> groundTempValTwo =
85+
data.getQuantityOptional(GROUND_TEMPERATURE_VALUE_TWO, StandardUnits.TEMPERATURE);
8686
WeatherValue weatherValue =
8787
new WeatherValue(
8888
coordinate,
@@ -91,8 +91,8 @@ protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data
9191
temperature,
9292
windDirection,
9393
windVelocity,
94-
groundTemp0cm,
95-
groundTemp80cm);
94+
groundTempValOne,
95+
groundTempValTwo);
9696

9797
return new TimeBasedValue<>(time, weatherValue);
9898
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ protected List<Set<String>> getFields(Class<?> entityClass) {
5555
"albrad",
5656
"asobs",
5757
"aswdifuS",
58-
"t_g",
5958
"t_v1",
6059
"t_v2",
6160
"u10m",
@@ -92,10 +91,10 @@ protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data
9291
data.getQuantity(TEMPERATURE, Units.KELVIN).to(StandardUnits.TEMPERATURE);
9392
ComparableQuantity<Angle> windDirection = getWindDirection(data);
9493
ComparableQuantity<Speed> windVelocity = getWindVelocity(data);
95-
ComparableQuantity<Temperature> groundTemperatureValueOne =
96-
data.getQuantityOptional(GROUND_TEMPERATURE_VALUE_ONE, Units.KELVIN).orElse(null);
97-
ComparableQuantity<Temperature> groundTemperatureValueTwo =
98-
data.getQuantityOptional(GROUND_TEMPERATURE_VALUE_TWO, Units.KELVIN).orElse(null);
94+
Optional<ComparableQuantity<Temperature>> groundTemperatureValueOne =
95+
data.getQuantityOptional(GROUND_TEMPERATURE_VALUE_ONE, Units.KELVIN);
96+
Optional<ComparableQuantity<Temperature>> groundTemperatureValueTwo =
97+
data.getQuantityOptional(GROUND_TEMPERATURE_VALUE_TWO, Units.KELVIN);
9998

10099
WeatherValue weatherValue =
101100
new WeatherValue(

src/main/java/edu/ie3/datamodel/models/value/WeatherValue.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public class WeatherValue implements Value {
2828
/** Wind values for this coordinate */
2929
private final WindValue wind;
3030

31-
/** Ground temperature value at 0cm depth for this coordinate */
32-
private final GroundTemperatureValue groundTemperatureValueOne;
31+
/** Ground temperature value for this coordinate */
32+
private final Optional<GroundTemperatureValue> groundTemperatureValueOne;
3333

34-
/** Ground temperature value at 80cm depth for this coordinate */
35-
private final GroundTemperatureValue groundTemperatureValueTwo;
34+
/** Ground temperature value for this coordinate */
35+
private final Optional<GroundTemperatureValue> groundTemperatureValueTwo;
3636

3737
/**
3838
* @param coordinate of this weather value set
@@ -47,8 +47,8 @@ public WeatherValue(
4747
SolarIrradianceValue solarIrradiance,
4848
TemperatureValue temperature,
4949
WindValue wind,
50-
GroundTemperatureValue groundTemperatureValueOne,
51-
GroundTemperatureValue groundTemperatureValueTwo) {
50+
Optional<GroundTemperatureValue> groundTemperatureValueOne,
51+
Optional<GroundTemperatureValue> groundTemperatureValueTwo) {
5252
this.coordinate = coordinate;
5353
this.solarIrradiance = solarIrradiance;
5454
this.temperature = temperature;
@@ -67,10 +67,8 @@ public WeatherValue(
6767
* @param direction Direction, the wind comes from as an angle from north increasing clockwise
6868
* (typically in rad)
6969
* @param velocity Wind velocity for this coordinate (typically in m/s)
70-
* @param groundTempValOne Ground temperature at 0cm for this coordinate (typically in K, can be
71-
* null)
72-
* @param groundTempValTwo Ground temperature at 80cm for this coordinate (typically in K, can be
73-
* null)
70+
* @param groundTempValOne Ground temperature for this coordinate (typically in K, can be null)
71+
* @param groundTempValTwo Ground temperature for this coordinate (typically in K, can be null)
7472
*/
7573
public WeatherValue(
7674
Point coordinate,
@@ -79,15 +77,15 @@ public WeatherValue(
7977
ComparableQuantity<Temperature> temperature,
8078
ComparableQuantity<Angle> direction,
8179
ComparableQuantity<Speed> velocity,
82-
ComparableQuantity<Temperature> groundTempValOne,
83-
ComparableQuantity<Temperature> groundTempValTwo) {
80+
Optional<ComparableQuantity<Temperature>> groundTempValOne,
81+
Optional<ComparableQuantity<Temperature>> groundTempValTwo) {
8482
this(
8583
coordinate,
8684
new SolarIrradianceValue(directSolarIrradiance, diffuseSolarIrradiance),
8785
new TemperatureValue(temperature),
8886
new WindValue(direction, velocity),
89-
groundTempValOne.map(GroundTemperatureValue::new),
90-
groundTempValTwo.map(GroundTemperatureValue::new));
87+
groundTempValOne.map(GroundTemperatureValue::new),
88+
groundTempValTwo.map(GroundTemperatureValue::new));
9189
}
9290

9391
public Point getCoordinate() {
@@ -107,11 +105,11 @@ public WindValue getWind() {
107105
}
108106

109107
public Optional<GroundTemperatureValue> getGroundTemperatureValueOne() {
110-
return Optional.ofNullable(groundTemperatureValueOne);
108+
return groundTemperatureValueOne;
111109
}
112110

113111
public Optional<GroundTemperatureValue> getGroundTemperatureValueTwo() {
114-
return Optional.ofNullable(groundTemperatureValueTwo);
112+
return groundTemperatureValueTwo;
115113
}
116114

117115
@Override

src/test/groovy/edu/ie3/test/common/TimeSeriesTestData.groovy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ trait TimeSeriesTestData {
207207
new SolarIrradianceValue(Quantities.getQuantity(10d, StandardUnits.SOLAR_IRRADIANCE), Quantities.getQuantity(15d, StandardUnits.SOLAR_IRRADIANCE)),
208208
new TemperatureValue(Quantities.getQuantity(10d, CELSIUS)),
209209
new WindValue(Quantities.getQuantity(10d, DEGREE_GEOM), Quantities.getQuantity(15d, METRE_PER_SECOND)),
210-
null,
211-
null
210+
new GroundTemperatureValue(Quantities.getQuantity(10d, CELSIUS)),
211+
new GroundTemperatureValue(Quantities.getQuantity(10d, CELSIUS))
212212
)
213213
),
214214
] as Set
@@ -223,8 +223,8 @@ trait TimeSeriesTestData {
223223
"temperature" : "5.0",
224224
"time" : "2020-04-02T10:00:00Z",
225225
"velocity" : "10.0",
226-
"groundTemperatureValueOne" : "",
227-
"groundTemperatureValueTwo" : ""
226+
"groundTemperatureValueOne" : "10.0",
227+
"groundTemperatureValueTwo" : "10.0"
228228
] as LinkedHashMap,
229229
[
230230
"coordinate" : "{\"type\":\"Point\",\"coordinates\":[7.412152,51.492758],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}",
@@ -234,8 +234,8 @@ trait TimeSeriesTestData {
234234
"temperature" : "15.0",
235235
"time" : "2020-04-02T10:15:00Z",
236236
"velocity" : "20.0",
237-
"groundTemperatureValueOne" : "",
238-
"groundTemperatureValueTwo" : ""
237+
"groundTemperatureValueOne" : "10.0",
238+
"groundTemperatureValueTwo" : "10.0"
239239
] as LinkedHashMap,
240240
[
241241
"coordinate" : "{\"type\":\"Point\",\"coordinates\":[7.412152,51.492758],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}",
@@ -245,8 +245,8 @@ trait TimeSeriesTestData {
245245
"temperature" : "10.0",
246246
"time" : "2020-04-02T10:30:00Z",
247247
"velocity" : "15.0",
248-
"groundTemperatureValueOne" : "",
249-
"groundTemperatureValueTwo" : ""
248+
"groundTemperatureValueOne" : "10.0",
249+
"groundTemperatureValueTwo" : "10.0"
250250
] as LinkedHashMap
251251
] as Set
252252

0 commit comments

Comments
 (0)