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

Register missing units to addUnit #282

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added implicit classes for `loactiontec.jts` Geometries that represent geographical geometries with functionality before located in `GeoUtils` [#163] (https://github.com/ie3-institute/PowerSystemUtils/issues/163)
- `OsmEntity` and `OsmContainer` to provide a simple, lightweight representation of openstreetmap data
- Register missing units for serialization/deserialization. Added test for labeling unit symbols correctly within PowerSystemUnits [#280] (https://github.com/ie3-institute/PowerSystemUtils/issues/280)

### Changed
- Refactored `GeoUtils`, moved them to the scala package and tailored them toward the `loactiontec.jts` Geometries used in the `OsmContainer` [#163] (https://github.com/ie3-institute/PowerSystemUtils/issues/163)
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/edu/ie3/util/quantities/PowerSystemUnits.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,22 @@ public class PowerSystemUnits extends Units {
public static final Unit<Energy> WATTHOUR =
new TransformedUnit<>("Wh", JOULE, MultiplyConverter.of(3600));

/** Varhour */
public static final Unit<Energy> VARHOUR =
new TransformedUnit<>("varh", JOULE, MultiplyConverter.of(3600));

/** Kilowatthour */
public static final Unit<Energy> KILOWATTHOUR = MetricPrefix.KILO(WATTHOUR);

/** Kilovarhour */
public static final Unit<Energy> KILOVARHOUR = MetricPrefix.KILO(VARHOUR);

/** Megawatthour */
public static final Unit<Energy> MEGAWATTHOUR = MetricPrefix.MEGA(WATTHOUR);

/** Megavarhour */
public static final Unit<Energy> MEGAVARHOUR = MetricPrefix.MEGA(VARHOUR);

/** Watthour per metre */
public static final Unit<SpecificEnergy> WATTHOUR_PER_METRE =
new ProductUnit<>(WATTHOUR.divide(METRE));
Expand Down Expand Up @@ -196,6 +204,7 @@ public class PowerSystemUnits extends Units {
addUnit(WATTHOUR_PER_METRE, "Wh/m");
addUnit(KILOWATTHOUR_PER_KILOMETRE, "kWh/km");
addUnit(KILOWATTHOUR, "kWh");
addUnit(MEGAWATTHOUR, "MWh");
addUnit(OHM_PER_KILOMETRE, "Ω/km");
addUnit(SIEMENS_PER_KILOMETRE, "S/km");
addUnit(VOLTAMPERE, "VA");
Expand All @@ -207,6 +216,9 @@ public class PowerSystemUnits extends Units {
addUnit(VAR, "var");
addUnit(KILOVAR, "kvar");
addUnit(MEGAVAR, "Mvar");
addUnit(VARHOUR, "varh");
addUnit(KILOVARHOUR, "kvarh");
addUnit(MEGAVARHOUR, "Mvarh");
addUnit(PU, "p.u.");
addUnit(EURO, "EUR");
addUnit(EURO_PER_KILOMETRE, "EUR/km");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,26 @@ class PowerSystemUnitsTest extends Specification {
Math.PI || 180.0
Math.PI * 3 / 2 || 270.0
}

def "Units are labeled with the correct label of the expected unit symbol"() {
danielfeismann marked this conversation as resolved.
Show resolved Hide resolved
when:
def getUnitLabel = PowerSystemUnits.addUnit(input).symbol

then:
getUnitLabel.equals(expectedLabel)

where:
input || expectedLabel
WATTHOUR || "Wh"
KILOWATTHOUR_PER_KILOMETRE || "kWh/km"
VOLTAMPERE || "VA"
PU_PER_HOUR || "p.u./h"
VAR || "var"
VARHOUR || "varh"
PU || "p.u."
EURO || "€"
MICROFARAD_PER_KILOMETRE || "µF/km"
FARAD_PER_KILOMETRE || "F/km"
DEGREE_GEOM || "°"
}
}