Skip to content

Commit 7a75771

Browse files
committed
Improve inheritance along TimeBasedValueFactory
1 parent 2aa1823 commit 7a75771

File tree

10 files changed

+80
-37
lines changed

10 files changed

+80
-37
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
/**
2525
* Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to
26-
* value mapping in the typical PowerSystemDataModel (PSDM) column scheme
26+
* value mapping in the typical column scheme used by German Federal Meteorological Service's COSMO
27+
* model
2728
*/
2829
public class CosmoTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
2930
private static final String DIFFUSE_IRRADIANCE = "diffuseirradiance";
@@ -32,6 +33,11 @@ public class CosmoTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFact
3233
private static final String WIND_DIRECTION = "winddirection";
3334
private static final String WIND_VELOCITY = "windvelocity";
3435

36+
/**
37+
* @deprecated Use {@link
38+
* CosmoTimeBasedWeatherValueFactory#CosmoTimeBasedWeatherValueFactory(String)} instead
39+
*/
40+
@Deprecated
3541
public CosmoTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
3642
super(timeUtil);
3743
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import edu.ie3.util.TimeUtil;
1212
import edu.ie3.util.quantities.PowerSystemUnits;
1313
import edu.ie3.util.quantities.interfaces.Irradiance;
14-
import java.time.ZoneId;
1514
import java.time.ZonedDateTime;
1615
import java.util.*;
1716
import javax.measure.quantity.Angle;
@@ -35,6 +34,11 @@ public class IconTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFacto
3534
private static final String WIND_VELOCITY_U = "u131m";
3635
private static final String WIND_VELOCITY_V = "v131m";
3736

37+
/**
38+
* @deprecated Use {@link
39+
* IconTimeBasedWeatherValueFactory#IconTimeBasedWeatherValueFactory(String)} instead
40+
*/
41+
@Deprecated
3842
public IconTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
3943
super(timeUtil);
4044
}
@@ -44,7 +48,7 @@ public IconTimeBasedWeatherValueFactory(String timePattern) {
4448
}
4549

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

5054
@Override

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,24 @@
1111
import edu.ie3.datamodel.models.StandardUnits;
1212
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
1313
import edu.ie3.datamodel.models.value.*;
14-
import edu.ie3.util.TimeUtil;
15-
import java.time.ZoneId;
1614
import java.time.ZonedDateTime;
1715
import java.util.*;
1816

1917
public class TimeBasedSimpleValueFactory<V extends Value>
2018
extends TimeBasedValueFactory<SimpleTimeBasedValueData<V>, V> {
21-
private static final String UUID = "uuid";
22-
private static final String TIME = "time";
2319
/* Energy price */
2420
private static final String PRICE = "price";
2521
/* Energy / Power */
2622
private static final String ACTIVE_POWER = "p";
2723
private static final String REACTIVE_POWER = "q";
2824
private static final String HEAT_DEMAND = "heatdemand";
2925

30-
private final TimeUtil timeUtil;
31-
3226
public TimeBasedSimpleValueFactory(Class<? extends V> valueClasses) {
33-
this(valueClasses, "yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'");
27+
super("yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'", valueClasses);
3428
}
3529

3630
public TimeBasedSimpleValueFactory(Class<? extends V> valueClasses, String timePattern) {
37-
super(valueClasses);
38-
timeUtil = new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, timePattern);
31+
super(timePattern, valueClasses);
3932
}
4033

4134
@Override

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import edu.ie3.datamodel.io.factory.Factory;
99
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
1010
import edu.ie3.datamodel.models.value.Value;
11+
import edu.ie3.util.TimeUtil;
12+
import java.time.ZoneId;
13+
import java.util.Locale;
1114

1215
/**
1316
* Abstract class that is able to build {@link TimeBasedValue}s from "flat" information
@@ -17,7 +20,45 @@
1720
*/
1821
public abstract class TimeBasedValueFactory<D extends TimeBasedValueData<V>, V extends Value>
1922
extends Factory<V, D, TimeBasedValue<V>> {
23+
/* Static field names, that are harmonized across different time based values */
24+
protected static final String UUID = "uuid";
25+
protected static final String TIME = "time";
26+
27+
protected final TimeUtil timeUtil;
28+
29+
/**
30+
* Build an instance of of a time based value factory. Time zone defaults to UTC, Locale to {@link
31+
* Locale#GERMANY} and the time stamp pattern to RFC 3339 standard.
32+
*
33+
* @param valueClasses Classes, that are covered by this factory
34+
* @see <a href="https://tools.ietf.org/html/rfc3339">RFC 3339 standard definition</a>
35+
*/
2036
public TimeBasedValueFactory(Class<? extends V>... valueClasses) {
37+
this(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'", valueClasses);
38+
}
39+
40+
/**
41+
* Build an instance of of a time based value factory. Time zone defaults to UTC and Locale to
42+
* {@link Locale#GERMANY}.
43+
*
44+
* @param timeStampPattern Pattern, that should be used to interpret a String to date time
45+
* @param valueClasses Classes, that are covered by this factory
46+
*/
47+
public TimeBasedValueFactory(String timeStampPattern, Class<? extends V>... valueClasses) {
48+
this(ZoneId.of("UTC"), Locale.GERMANY, timeStampPattern, valueClasses);
49+
}
50+
51+
/**
52+
* Build an instance of of a time based value factory.
53+
*
54+
* @param timeZone Time zone to use, when parsing to date time
55+
* @param locale Locale to use, when parsing to date time
56+
* @param timeStampPattern Pattern, that should be used to interpret a String to date time
57+
* @param valueClasses Classes, that are covered by this factory
58+
*/
59+
public TimeBasedValueFactory(
60+
ZoneId timeZone, Locale locale, String timeStampPattern, Class<? extends V>... valueClasses) {
2161
super(valueClasses);
62+
timeUtil = new TimeUtil(timeZone, locale, timeStampPattern);
2263
}
2364
}

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import edu.ie3.util.TimeUtil;
1010
import edu.ie3.util.naming.Naming;
1111
import edu.ie3.util.naming.NamingConvention;
12-
import java.time.ZoneId;
1312
import java.util.*;
1413

1514
/**
@@ -18,24 +17,24 @@
1817
*/
1918
public abstract class TimeBasedWeatherValueFactory
2019
extends TimeBasedValueFactory<TimeBasedWeatherValueData, WeatherValue> {
21-
protected static final String UUID = "uuid";
22-
protected static final String TIME = "time";
2320
/* Hold a case agnostic representation of the composite word "coordinate id", that allows for later case conversion */
2421
protected static final Naming COORDINATE_ID_NAMING = Naming.from("coordinate", "id");
2522

26-
protected final TimeUtil timeUtil;
27-
2823
protected TimeBasedWeatherValueFactory() {
29-
this("yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'");
24+
super(WeatherValue.class);
3025
}
3126

3227
protected TimeBasedWeatherValueFactory(String timePattern) {
33-
this(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, timePattern));
28+
super(timePattern, WeatherValue.class);
3429
}
3530

31+
/**
32+
* @deprecated Use {@link TimeBasedWeatherValueFactory#TimeBasedWeatherValueFactory(String)}
33+
* instead
34+
*/
35+
@Deprecated
3636
protected TimeBasedWeatherValueFactory(TimeUtil timeUtil) {
37-
super(WeatherValue.class);
38-
this.timeUtil = timeUtil;
37+
super(timeUtil.getDtfPattern(), WeatherValue.class);
3938
}
4039

4140
/**

src/test/groovy/edu/ie3/datamodel/io/factory/timeseries/IconTimeBasedWeatherValueFactoryTest.groovy

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ class IconTimeBasedWeatherValueFactoryTest extends Specification {
7676
def coordinate = CosmoWeatherTestData.COORDINATE_67775
7777

7878
def parameter = [
79-
"time" : "2019-08-01 01:00:00",
80-
"albRad" : "13.015240669",
81-
"asobS" : "3.555093673828124",
82-
"aswdifdS": "1.8088226191406245",
83-
"aswdifuS": "0.5713421484374998",
84-
"aswdirS" : "2.317613203124999",
85-
"t2m" : "289.1179319051744",
86-
"tg" : "288.4101691197649",
87-
"u10m" : "0.3021732864307963",
88-
"u131m" : "2.6058700426057797",
89-
"u20m" : "0.32384365019387784",
79+
"time" : "2019-08-01 01:00:00",
80+
"albRad" : "13.015240669",
81+
"asobS" : "3.555093673828124",
82+
"aswdifdS" : "1.8088226191406245",
83+
"aswdifuS" : "0.5713421484374998",
84+
"aswdirS" : "2.317613203124999",
85+
"t2m" : "289.1179319051744",
86+
"tg" : "288.4101691197649",
87+
"u10m" : "0.3021732864307963",
88+
"u131m" : "2.6058700426057797",
89+
"u20m" : "0.32384365019387784",
9090
"u216m" : "3.9015497418041756",
9191
"u65m" : "1.2823686334340363",
9292
"v10m" : "1.3852550649486943",
@@ -98,7 +98,7 @@ class IconTimeBasedWeatherValueFactoryTest extends Specification {
9898
"w20m" : "-0.0100060345167524",
9999
"w216m" : "-0.030348050471342078",
100100
"w65m" : "-0.01817112027569893",
101-
"z0" : "0.955323922526438",
101+
"z0" : "0.955323922526438",
102102
"coordinateId": "67775",
103103
"p131m" : "",
104104
"p20m" : "",

src/test/groovy/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSourceCosmoIT.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CouchbaseWeatherSourceCosmoIT extends Specification implements WeatherSour
6464

6565
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
6666
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
67-
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern))
67+
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(dtfPattern)
6868
source = new CouchbaseWeatherSource(connector, CosmoWeatherTestData.coordinateSource, weatherFactory, dtfPattern)
6969
}
7070

src/test/groovy/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSourceIconIT.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class CouchbaseWeatherSourceIconIT extends Specification implements WeatherSourc
6262

6363
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
6464
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
65-
def weatherFactory = new IconTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern))
65+
def weatherFactory = new IconTimeBasedWeatherValueFactory(dtfPattern)
6666
source = new CouchbaseWeatherSource(connector, IconWeatherTestData.coordinateSource, weatherFactory, dtfPattern)
6767
}
6868

src/test/groovy/edu/ie3/datamodel/io/source/sql/SqlWeatherSourceCosmoIT.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SqlWeatherSourceCosmoIT extends Specification implements WeatherSourceTest
4343
postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather.sql")
4444

4545
def connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
46-
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(TimeUtil.withDefaults)
46+
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(TimeUtil.withDefaults.getDtfPattern())
4747
source = new SqlWeatherSource(connector, CosmoWeatherTestData.coordinateSource, schemaName, weatherTableName, namingConvention, weatherFactory)
4848
}
4949

src/test/groovy/edu/ie3/datamodel/io/source/sql/SqlWeatherSourceIconIT.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SqlWeatherSourceIconIT extends Specification implements WeatherSourceTestH
4343
postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather.sql")
4444

4545
def connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
46-
def weatherFactory = new IconTimeBasedWeatherValueFactory(TimeUtil.withDefaults)
46+
def weatherFactory = new IconTimeBasedWeatherValueFactory(TimeUtil.withDefaults.getDtfPattern())
4747
source = new SqlWeatherSource(connector, IconWeatherTestData.coordinateSource, schemaName, weatherTableName, namingConvention, weatherFactory)
4848
}
4949

0 commit comments

Comments
 (0)