Skip to content

Fix returning null in TimeBasedWeatherValueData.java #1302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fixed SonarQube junit path issue in GitHub Actions [#1284](https://github.com/ie3-institute/PowerSystemDataModel/issues/1284)
### Changed
- Fix returning null in TimeBasedWeatherValueData [#356](https://github.com/ie3-institute/PowerSystemDataModel/issues/356)

- ### Changed
- Replaced `return this` with `return thisInstance` in CopyBuilders [#1250](https://github.com/ie3-institute/PowerSystemDataModel/issues/1250)

## [6.0.0] - 2025-02-27
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/edu/ie3/datamodel/io/factory/FactoryData.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
* @param unit unit of Quantity
* @param <Q> unit type parameter
* @return Quantity of given field with given unit
* @deprecated Use {@link #getQuantityOptional(String, Unit)} instead.
*/
@Deprecated

Check warning on line 78 in src/main/java/edu/ie3/datamodel/io/factory/FactoryData.java

View check run for this annotation

SonarQubeGithubPRChecks / PowerSystemDataModel Sonarqube Results

src/main/java/edu/ie3/datamodel/io/factory/FactoryData.java#L78

Add 'since' and/or 'forRemoval' arguments to the @deprecated annotation.
public <Q extends Quantity<Q>> ComparableQuantity<Q> getQuantity(String field, Unit<Q> unit) {
return Quantities.getQuantity(getDouble(field), unit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data
Point coordinate = data.getCoordinate();
ZonedDateTime time = timeUtil.toZonedDateTime(data.getField(TIME));
ComparableQuantity<Irradiance> directIrradiance =
data.getQuantity(DIRECT_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE);
data.getQuantityOptional(DIRECT_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE)
.orElse(null);
ComparableQuantity<Irradiance> diffuseIrradiance =
data.getQuantity(DIFFUSE_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE);
data.getQuantityOptional(DIFFUSE_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE)
.orElse(null);
ComparableQuantity<Temperature> temperature =
data.getQuantity(TEMPERATURE, StandardUnits.TEMPERATURE);
data.getQuantityOptional(TEMPERATURE, StandardUnits.TEMPERATURE).orElse(null);
ComparableQuantity<Angle> windDirection =
data.getQuantity(WIND_DIRECTION, StandardUnits.WIND_DIRECTION);
data.getQuantityOptional(WIND_DIRECTION, StandardUnits.WIND_DIRECTION).orElse(null);
ComparableQuantity<Speed> windVelocity =
data.getQuantity(WIND_VELOCITY, StandardUnits.WIND_VELOCITY);
data.getQuantityOptional(WIND_VELOCITY, StandardUnits.WIND_VELOCITY).orElse(null);

WeatherValue weatherValue =
new WeatherValue(
coordinate,
Expand All @@ -80,6 +83,7 @@ protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data
temperature,
windDirection,
windVelocity);

return new TimeBasedValue<>(time, weatherValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

import edu.ie3.datamodel.models.value.WeatherValue;
import java.util.Map;
import javax.measure.Quantity;
import javax.measure.Unit;
import org.locationtech.jts.geom.Point;
import tech.units.indriya.ComparableQuantity;

public class TimeBasedWeatherValueData extends TimeBasedValueData<WeatherValue> {

Expand All @@ -31,11 +28,6 @@ public Point getCoordinate() {
return coordinate;
}

@Override
public <Q extends Quantity<Q>> ComparableQuantity<Q> getQuantity(String field, Unit<Q> unit) {
return getField(field).isEmpty() ? null : super.getQuantity(field, unit);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ class CosmoTimeBasedWeatherValueFactoryTest extends Specification {
def data = new TimeBasedWeatherValueData(parameter, coordinate)

def expectedResults = new TimeBasedValue(
time, new WeatherValue(coordinate,
Quantities.getQuantity(286.872985839844d, StandardUnits.SOLAR_IRRADIANCE),
Quantities.getQuantity(282.671997070312d, StandardUnits.SOLAR_IRRADIANCE),
null,
Quantities.getQuantity(0d, StandardUnits.WIND_DIRECTION),
Quantities.getQuantity(1.66103506088257d, StandardUnits.WIND_VELOCITY)))
time, new WeatherValue( coordinate,
data.getQuantityOptional("directIrradiance", StandardUnits.SOLAR_IRRADIANCE).orElse(null),
data.getQuantityOptional("diffuseIrradiance", StandardUnits.SOLAR_IRRADIANCE).orElse(null),
data.getQuantityOptional("temperature", StandardUnits.TEMPERATURE).orElse(null),
data.getQuantityOptional("windDirection", StandardUnits.WIND_DIRECTION).orElse(null),
data.getQuantityOptional("windVelocity", StandardUnits.WIND_VELOCITY).orElse(null)))

when:
def model = factory.buildModel(data)
Expand Down Expand Up @@ -67,12 +67,16 @@ class CosmoTimeBasedWeatherValueFactoryTest extends Specification {
def data = new TimeBasedWeatherValueData(parameter, coordinate)

def expectedResults = new TimeBasedValue(
time, new WeatherValue(coordinate,
Quantities.getQuantity(286.872985839844d, StandardUnits.SOLAR_IRRADIANCE),
Quantities.getQuantity(282.671997070312d, StandardUnits.SOLAR_IRRADIANCE),
Quantities.getQuantity(278.019012451172d, StandardUnits.TEMPERATURE),
Quantities.getQuantity(0d, StandardUnits.WIND_DIRECTION),
Quantities.getQuantity(1.66103506088257d, StandardUnits.WIND_VELOCITY)))
time, new WeatherValue(
coordinate,
data.getQuantityOptional("directIrradiance", StandardUnits.SOLAR_IRRADIANCE).orElse(null),
data.getQuantityOptional("diffuseIrradiance", StandardUnits.SOLAR_IRRADIANCE).orElse(null),
data.getQuantityOptional("temperature", StandardUnits.TEMPERATURE).orElse(null),
data.getQuantityOptional("windDirection", StandardUnits.WIND_DIRECTION).orElse(null),
data.getQuantityOptional("windVelocity", StandardUnits.WIND_VELOCITY).orElse(null)
)
)


when:
def model = factory.buildModel(data)
Expand Down