Skip to content

Commit

Permalink
Unit for feeder info (#555)
Browse files Browse the repository at this point in the history
* Allow unit parametrization in SvgParameters

* DefaultLabelProvider modification

* Add new test for unit customization

* Update other test references

* Fix code smells

* Add missing parameter in constructor

---------

Signed-off-by: Sophie Frasnedo <sophie.frasnedo@rte-france.com>
  • Loading branch information
So-Fras authored Sep 29, 2023
1 parent 07edea0 commit 909a8d0
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ private List<FeederInfo> buildFeederInfos(HvdcLine hvdcLine, NodeSide side) {

private List<FeederInfo> buildFeederInfos(Terminal terminal) {
List<FeederInfo> feederInfoList = new ArrayList<>();
feederInfoList.add(new DirectionalFeederInfo(ARROW_ACTIVE, terminal.getP(), valueFormatter::formatPower));
feederInfoList.add(new DirectionalFeederInfo(ARROW_REACTIVE, terminal.getQ(), valueFormatter::formatPower));
feederInfoList.add(new DirectionalFeederInfo(ARROW_ACTIVE, terminal.getP(), svgParameters.getActivePowerUnit(), valueFormatter::formatPower));
feederInfoList.add(new DirectionalFeederInfo(ARROW_REACTIVE, terminal.getQ(), svgParameters.getReactivePowerUnit(), valueFormatter::formatPower));
if (this.svgParameters.isDisplayCurrentFeederInfo()) {
feederInfoList.add(new DirectionalFeederInfo(ARROW_CURRENT, terminal.getI(), valueFormatter::formatCurrent));
feederInfoList.add(new DirectionalFeederInfo(ARROW_CURRENT, terminal.getI(), svgParameters.getCurrentUnit(), valueFormatter::formatPower));
}
return feederInfoList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.sld.svg;

import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.DoubleFunction;

/**
Expand Down Expand Up @@ -42,6 +43,16 @@ public DirectionalFeederInfo(String componentType, double value, DoubleFunction<
this.value = value;
}

public DirectionalFeederInfo(String componentType, double value, String unit, BiFunction<Double, String, String> formatter, String userDefinedId) {
super(componentType, null, formatter.apply(value, unit), userDefinedId);
this.arrowDirection = Objects.requireNonNull(getArrowDirection(value));
this.value = value;
}

public DirectionalFeederInfo(String componentType, double value, String unit, BiFunction<Double, String, String> formatter) {
this(componentType, value, unit, formatter, null);
}

private static LabelProvider.LabelDirection getArrowDirection(double value) {
return value > 0 ? LabelProvider.LabelDirection.OUT : LabelProvider.LabelDirection.IN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class SvgParameters {
private int powerValuePrecision = 0;
private int angleValuePrecision = 1;
private int currentValuePrecision = 0;
private String activePowerUnit = "";
private String reactivePowerUnit = "";
private String currentUnit = "";
private double busInfoMargin = 0.0; //Can be used as horizontal shifting value for busInfo indicator. Can be negative value
private double feederInfosIntraMargin = 10;
private double feederInfosOuterMargin = 20;
Expand Down Expand Up @@ -60,6 +63,9 @@ public SvgParameters(SvgParameters other) {
this.powerValuePrecision = other.powerValuePrecision;
this.angleValuePrecision = other.angleValuePrecision;
this.currentValuePrecision = other.currentValuePrecision;
this.activePowerUnit = other.activePowerUnit;
this.reactivePowerUnit = other.reactivePowerUnit;
this.currentUnit = other.currentUnit;
this.busInfoMargin = other.busInfoMargin;
this.feederInfosIntraMargin = other.feederInfosIntraMargin;
this.feederInfosOuterMargin = other.feederInfosOuterMargin;
Expand Down Expand Up @@ -154,6 +160,33 @@ public SvgParameters setCurrentValuePrecision(int currentValuePrecision) {
return this;
}

public String getActivePowerUnit() {
return activePowerUnit;
}

public SvgParameters setActivePowerUnit(String activePowerUnit) {
this.activePowerUnit = activePowerUnit;
return this;
}

public String getReactivePowerUnit() {
return reactivePowerUnit;
}

public SvgParameters setReactivePowerUnit(String reactivePowerUnit) {
this.reactivePowerUnit = reactivePowerUnit;
return this;
}

public String getCurrentUnit() {
return currentUnit;
}

public SvgParameters setCurrentUnit(String currentUnit) {
this.currentUnit = currentUnit;
return this;
}

public double getBusInfoMargin() {
return busInfoMargin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import com.powsybl.sld.builders.NetworkGraphBuilder;
import com.powsybl.sld.layout.SmartVoltageLevelLayoutFactory;
import com.powsybl.sld.model.coordinate.Direction;
import com.powsybl.sld.model.graphs.VoltageLevelGraph;
import com.powsybl.sld.model.nodes.FeederNode;
Expand All @@ -20,10 +21,7 @@
import com.powsybl.sld.svg.DirectionalFeederInfo;
import com.powsybl.sld.svg.FeederInfo;
import com.powsybl.sld.svg.LabelProvider;
import com.powsybl.sld.svg.styles.AnimatedFeederInfoStyleProvider;
import com.powsybl.sld.svg.styles.BasicStyleProvider;
import com.powsybl.sld.svg.styles.StyleProvider;
import com.powsybl.sld.svg.styles.StyleProvidersList;
import com.powsybl.sld.svg.styles.*;
import com.powsybl.sld.svg.styles.iidm.TopologicalStyleProvider;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -233,4 +231,16 @@ public Optional<String> getRightLabel() {
// write SVG and compare to reference
assertEquals(toString("/TestAnimatedFeederInfos.svg"), toSVG(g, "/TestAnimatedFeederInfos.svg", componentLibrary, layoutParameters, svgParameters, labelProvider, styleProvider));
}

@Test
void testBuildFeederInfosWithUnits() {
Network network = IeeeCdfNetworkFactory.create9();
svgParameters.setDisplayCurrentFeederInfo(true)
.setActivePowerUnit("MW")
.setReactivePowerUnit("MVAR")
.setCurrentUnit("A");
VoltageLevelGraph g = new NetworkGraphBuilder(network).buildVoltageLevelGraph("VL5");
new SmartVoltageLevelLayoutFactory(network).create(g).run(layoutParameters);
assertEquals(toString("/TestUnitsOnFeederInfos.svg"), toSVG(g, "/TestUnitsOnFeederInfos.svg", componentLibrary, layoutParameters, svgParameters, new DefaultLabelProvider(network, componentLibrary, layoutParameters, svgParameters), new NominalVoltageStyleProvider()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ void test() {
.setPowerValuePrecision(3)
.setAngleValuePrecision(2)
.setCurrentValuePrecision(1)
.setActivePowerUnit("MW")
.setReactivePowerUnit("MVAR")
.setCurrentUnit("A")
.setBusInfoMargin(22)
.setFeederInfosIntraMargin(21)
.setFeederInfosOuterMargin(25)
Expand Down Expand Up @@ -54,6 +57,9 @@ void test() {
assertEquals(svgParameters0.getPowerValuePrecision(), svgParameters1.getPowerValuePrecision());
assertEquals(svgParameters0.getAngleValuePrecision(), svgParameters1.getAngleValuePrecision());
assertEquals(svgParameters0.getCurrentValuePrecision(), svgParameters1.getCurrentValuePrecision());
assertEquals(svgParameters0.getActivePowerUnit(), svgParameters1.getActivePowerUnit());
assertEquals(svgParameters0.getReactivePowerUnit(), svgParameters1.getReactivePowerUnit());
assertEquals(svgParameters0.getCurrentUnit(), svgParameters1.getCurrentUnit());
assertEquals(svgParameters0.getBusInfoMargin(), svgParameters1.getBusInfoMargin(), 0);
assertEquals(svgParameters0.getFeederInfosIntraMargin(), svgParameters1.getFeederInfosIntraMargin(), 0);
assertEquals(svgParameters0.getFeederInfosOuterMargin(), svgParameters1.getFeederInfosOuterMargin(), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@
"powerValuePrecision" : 0,
"angleValuePrecision" : 1,
"currentValuePrecision" : 0,
"activePowerUnit" : "",
"reactivePowerUnit" : "",
"currentUnit" : "",
"busInfoMargin" : 0.0,
"feederInfosIntraMargin" : 10.0,
"feederInfosOuterMargin" : 20.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@
"powerValuePrecision" : 0,
"angleValuePrecision" : 1,
"currentValuePrecision" : 0,
"activePowerUnit" : "",
"reactivePowerUnit" : "",
"currentUnit" : "",
"busInfoMargin" : 0.0,
"feederInfosIntraMargin" : 10.0,
"feederInfosOuterMargin" : 20.0,
Expand Down
Loading

0 comments on commit 909a8d0

Please sign in to comment.