Skip to content

Commit 00c3b3a

Browse files
authored
Merge branch 'dev' into sb/#234-mergingZippingMethods
2 parents 691f0ff + 5c91ad3 commit 00c3b3a

28 files changed

+1379
-297
lines changed

src/main/java/edu/ie3/datamodel/io/connectors/SqlConnector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package edu.ie3.datamodel.io.connectors;
77

8+
import edu.ie3.util.StringUtils;
89
import edu.ie3.util.TimeUtil;
910
import java.sql.*;
1011
import java.util.*;
@@ -121,7 +122,7 @@ public Map<String, String> extractFieldMap(ResultSet rs) {
121122
ResultSetMetaData metaData = rs.getMetaData();
122123
int columnCount = metaData.getColumnCount();
123124
for (int i = 1; i <= columnCount; i++) {
124-
String columnName = metaData.getColumnName(i);
125+
String columnName = StringUtils.snakeCaseToCamelCase(metaData.getColumnName(i));
125126
String value;
126127
Object result = rs.getObject(i);
127128
if (result instanceof Timestamp) {
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
* © 2020. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
package edu.ie3.datamodel.io.factory.timeseries;
7+
8+
import edu.ie3.datamodel.models.StandardUnits;
9+
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
10+
import edu.ie3.datamodel.models.value.WeatherValue;
11+
import edu.ie3.util.TimeUtil;
12+
import edu.ie3.util.quantities.PowerSystemUnits;
13+
import edu.ie3.util.quantities.interfaces.Irradiation;
14+
import java.time.ZoneId;
15+
import java.time.ZonedDateTime;
16+
import java.util.*;
17+
import javax.measure.quantity.Angle;
18+
import javax.measure.quantity.Speed;
19+
import javax.measure.quantity.Temperature;
20+
import org.locationtech.jts.geom.Point;
21+
import tech.units.indriya.ComparableQuantity;
22+
import tech.units.indriya.quantity.Quantities;
23+
import tech.units.indriya.unit.Units;
24+
25+
/**
26+
* Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to
27+
* value mapping in the column scheme, ie<sup>3</sup> uses to store it's data from German Federal
28+
* Weather Service's ICON-EU model
29+
*/
30+
public class IconTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
31+
/* Redefine the column names to meet the icon specifications */
32+
private static final String COORDINATE = "coordinateId";
33+
private static final String TIME = "datum";
34+
private static final String DIFFUSE_IRRADIATION = "aswdifdS";
35+
private static final String DIRECT_IRRADIATION = "aswdirS";
36+
private static final String TEMPERATURE = "t2m";
37+
private static final String WIND_VELOCITY_U = "u131m";
38+
private static final String WIND_VELOCITY_V = "v131m";
39+
40+
public IconTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
41+
super(timeUtil);
42+
}
43+
44+
public IconTimeBasedWeatherValueFactory(String timePattern) {
45+
super(timePattern);
46+
}
47+
48+
public IconTimeBasedWeatherValueFactory() {
49+
super(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd HH:mm:ss"));
50+
}
51+
52+
@Override
53+
public String getCoordinateIdFieldString() {
54+
return COORDINATE;
55+
}
56+
57+
@Override
58+
public String getTimeFieldString() {
59+
return TIME;
60+
}
61+
62+
@Override
63+
protected List<Set<String>> getFields(TimeBasedWeatherValueData data) {
64+
Set<String> minConstructorParams =
65+
newSet(
66+
TIME,
67+
DIFFUSE_IRRADIATION,
68+
DIRECT_IRRADIATION,
69+
TEMPERATURE,
70+
WIND_VELOCITY_U,
71+
WIND_VELOCITY_V);
72+
Set<String> allParameters = new HashSet<>(minConstructorParams);
73+
allParameters.addAll(
74+
newSet(
75+
"albRad",
76+
"asobS",
77+
DIFFUSE_IRRADIATION,
78+
"aswdifuS",
79+
DIRECT_IRRADIATION,
80+
TEMPERATURE,
81+
"tG",
82+
"u10m",
83+
WIND_VELOCITY_U,
84+
"u20m",
85+
"u216m",
86+
"u65m",
87+
"v10m",
88+
WIND_VELOCITY_V,
89+
"v20m",
90+
"v216m",
91+
"v65m",
92+
"w131m",
93+
"w20m",
94+
"w216m",
95+
"w65m",
96+
"z0",
97+
"p131m",
98+
"p20m",
99+
"p65m",
100+
"sobsRad",
101+
"t131m"));
102+
Set<String> allParametersWithUuid = new HashSet<>(allParameters);
103+
allParametersWithUuid.add("uuid");
104+
105+
return Arrays.asList(minConstructorParams, allParameters, allParametersWithUuid);
106+
}
107+
108+
@Override
109+
protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data) {
110+
Point coordinate = data.getCoordinate();
111+
java.util.UUID uuid = data.containsKey(UUID) ? data.getUUID(UUID) : java.util.UUID.randomUUID();
112+
ZonedDateTime time = timeUtil.toZonedDateTime(data.getField(TIME));
113+
ComparableQuantity<Irradiation> directIrradiation =
114+
data.getQuantity(DIRECT_IRRADIATION, PowerSystemUnits.WATT_PER_SQUAREMETRE)
115+
.to(StandardUnits.IRRADIATION);
116+
ComparableQuantity<Irradiation> diffuseIrradiation =
117+
data.getQuantity(DIFFUSE_IRRADIATION, PowerSystemUnits.WATT_PER_SQUAREMETRE)
118+
.to(StandardUnits.IRRADIATION);
119+
ComparableQuantity<Temperature> temperature =
120+
data.getQuantity(TEMPERATURE, Units.KELVIN).to(StandardUnits.TEMPERATURE);
121+
ComparableQuantity<Angle> windDirection = getWindDirection(data);
122+
ComparableQuantity<Speed> windVelocity = getWindVelocity(data);
123+
WeatherValue weatherValue =
124+
new WeatherValue(
125+
coordinate,
126+
directIrradiation,
127+
diffuseIrradiation,
128+
temperature,
129+
windDirection,
130+
windVelocity);
131+
return new TimeBasedValue<>(uuid, time, weatherValue);
132+
}
133+
134+
/**
135+
* Determines the wind direction. In ICON the wind velocity is given in three dimensional
136+
* Cartesian coordinates. Here, the upward component is neglected. 0° or 0 rad are defined to
137+
* point northwards. The angle increases clockwise. Please note, that the wind direction is the
138+
* direction, the wind <b>comes</b> from and not goes to. We choose to use the wind velocity
139+
* calculations at 131 m above ground, as this is a height that pretty good matches the common hub
140+
* height of today's onshore wind generators, that are commonly connected to the voltage levels of
141+
* interest.
142+
*
143+
* @param data Collective information to convert
144+
* @return A {@link ComparableQuantity} of type {@link Speed}, that is converted to {@link
145+
* StandardUnits#WIND_VELOCITY}
146+
*/
147+
private static ComparableQuantity<Angle> getWindDirection(TimeBasedWeatherValueData data) {
148+
/* Get the three dimensional parts of the wind velocity vector in cartesian coordinates */
149+
double u =
150+
data.getDouble(WIND_VELOCITY_U); // Wind component from west to east (parallel to latitudes)
151+
double v =
152+
data.getDouble(
153+
WIND_VELOCITY_V); // Wind component from south to north (parallel to longitudes)
154+
155+
double angle = Math.toDegrees(Math.atan2(-u, -v));
156+
return Quantities.getQuantity(angle < 0 ? angle + 360d : angle, PowerSystemUnits.DEGREE_GEOM)
157+
.to(StandardUnits.WIND_DIRECTION);
158+
}
159+
160+
/**
161+
* Determines the wind velocity. In ICON the wind velocity is given in three dimensional Cartesian
162+
* coordinates. Here, the upward component is neglected. We choose to use the wind velocity
163+
* calculations at 131 m above ground, as this is a height that pretty good matches the common hub
164+
* height of today's onshore wind generators, that are commonly connected to the voltage levels of
165+
* interest.
166+
*
167+
* @param data Collective information to convert
168+
* @return A {@link ComparableQuantity} of type {@link Speed}, that is converted to {@link
169+
* StandardUnits#WIND_VELOCITY}
170+
*/
171+
private static ComparableQuantity<Speed> getWindVelocity(TimeBasedWeatherValueData data) {
172+
/* Get the three dimensional parts of the wind velocity vector in cartesian coordinates */
173+
double u = data.getDouble(WIND_VELOCITY_U);
174+
double v = data.getDouble(WIND_VELOCITY_V);
175+
176+
double velocity = Math.sqrt(Math.pow(u, 2) + Math.pow(v, 2));
177+
return Quantities.getQuantity(velocity, Units.METRE_PER_SECOND).to(StandardUnits.WIND_VELOCITY);
178+
}
179+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* © 2020. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
package edu.ie3.datamodel.io.factory.timeseries;
7+
8+
import static edu.ie3.datamodel.io.factory.timeseries.TimeBasedSimpleValueFactory.*;
9+
10+
import edu.ie3.datamodel.models.StandardUnits;
11+
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
12+
import edu.ie3.datamodel.models.value.WeatherValue;
13+
import edu.ie3.util.TimeUtil;
14+
import edu.ie3.util.quantities.interfaces.Irradiation;
15+
import java.time.ZonedDateTime;
16+
import java.util.Collections;
17+
import java.util.List;
18+
import java.util.Set;
19+
import javax.measure.quantity.Angle;
20+
import javax.measure.quantity.Speed;
21+
import javax.measure.quantity.Temperature;
22+
import org.locationtech.jts.geom.Point;
23+
import tech.units.indriya.ComparableQuantity;
24+
25+
/**
26+
* Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to
27+
* value mapping in the typical PowerSystemDataModel (PSDM) column scheme
28+
*/
29+
public class PsdmTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
30+
private static final String COORDINATE = "coordinate";
31+
32+
public PsdmTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
33+
super(timeUtil);
34+
}
35+
36+
public PsdmTimeBasedWeatherValueFactory(String timePattern) {
37+
super(timePattern);
38+
}
39+
40+
public PsdmTimeBasedWeatherValueFactory() {
41+
super();
42+
}
43+
44+
@Override
45+
public String getCoordinateIdFieldString() {
46+
return COORDINATE;
47+
}
48+
49+
@Override
50+
public String getTimeFieldString() {
51+
return TIME;
52+
}
53+
54+
@Override
55+
protected List<Set<String>> getFields(TimeBasedWeatherValueData data) {
56+
Set<String> minConstructorParams =
57+
newSet(
58+
UUID,
59+
TIME,
60+
DIFFUSE_IRRADIATION,
61+
DIRECT_IRRADIATION,
62+
TEMPERATURE,
63+
WIND_DIRECTION,
64+
WIND_VELOCITY);
65+
return Collections.singletonList(minConstructorParams);
66+
}
67+
68+
@Override
69+
protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data) {
70+
Point coordinate = data.getCoordinate();
71+
java.util.UUID uuid = data.getUUID(UUID);
72+
ZonedDateTime time = timeUtil.toZonedDateTime(data.getField(TIME));
73+
ComparableQuantity<Irradiation> directIrradiation =
74+
data.getQuantity(DIRECT_IRRADIATION, StandardUnits.IRRADIATION);
75+
ComparableQuantity<Irradiation> diffuseIrradiation =
76+
data.getQuantity(DIFFUSE_IRRADIATION, StandardUnits.IRRADIATION);
77+
ComparableQuantity<Temperature> temperature =
78+
data.getQuantity(TEMPERATURE, StandardUnits.TEMPERATURE);
79+
ComparableQuantity<Angle> windDirection =
80+
data.getQuantity(WIND_DIRECTION, StandardUnits.WIND_DIRECTION);
81+
ComparableQuantity<Speed> windVelocity =
82+
data.getQuantity(WIND_VELOCITY, StandardUnits.WIND_VELOCITY);
83+
WeatherValue weatherValue =
84+
new WeatherValue(
85+
coordinate,
86+
directIrradiation,
87+
diffuseIrradiation,
88+
temperature,
89+
windDirection,
90+
windVelocity);
91+
return new TimeBasedValue<>(uuid, time, weatherValue);
92+
}
93+
}

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

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@
77

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

10-
import edu.ie3.datamodel.models.StandardUnits;
11-
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
1210
import edu.ie3.datamodel.models.value.WeatherValue;
1311
import edu.ie3.util.TimeUtil;
14-
import edu.ie3.util.quantities.interfaces.Irradiation;
1512
import java.time.ZoneId;
16-
import java.time.ZonedDateTime;
1713
import java.util.*;
18-
import javax.measure.quantity.Angle;
19-
import javax.measure.quantity.Speed;
20-
import javax.measure.quantity.Temperature;
21-
import org.locationtech.jts.geom.Point;
22-
import tech.units.indriya.ComparableQuantity;
2314

24-
public class TimeBasedWeatherValueFactory
15+
/**
16+
* Abstract factory to handle the conversion from "flat" field to value mapping onto actual {@link
17+
* TimeBasedValueFactory} with {@link WeatherValue}
18+
*/
19+
public abstract class TimeBasedWeatherValueFactory
2520
extends TimeBasedValueFactory<TimeBasedWeatherValueData, WeatherValue> {
21+
protected static final String UUID = "uuid";
22+
protected static final String TIME = "time";
2623

27-
private static final String UUID = "uuid";
28-
private static final String TIME = "time";
29-
30-
private final TimeUtil timeUtil;
24+
protected final TimeUtil timeUtil;
3125

3226
public TimeBasedWeatherValueFactory() {
3327
this("yyyy-MM-dd'T'HH:mm:ss[.S[S][S]]'Z'");
@@ -42,43 +36,17 @@ public TimeBasedWeatherValueFactory(TimeUtil timeUtil) {
4236
this.timeUtil = timeUtil;
4337
}
4438

45-
@Override
46-
protected List<Set<String>> getFields(TimeBasedWeatherValueData data) {
47-
Set<String> minConstructorParams =
48-
newSet(
49-
UUID,
50-
TIME,
51-
DIFFUSE_IRRADIATION,
52-
DIRECT_IRRADIATION,
53-
TEMPERATURE,
54-
WIND_DIRECTION,
55-
WIND_VELOCITY);
56-
return Collections.singletonList(minConstructorParams);
57-
}
58-
59-
@Override
60-
protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data) {
61-
Point coordinate = data.getCoordinate();
62-
UUID uuid = data.getUUID(UUID);
63-
ZonedDateTime time = timeUtil.toZonedDateTime(data.getField(TIME));
64-
ComparableQuantity<Irradiation> directIrradiation =
65-
data.getQuantity(DIRECT_IRRADIATION, StandardUnits.IRRADIATION);
66-
ComparableQuantity<Irradiation> diffuseIrradiation =
67-
data.getQuantity(DIFFUSE_IRRADIATION, StandardUnits.IRRADIATION);
68-
ComparableQuantity<Temperature> temperature =
69-
data.getQuantity(TEMPERATURE, StandardUnits.TEMPERATURE);
70-
ComparableQuantity<Angle> windDirection =
71-
data.getQuantity(WIND_DIRECTION, StandardUnits.WIND_DIRECTION);
72-
ComparableQuantity<Speed> windVelocity =
73-
data.getQuantity(WIND_VELOCITY, StandardUnits.WIND_VELOCITY);
74-
WeatherValue weatherValue =
75-
new WeatherValue(
76-
coordinate,
77-
directIrradiation,
78-
diffuseIrradiation,
79-
temperature,
80-
windDirection,
81-
windVelocity);
82-
return new TimeBasedValue<>(uuid, time, weatherValue);
83-
}
39+
/**
40+
* Return the field name for the coordinate id
41+
*
42+
* @return the field name for the coordinate id
43+
*/
44+
public abstract String getCoordinateIdFieldString();
45+
46+
/**
47+
* Return the field name for the date time
48+
*
49+
* @return the field name for the date time
50+
*/
51+
public abstract String getTimeFieldString();
8452
}

0 commit comments

Comments
 (0)