Skip to content

Commit f88d124

Browse files
committed
Implementing reviewer's requests.
1 parent ba5f2b3 commit f88d124

File tree

5 files changed

+35
-39
lines changed

5 files changed

+35
-39
lines changed

docs/readthedocs/io/csvfiles.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,33 +122,34 @@ This is the UUID from the example above `2fcb3e53-b94a-4b96-bea4-c469e499f1a1`.
122122
The following keys are supported until now:
123123
```{list-table}
124124
:widths: auto
125+
:class: wrapping
125126
:header-rows: 1
126127
127128
* - Key
128-
- Information and supported head line
129+
- Information and supported head line.
129130
* - c
130131
- An energy price (e.g. in €/MWh; c stands for charge).
131132
Permissible head line: ``time,price``
132133
* - p
133-
- Active power
134+
- Active power.
134135
Permissible head line: ``time,p``
135136
* - pq
136-
- Active and reactive power
137+
- Active and reactive power.
137138
Permissible head line: ``time,p,q``
138139
* - h
139-
- Heat power demand
140+
- Heat power demand.
140141
Permissible head line: ``time,h``
141142
* - ph
142-
- Active and heat power
143+
- Active and heat power.
143144
Permissible head line: ``time,p,h``
144145
* - pqh
145-
- Active, reactive and heat power
146+
- Active, reactive and heat power.
146147
Permissible head line: ``time,p,q,h``
147148
* - v
148-
- Voltage mangnitude in pu and angle in °
149+
- Voltage mangnitude in pu and angle in °.
149150
Permissible head line: ``time,vMag,vAng``
150151
* - weather
151-
- Weather information
152+
- Weather information.
152153
Permissible head line: ``time,coordinate,direct_irradiation,diffuse_irradiation,temperature,wind_velocity,wind_direction``
153154
154155
```

docs/readthedocs/models/input/additionaldata/timeseries.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ The following different values are available:
3232
- Electrical active and reactive power
3333
3434
* - `HeatAndPValue`
35-
- | Combination of thermal power (e.g. in kW)
36-
| and electrical active power (e.g. in kW)
35+
- Combination of thermal power (e.g. in kW) <br> and electrical active power (e.g. in kW)
3736
3837
* - `HeatAndSValue`
39-
- | Combination of thermal power (e.g. in kW)
40-
| and electrical active and reactive power (e.g. in kW and kVAr)
38+
- Combination of thermal power (e.g. in kW) <br> and electrical active and reactive power (e.g. in kW and kVAr)
4139
4240
* - `EnergyPriceValue`
4341
- Wholesale market price (e.g. in € / MWh)
@@ -52,7 +50,7 @@ The following different values are available:
5250
- Combination of wind direction and wind velocity
5351
5452
* - `VoltageValue`
55-
- Combination of voltage magnitude in pu and angle in °
53+
- Combination of voltage magnitude in p.u. and angle in °
5654
5755
* - `WeatherValue`
5856
- Combination of irradiance, temperature and wind information

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
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.datamodel.utils.Try;
1415
import java.time.ZonedDateTime;
1516
import java.time.format.DateTimeFormatter;
16-
import java.util.Arrays;
17-
import java.util.Collections;
18-
import java.util.List;
19-
import java.util.Set;
17+
import java.util.*;
18+
import javax.measure.quantity.Angle;
19+
import tech.units.indriya.ComparableQuantity;
2020

2121
public class TimeBasedSimpleValueFactory<V extends Value>
2222
extends TimeBasedValueFactory<SimpleTimeBasedValueData<V>, V> {
@@ -72,16 +72,10 @@ protected TimeBasedValue<V> buildModel(SimpleTimeBasedValueData<V> data) {
7272
} else if (PValue.class.isAssignableFrom(data.getTargetClass())) {
7373
value = (V) new PValue(data.getQuantity(ACTIVE_POWER, ACTIVE_POWER_IN));
7474
} else if (VoltageValue.class.isAssignableFrom(data.getTargetClass())) {
75+
Optional<ComparableQuantity<Angle>> angleOption =
76+
Try.of(() -> data.getQuantity(VANG, VOLTAGE_ANGLE), FactoryException.class).getData();
7577

76-
try {
77-
value =
78-
(V)
79-
new VoltageValue(
80-
data.getQuantity(VMAG, VOLTAGE_MAGNITUDE),
81-
data.getQuantity(VANG, VOLTAGE_ANGLE));
82-
} catch (FactoryException e) {
83-
value = (V) new VoltageValue(data.getQuantity(VMAG, VOLTAGE_MAGNITUDE));
84-
}
78+
value = (V) new VoltageValue(data.getQuantity(VMAG, VOLTAGE_MAGNITUDE), angleOption);
8579
} else {
8680
throw new FactoryException(
8781
"The given factory cannot handle target class '" + data.getTargetClass() + "'.");
@@ -106,6 +100,8 @@ protected List<Set<String>> getFields(Class<?> entityClass) {
106100
minConstructorParams.addAll(Arrays.asList(ACTIVE_POWER, REACTIVE_POWER));
107101
} else if (PValue.class.isAssignableFrom(entityClass)) {
108102
minConstructorParams.add(ACTIVE_POWER);
103+
} else if (VoltageValue.class.isAssignableFrom(entityClass)) {
104+
minConstructorParams.addAll(List.of(VMAG, VANG));
109105
} else {
110106
throw new FactoryException(
111107
"The given factory cannot handle target class '" + entityClass + "'.");

src/main/java/edu/ie3/datamodel/models/value/VoltageValue.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,23 @@ public class VoltageValue implements Value {
2727

2828
/**
2929
* @param magnitude of the voltage in p.u.
30-
* @param angle of the voltage in degree
30+
* @param angleOption option for the angle of this voltage in degree
3131
*/
3232
public VoltageValue(
33-
ComparableQuantity<Dimensionless> magnitude, ComparableQuantity<Angle> angle) {
33+
ComparableQuantity<Dimensionless> magnitude,
34+
Optional<ComparableQuantity<Angle>> angleOption) {
3435
this.magnitude = magnitude;
35-
this.angle = angle;
36+
this.angle = angleOption.orElse(Quantities.getQuantity(0.0, VOLTAGE_ANGLE));
3637
}
3738

3839
/**
39-
* This constructor will set the angle to 0°
40-
*
4140
* @param magnitude of the voltage in p.u.
41+
* @param angle of the voltage in degree
4242
*/
43-
public VoltageValue(ComparableQuantity<Dimensionless> magnitude) {
43+
public VoltageValue(
44+
ComparableQuantity<Dimensionless> magnitude, ComparableQuantity<Angle> angle) {
4445
this.magnitude = magnitude;
45-
this.angle = Quantities.getQuantity(0.0, VOLTAGE_ANGLE);
46+
this.angle = angle;
4647
}
4748

4849
public Optional<ComparableQuantity<Dimensionless>> getMagnitude() {
@@ -65,8 +66,8 @@ public Optional<ComparableQuantity<Dimensionless>> getImagPart() {
6566
double mag = magnitude.to(PU).getValue().doubleValue();
6667
double ang = angle.to(DEGREE_GEOM).getValue().doubleValue();
6768

68-
double eInPu = mag * sin(toRadians(ang));
69-
return Optional.of(Quantities.getQuantity(eInPu, PU));
69+
double fInPu = mag * sin(toRadians(ang));
70+
return Optional.of(Quantities.getQuantity(fInPu, PU));
7071
}
7172

7273
@Override

src/test/groovy/edu/ie3/datamodel/models/value/VoltageValueTest.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ package edu.ie3.datamodel.models.value
77

88
import static edu.ie3.util.quantities.PowerSystemUnits.*
99

10+
import edu.ie3.util.quantities.QuantityUtil
1011
import spock.lang.Specification
1112
import tech.units.indriya.quantity.Quantities
1213

13-
1414
class VoltageValueTest extends Specification {
1515

1616
def "A VoltageValue should return the real part correctly"() {
@@ -19,13 +19,13 @@ class VoltageValueTest extends Specification {
1919

2020
then:
2121
actual.isPresent()
22-
actual.get() =~ expected
22+
QuantityUtil.isEquivalentAbs(actual.get(), expected, 1e-3)
2323

2424
where:
2525
value | expected
2626
new VoltageValue(Quantities.getQuantity(1, PU), Quantities.getQuantity(0, DEGREE_GEOM)) | Quantities.getQuantity(1, PU)
2727
new VoltageValue(Quantities.getQuantity(1, PU), Quantities.getQuantity(45, DEGREE_GEOM)) | Quantities.getQuantity(0.7071067811865476, PU)
28-
new VoltageValue(Quantities.getQuantity(1, PU), Quantities.getQuantity(90, DEGREE_GEOM)) | Quantities.getQuantity(6.123233995736766E-17, PU) // ~0pu
28+
new VoltageValue(Quantities.getQuantity(1, PU), Quantities.getQuantity(90, DEGREE_GEOM)) | Quantities.getQuantity(0, PU)
2929
}
3030

3131

@@ -35,7 +35,7 @@ class VoltageValueTest extends Specification {
3535

3636
then:
3737
actual.isPresent()
38-
actual.get() =~ expected
38+
QuantityUtil.isEquivalentAbs(actual.get(), expected, 1e-3)
3939

4040
where:
4141
value | expected

0 commit comments

Comments
 (0)