Skip to content

Improve handling of time stamp pattern in factories #331

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 28 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
ce467c0
Adapt column name from "datum" to "time" with ICON weather data
ckittl Apr 14, 2021
f238fc1
Adding integration test for Couchbase and ICON weather model
ckittl Apr 16, 2021
0b7031d
Force user to provide time stamp pattern to ensure harmonized parsing
ckittl Apr 16, 2021
8549a7c
Harmonize naming of tests
ckittl Apr 16, 2021
dbc85f3
Adding integration test for InfluxDB and ICON weather model + improvi…
ckittl Apr 16, 2021
4b2243d
Add text file to gitattributes.
ckittl Apr 16, 2021
b0aa625
Improve inheritance along TimeBasedValueFactory
ckittl Apr 16, 2021
1ee3483
Check validity of time stamp pattern used by factory
ckittl Apr 16, 2021
fa6baba
Using time stamp pattern from factory to build Couchbase queries
ckittl Apr 16, 2021
3671b18
Adapt CHANGELOG.md
ckittl Apr 16, 2021
de6e2f5
Adapt Javadoc
ckittl Apr 16, 2021
f25150e
Adapt Javadoc +1
ckittl Apr 16, 2021
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
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# 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
src/test/resources/testContainerFiles/influxDb/icon/weather.txt eol=lf
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Reworking the time series source (one source per time series, distinct mapping source, factory pattern)
- BREAKING: Moved methods `buildSafe{Coord,Point,LineString,LineStringBetweenCoords,LineStringBetweenPoints}`, `totalLengthOfLineString` from `GridAndGeoUtils` to `GeoUtils` in [_PowerSystemUtils_](https://github.com/ie3-institute/PowerSystemUtils)
- BREAKING: Moved `CoordinateDistance` to [_PowerSystemUtils_](https://github.com/ie3-institute/PowerSystemUtils)
- BREAKING: Weather source
- Adapted data scheme (COSMO: `"coordinate"` to `"coordinate id"`, `"irradiation"` to `"irradiance"`, ICON: `"datum"` to `"time"`)
- Harmonized the source of coordinate id column name across implementations of `WeatherSource`
- Get field name in different casing (to actually get the column name in database, file, ...)
- Force user to provide time stamp pattern to `CouchbaseWeatherSource` to ensure harmonized querying
- Use naming convention dependent field names from factories within `InfluxDBWeatherSource`
- Check, if time stamp pattern is [RFC 3339](https://tools.ietf.org/html/rfc3339) compliant, as this is the output of InfluxDB
- Use factory's time stamp pattern to build queries within `CouchbaseWeatherSource`

### Fixed
- InfluxDbConnector now keeps session instead of creating a new one each call
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ apply from: scriptsLocation + 'vcs.gradle'
apply from: scriptsLocation + 'semVer.gradle'

repositories {
jcenter() //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 All @@ -52,7 +52,7 @@ repositories {

dependencies {
// ie³ power system utils
compile 'com.github.ie3-institute:PowerSystemUtils:1.5.1'
compile 'com.github.ie3-institute:PowerSystemUtils:1.5.2'

implementation 'tech.units:indriya:2.1.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
package edu.ie3.datamodel.io.factory.timeseries;

import static edu.ie3.datamodel.io.factory.timeseries.TimeBasedSimpleValueFactory.*;

import edu.ie3.datamodel.models.StandardUnits;
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
import edu.ie3.datamodel.models.value.WeatherValue;
Expand All @@ -25,33 +23,34 @@

/**
* Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to
* value mapping in the typical PowerSystemDataModel (PSDM) column scheme
* value mapping in the typical column scheme used by German Federal Meteorological Service's COSMO
* model
*/
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) {
/**
* @param timeUtil The time util to use
* @deprecated Use {@link
* CosmoTimeBasedWeatherValueFactory#CosmoTimeBasedWeatherValueFactory(String)} instead
*/
@Deprecated
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 @@ -11,7 +11,6 @@
import edu.ie3.util.TimeUtil;
import edu.ie3.util.quantities.PowerSystemUnits;
import edu.ie3.util.quantities.interfaces.Irradiance;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import javax.measure.quantity.Angle;
Expand All @@ -29,14 +28,18 @@
*/
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";
private static final String TEMPERATURE = "t2m";
private static final String WIND_VELOCITY_U = "u131m";
private static final String WIND_VELOCITY_V = "v131m";

/**
* @param timeUtil The time util to use
* @deprecated Use {@link
* IconTimeBasedWeatherValueFactory#IconTimeBasedWeatherValueFactory(String)} instead
*/
@Deprecated
public IconTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
super(timeUtil);
}
Expand All @@ -46,12 +49,7 @@ public IconTimeBasedWeatherValueFactory(String timePattern) {
}

public IconTimeBasedWeatherValueFactory() {
super(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd HH:mm:ss"));
}

@Override
public String getCoordinateIdFieldString() {
return COORDINATE;
super("yyyy-MM-dd HH:mm:ss");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,24 @@
import edu.ie3.datamodel.models.StandardUnits;
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
import edu.ie3.datamodel.models.value.*;
import edu.ie3.util.TimeUtil;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;

public class TimeBasedSimpleValueFactory<V extends Value>
extends TimeBasedValueFactory<SimpleTimeBasedValueData<V>, V> {
private static final String UUID = "uuid";
private static final String TIME = "time";
/* Energy price */
private static final String PRICE = "price";
/* Energy / Power */
private static final String ACTIVE_POWER = "p";
private static final String REACTIVE_POWER = "q";
private static final String HEAT_DEMAND = "heatdemand";

private final TimeUtil timeUtil;

public TimeBasedSimpleValueFactory(Class<? extends V> valueClasses) {
this(valueClasses, "yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'");
super("yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'", valueClasses);
}

public TimeBasedSimpleValueFactory(Class<? extends V> valueClasses, String timePattern) {
super(valueClasses);
timeUtil = new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, timePattern);
super(timePattern, valueClasses);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import edu.ie3.datamodel.io.factory.Factory;
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
import edu.ie3.datamodel.models.value.Value;
import edu.ie3.util.TimeUtil;
import java.time.ZoneId;
import java.util.Locale;

/**
* Abstract class that is able to build {@link TimeBasedValue}s from "flat" information
Expand All @@ -17,7 +20,49 @@
*/
public abstract class TimeBasedValueFactory<D extends TimeBasedValueData<V>, V extends Value>
extends Factory<V, D, TimeBasedValue<V>> {
/* Static field names, that are harmonized across different time based values */
protected static final String UUID = "uuid";
protected static final String TIME = "time";

protected final TimeUtil timeUtil;

/**
* Build an instance of of a time based value factory. Time zone defaults to UTC, Locale to {@link
* Locale#GERMANY} and the time stamp pattern to RFC 3339 standard.
*
* @param valueClasses Classes, that are covered by this factory
* @see <a href="https://tools.ietf.org/html/rfc3339">RFC 3339 standard definition</a>
*/
public TimeBasedValueFactory(Class<? extends V>... valueClasses) {
this(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'", valueClasses);
}

/**
* Build an instance of of a time based value factory. Time zone defaults to UTC and Locale to
* {@link Locale#GERMANY}.
*
* @param timeStampPattern Pattern, that should be used to interpret a String to date time
* @param valueClasses Classes, that are covered by this factory
*/
public TimeBasedValueFactory(String timeStampPattern, Class<? extends V>... valueClasses) {
this(ZoneId.of("UTC"), Locale.GERMANY, timeStampPattern, valueClasses);
}

/**
* Build an instance of of a time based value factory.
*
* @param timeZone Time zone to use, when parsing to date time
* @param locale Locale to use, when parsing to date time
* @param timeStampPattern Pattern, that should be used to interpret a String to date time
* @param valueClasses Classes, that are covered by this factory
*/
public TimeBasedValueFactory(
ZoneId timeZone, Locale locale, String timeStampPattern, Class<? extends V>... valueClasses) {
super(valueClasses);
timeUtil = new TimeUtil(timeZone, locale, timeStampPattern);
}

public String getTimeStampPattern() {
return timeUtil.getDtfPattern();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import edu.ie3.datamodel.models.value.WeatherValue;
import edu.ie3.util.TimeUtil;
import java.time.ZoneId;
import edu.ie3.util.naming.Naming;
import edu.ie3.util.naming.NamingConvention;
import java.util.*;

/**
Expand All @@ -16,30 +17,45 @@
*/
public abstract class TimeBasedWeatherValueFactory
extends TimeBasedValueFactory<TimeBasedWeatherValueData, WeatherValue> {
protected static final String UUID = "uuid";
protected static final String TIME = "time";

protected final TimeUtil timeUtil;
/* Hold a case agnostic representation of the composite word "coordinate id", that allows for later case conversion */
protected static final Naming COORDINATE_ID_NAMING = Naming.from("coordinate", "id");

protected TimeBasedWeatherValueFactory() {
this("yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'");
super(WeatherValue.class);
}

protected TimeBasedWeatherValueFactory(String timePattern) {
this(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, timePattern));
super(timePattern, WeatherValue.class);
}

/**
* @param timeUtil The time util to use
* @deprecated Use {@link TimeBasedWeatherValueFactory#TimeBasedWeatherValueFactory(String)}
* instead
*/
@Deprecated
protected TimeBasedWeatherValueFactory(TimeUtil timeUtil) {
super(WeatherValue.class);
this.timeUtil = timeUtil;
super(timeUtil.getDtfPattern(), WeatherValue.class);
}

/**
* Return the field name for the coordinate id
* Return the field name for the coordinate id in flat case.
*
* @return the field name for the coordinate id
*/
public abstract String getCoordinateIdFieldString();
public String getCoordinateIdFieldString() {
return COORDINATE_ID_NAMING.flatCase();
}

/**
* Return the field name for the coordinate id in desired case.
*
* @param convention The desired naming convention / casing
* @return the field name for the coordinate id in appropriate case
*/
public String getCoordinateIdFieldString(NamingConvention convention) {
return COORDINATE_ID_NAMING.as(convention);
}

/**
* Return the field name for the date time
Expand Down
Loading