Skip to content
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

Adapt to changed scheme of COSMO weather data #558

Merged
merged 31 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
697f9da
Alter scheme for COSMO weather in test files
ckittl Apr 6, 2021
fa0fc4a
Renaming of "weather data scheme" and equivalent classes and methods
ckittl Apr 6, 2021
15d9550
Adapt to plain naming in Couchbase files
ckittl Apr 6, 2021
343b832
Fix some tests
ckittl Apr 6, 2021
454420d
Consolidate csv weather test files in one place
ckittl Apr 6, 2021
5365a79
Use PowerSystemUtils v 1.5.2
ckittl Apr 9, 2021
c9a8c16
Use maven central instead of jcenter
ckittl Apr 9, 2021
30699e2
Pull naming of coordinate id {field / key / column} naming into TimeB…
ckittl Apr 9, 2021
b272635
Fix InfluxDbWeatherSource
ckittl Apr 9, 2021
6940eaf
Simplifying the sql weather source by fixing the column name to a giv…
ckittl Apr 9, 2021
ccd9418
Harmonizing the couchbase weather source with other source implementa…
ckittl Apr 9, 2021
5609e04
Offer possibility to set naming strategy in sql and couchbase weather…
ckittl Apr 9, 2021
00859be
Document work
ckittl Apr 9, 2021
7995b54
Merge branch 'dev' into ck/#267-adaptColumnSchemeOfCOSMOWeatherData
ckittl Apr 14, 2021
2165981
Merge remote-tracking branch 'origin/dev' into ck/#267-adaptColumnSch…
ckittl Apr 21, 2021
2c1cc77
Reducing code smells
ckittl Apr 21, 2021
1cf83de
Merge remote-tracking branch 'origin/dev' into ck/#267-adaptColumnSch…
ckittl Jan 28, 2022
a8f1f98
Fix tests
ckittl Jan 28, 2022
8c6b2b6
Improved CHANGELOG
ckittl Jan 28, 2022
6b351f0
Improve documentation of the code
ckittl Jan 28, 2022
a6d8fdd
Move test data
ckittl Jan 28, 2022
da408e1
Fmt
ckittl Jan 28, 2022
4dfbe0c
reducing code smells
ckittl Jan 28, 2022
2075f1f
Merge branch 'dev' into ck/#267-adaptColumnSchemeOfCOSMOWeatherData
t-ober Feb 4, 2022
46019f2
Merge branch 'dev' into ck/#267-adaptColumnSchemeOfCOSMOWeatherData
sebastian-peter Feb 9, 2022
6c97ff1
Merge branch 'dev' into ck/#267-adaptColumnSchemeOfCOSMOWeatherData
sebastian-peter Mar 2, 2022
ae52c4d
Reverting introduction of NamingConvention
sebastian-peter Mar 3, 2022
7287f11
Merge branch 'dev' into sp/#267-cosmo-weather-scheme-adaptions
sebastian-peter Mar 3, 2022
9e65c8b
Fixing tests
sebastian-peter Mar 3, 2022
aafa1f2
Fixing code smell: uppercase naming of static final field
sebastian-peter Mar 3, 2022
fd18347
Addressing reviewer's comments
sebastian-peter Mar 3, 2022
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# The following file will be copied to a unix Docker image and imported to InfluxDB data base. Therefore, the line
# ending plays a crucial role. This prevents the endings from being adjusted with 'core.autocrlf=true'
src/test/resources/testContainerFiles/influxDb/weather.txt eol=lf
src/test/resources/testContainerFiles/influxDb/cosmo/weather.txt eol=lf
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `edu.ie3.datamodel.io.csv.timeseries.LoadProfileTimeSeriesMetaInformation`
- `edu.ie3.datamodel.io.connectors.CsvFileConnector.CsvIndividualTimeSeriesMetaInformation`
- and related methods
- BREAKING: Comprehensive harmonization around weather sources [#267](https://github.com/ie3-institute/PowerSystemDataModel/issues/267)
- Adapted the expected column scheme
- General weather model
- `coordinate` to `coordinateid`
- DWD COSMO model
- `diffuseirradiation` to `diffuseirradiance`
- `directirradiation` to `directirradiance`

## [2.1.0] - 2022-01-05

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ apply from: scriptsLocation + 'vcs.gradle'
apply from: scriptsLocation + 'semVer.gradle'

repositories {
mavenCentral() //searches in bintray's repository 'jCenter', which contains Maven Central
mavenCentral() // searches in Sonatype's repository 'Maven Central'
maven { url 'https://www.jitpack.io' } // allows github repos as dependencies

// sonatype snapshot repo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,25 @@
* Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to
* value mapping in the typical PowerSystemDataModel (PSDM) column scheme
*/
public class PsdmTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
private static final String COORDINATE = "coordinate";
private static final String DIFFUSE_IRRADIANCE = "diffuseirradiation";
private static final String DIRECT_IRRADIANCE = "directirradiation";
public class CosmoTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
private static final String DIFFUSE_IRRADIANCE = "diffuseirradiance";
private static final String DIRECT_IRRADIANCE = "directirradiance";
private static final String TEMPERATURE = "temperature";
private static final String WIND_DIRECTION = "winddirection";
private static final String WIND_VELOCITY = "windvelocity";

public PsdmTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
public CosmoTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
super(timeUtil);
}

public PsdmTimeBasedWeatherValueFactory(String timePattern) {
public CosmoTimeBasedWeatherValueFactory(String timePattern) {
super(timePattern);
}

public PsdmTimeBasedWeatherValueFactory() {
public CosmoTimeBasedWeatherValueFactory() {
super();
}

@Override
public String getCoordinateIdFieldString() {
return COORDINATE;
}

@Override
public String getTimeFieldString() {
return TIME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
public class IconTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
/* Redefine the column names to meet the icon specifications */
private static final String COORDINATE = "coordinateid";
private static final String TIME = "datum";
private static final String DIFFUSE_IRRADIANCE = "aswdifdS";
private static final String DIRECT_IRRADIANCE = "aswdirS";
Expand All @@ -49,11 +48,6 @@ public IconTimeBasedWeatherValueFactory() {
super(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd HH:mm:ss"));
}

@Override
public String getCoordinateIdFieldString() {
return COORDINATE;
}

@Override
public String getTimeFieldString() {
return TIME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public abstract class TimeBasedWeatherValueFactory
extends TimeBasedValueFactory<TimeBasedWeatherValueData, WeatherValue> {
protected static final String UUID = "uuid";
protected static final String TIME = "time";
protected static final String COORDINATE_ID = "coordinateid";

protected final TimeUtil timeUtil;

Expand All @@ -39,7 +40,9 @@ protected TimeBasedWeatherValueFactory(TimeUtil timeUtil) {
*
* @return the field name for the coordinate id
*/
public abstract String getCoordinateIdFieldString();
public String getCoordinateIdFieldString() {
return COORDINATE_ID;
}

/**
* Return the field name for the date time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public class InfluxDbWeatherSource implements WeatherSource {
private static final String WHERE = " where ";
private static final String MEASUREMENT_NAME_WEATHER = "weather";
private static final int MILLI_TO_NANO_FACTOR = 1000000;
private final String coordinateIdColumnName;

/* Final name of the coordinate id field for use in factories */
private final String coordinateIdFieldName;
sebastian-peter marked this conversation as resolved.
Show resolved Hide resolved
/* Final name of the column within the database */
private static final String coordinateIdColumnName = "coordinate_id";
sebastian-peter marked this conversation as resolved.
Show resolved Hide resolved
private final InfluxDbConnector connector;
private final IdCoordinateSource coordinateSource;
private final TimeBasedWeatherValueFactory weatherValueFactory;
Expand All @@ -50,7 +54,7 @@ public InfluxDbWeatherSource(
this.connector = connector;
this.coordinateSource = coordinateSource;
this.weatherValueFactory = weatherValueFactory;
this.coordinateIdColumnName = weatherValueFactory.getCoordinateIdFieldString();
this.coordinateIdFieldName = weatherValueFactory.getCoordinateIdFieldString();
sebastian-peter marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down Expand Up @@ -113,7 +117,7 @@ public Map<Point, IndividualTimeSeries<WeatherValue>> getWeather(
public IndividualTimeSeries<WeatherValue> getWeather(
ClosedInterval<ZonedDateTime> timeInterval, Point coordinate) {
Optional<Integer> coordinateId = coordinateSource.getId(coordinate);
if (!coordinateId.isPresent()) {
if (coordinateId.isEmpty()) {
return new IndividualTimeSeries<>(UUID.randomUUID(), Collections.emptySet());
}
try (InfluxDB session = connector.getSession()) {
Expand All @@ -130,7 +134,7 @@ public IndividualTimeSeries<WeatherValue> getWeather(
@Override
public Optional<TimeBasedValue<WeatherValue>> getWeather(ZonedDateTime date, Point coordinate) {
Optional<Integer> coordinateId = coordinateSource.getId(coordinate);
if (!coordinateId.isPresent()) {
if (coordinateId.isEmpty()) {
return Optional.empty();
}
try (InfluxDB session = connector.getSession()) {
Expand All @@ -152,24 +156,25 @@ private Stream<Optional<TimeBasedValue<WeatherValue>>> optTimeBasedValueStream(
return measurementsMap.get(MEASUREMENT_NAME_WEATHER).stream()
sebastian-peter marked this conversation as resolved.
Show resolved Hide resolved
.map(
fieldToValue -> {
Optional<Point> coordinate =
coordinateSource.getCoordinate(
Integer.parseInt(fieldToValue.remove(coordinateIdColumnName)));
if (!coordinate.isPresent()) return null;
fieldToValue.putIfAbsent("uuid", UUID.randomUUID().toString());

/* The factory expects camel case id's for fields -> Convert the keys */
Map<String, String> camelCaseFields =
/* The factory expects flat case id's for fields -> Convert the keys */
Map<String, String> flatCaseFields =
fieldToValue.entrySet().stream()
.collect(
Collectors.toMap(
entry -> StringUtils.snakeCaseToCamelCase(entry.getKey()),
entry ->
StringUtils.snakeCaseToCamelCase(entry.getKey()).toLowerCase(),
Map.Entry::getValue));
t-ober marked this conversation as resolved.
Show resolved Hide resolved

return new TimeBasedWeatherValueData(camelCaseFields, coordinate.get());
})
.filter(Objects::nonNull)
.map(weatherValueFactory::get);
/* Add a random UUID if necessary */
flatCaseFields.putIfAbsent("uuid", UUID.randomUUID().toString());

/* Get the corresponding coordinate id from map AND REMOVE THE ENTRY !!! */
int coordinateId = Integer.parseInt(flatCaseFields.remove(coordinateIdFieldName));
return coordinateSource
.getCoordinate(coordinateId)
.map(point -> new TimeBasedWeatherValueData(flatCaseFields, point))
.flatMap(weatherValueFactory::get);
});
}

private String createQueryStringForCoordinateAndTimeInterval(
Expand Down Expand Up @@ -205,7 +210,7 @@ private String createTimeConstraint(ZonedDateTime date) {
}

private String createCoordinateConstraintString(int coordinateId) {
return "coordinate='" + coordinateId + "'";
return coordinateIdColumnName + "='" + coordinateId + "'";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ public SqlWeatherSource(

String dbTimeColumnName =
getDbColumnName(weatherFactory.getTimeFieldString(), weatherTableName);
String dbCoordColumnName = getDbColumnName(factoryCoordinateFieldName, weatherTableName);
String dbCoordinateIdColumnName = getDbColumnName(factoryCoordinateFieldName, weatherTableName);

// setup queries
this.queryTimeInterval =
createQueryStringForTimeInterval(schemaName, weatherTableName, dbTimeColumnName);
this.queryTimeAndCoordinate =
createQueryStringForTimeAndCoordinate(
schemaName, weatherTableName, dbTimeColumnName, dbCoordColumnName);
schemaName, weatherTableName, dbTimeColumnName, dbCoordinateIdColumnName);
this.queryTimeIntervalAndCoordinates =
createQueryStringForTimeIntervalAndCoordinates(
schemaName, weatherTableName, dbTimeColumnName, dbCoordColumnName);
schemaName, weatherTableName, dbTimeColumnName, dbCoordinateIdColumnName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ package edu.ie3.datamodel.io.factory.timeseries
import edu.ie3.datamodel.models.StandardUnits
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
import edu.ie3.datamodel.models.value.WeatherValue
import edu.ie3.test.common.PsdmWeatherTestData
import edu.ie3.test.common.CosmoWeatherTestData
import edu.ie3.util.TimeUtil
import spock.lang.Specification
import tech.units.indriya.quantity.Quantities

class PsdmTimeBasedWeatherValueFactoryTest extends Specification {
class CosmoTimeBasedWeatherValueFactoryTest extends Specification {

def "A PsdmTimeBasedWeatherValueFactory should be able to create time series with missing values"() {
given:
def factory = new PsdmTimeBasedWeatherValueFactory("yyyy-MM-dd HH:mm:ss")
def coordinate = PsdmWeatherTestData.COORDINATE_193186
def factory = new CosmoTimeBasedWeatherValueFactory("yyyy-MM-dd HH:mm:ss")
def coordinate = CosmoWeatherTestData.COORDINATE_193186
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")

Map<String, String> parameter = [
"uuid" : "980f7714-8def-479f-baae-4deed6c8d6d1",
"time" : TimeUtil.withDefaults.toString(time),
"diffuseirradiation": "282.671997070312",
"directirradiation" : "286.872985839844",
"temperature" : "",
"winddirection" : "0",
"windvelocity" : "1.66103506088257"
"uuid" : "980f7714-8def-479f-baae-4deed6c8d6d1",
"time" : TimeUtil.withDefaults.toString(time),
"diffuseirradiance": "282.671997070312",
"directirradiance" : "286.872985839844",
"temperature" : "",
"winddirection" : "0",
"windvelocity" : "1.66103506088257"
]

def data = new TimeBasedWeatherValueData(parameter, coordinate)
Expand All @@ -50,18 +50,18 @@ class PsdmTimeBasedWeatherValueFactoryTest extends Specification {

def "A PsdmTimeBasedWeatherValueFactory should be able to create time series values"() {
given:
def factory = new PsdmTimeBasedWeatherValueFactory("yyyy-MM-dd HH:mm:ss")
def coordinate = PsdmWeatherTestData.COORDINATE_193186
def factory = new CosmoTimeBasedWeatherValueFactory("yyyy-MM-dd HH:mm:ss")
def coordinate = CosmoWeatherTestData.COORDINATE_193186
def time = TimeUtil.withDefaults.toZonedDateTime("2019-01-01 00:00:00")

Map<String, String> parameter = [
"time" : TimeUtil.withDefaults.toString(time),
"uuid" : "980f7714-8def-479f-baae-4deed6c8d6d1",
"diffuseirradiation": "282.671997070312",
"directirradiation" : "286.872985839844",
"temperature" : "278.019012451172",
"winddirection" : "0",
"windvelocity" : "1.66103506088257"
"time" : TimeUtil.withDefaults.toString(time),
"uuid" : "980f7714-8def-479f-baae-4deed6c8d6d1",
"diffuseirradiance": "282.671997070312",
"directirradiance" : "286.872985839844",
"temperature" : "278.019012451172",
"winddirection" : "0",
"windvelocity" : "1.66103506088257"
]

def data = new TimeBasedWeatherValueData(parameter, coordinate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package edu.ie3.datamodel.io.factory.timeseries

import edu.ie3.datamodel.models.StandardUnits
import edu.ie3.test.common.PsdmWeatherTestData
import edu.ie3.test.common.CosmoWeatherTestData
import edu.ie3.util.TimeUtil
import edu.ie3.util.quantities.PowerSystemUnits
import edu.ie3.util.quantities.QuantityUtil
Expand Down Expand Up @@ -73,7 +73,7 @@ class IconTimeBasedWeatherValueFactoryTest extends Specification {
def "A time based weather value factory for ICON column scheme builds a single time based value correctly"() {
given:
def factory = new IconTimeBasedWeatherValueFactory()
def coordinate = PsdmWeatherTestData.COORDINATE_67775
def coordinate = CosmoWeatherTestData.COORDINATE_67775

def parameter = [
"datum" : "2019-08-01 01:00:00",
Expand Down
Loading