Skip to content

Commit

Permalink
Id attribute optional in measurement/discrete measurement extensions (#…
Browse files Browse the repository at this point in the history
…452)

* Make measurement and discrete measurement extensions id attribute optional
* Fix clang-tidy cognitive-complexity

Signed-off-by: gaouizer <[email protected]>
  • Loading branch information
gaouizer authored Jul 25, 2024
1 parent 77dfcf7 commit 04d4cf5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ Checks: '-*,

WarningsAsErrors: '*'
HeaderFilterRegex: 'include/powsybl/.*|src/.*|extensions/.*|test/.*'

CheckOptions:
- { key: readability-function-cognitive-complexity.IgnoreMacros, value: true }
10 changes: 10 additions & 0 deletions extensions/iidm/resources/disMeasRef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@
</dm:discreteMeasurement>
</dm:discreteMeasurements>
</iidm:extension>
<iidm:extension id="S1VL1_BBS_TWT_DISCONNECTOR">
<dm:discreteMeasurements>
<dm:discreteMeasurement type="SWITCH_POSITION" valueType="STRING" value="CLOSED" valid="false">
<dm:property name="source" value="test"/>
</dm:discreteMeasurement>
<dm:discreteMeasurement type="OTHER" valueType="STRING" value="CLOSED" valid="false">
<dm:property name="source" value="test"/>
</dm:discreteMeasurement>
</dm:discreteMeasurements>
</iidm:extension>
<iidm:extension id="TWT">
<dm:discreteMeasurements>
<dm:discreteMeasurement id="DIS_MEAS_TAP_POS" type="TAP_POSITION" tapChanger="PHASE_TAP_CHANGER" valueType="INT" value="15" valid="true">
Expand Down
4 changes: 4 additions & 0 deletions extensions/iidm/resources/measRef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<m:measurement id="MEAS_TWT_Q_1" type="REACTIVE_POWER" side="ONE" value="605.20000000000005" standardDeviation="9.6999999999999993" valid="true">
<m:property name="source" value="test2"/>
</m:measurement>
<m:measurement type="ACTIVE_POWER" side="TWO" value="-300" standardDeviation="10.199999999999999" valid="true"/>
<m:measurement type="ACTIVE_POWER" side="ONE" value="301.19999999999999" standardDeviation="9.6999999999999993" valid="true">
<m:property name="source" value="test2"/>
</m:measurement>
</m:measurements>
</iidm:extension>
</iidm:network>
5 changes: 4 additions & 1 deletion extensions/iidm/src/DiscreteMeasurementsXmlSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ Extension& DiscreteMeasurementsXmlSerializer::read(Extendable& extendable, conve

void DiscreteMeasurementsXmlSerializer::readDiscreteMeasurement(DiscreteMeasurements& discreteMeasurements, const xml::XmlStreamReader& reader) {
DiscreteMeasurementAdder adder = discreteMeasurements.newDiscreteMeasurement()
.setId(reader.getAttributeValue(ID))
.setType(Enum::fromString<DiscreteMeasurement::Type>(reader.getAttributeValue(TYPE)))
.setValid(reader.getAttributeValue<bool>(VALID));
const std::string& dmId = reader.getOptionalAttributeValue(ID, "");
if (!dmId.empty()) {
adder.setId(dmId);
}
const std::string& tapChanger = reader.getOptionalAttributeValue(TAP_CHANGER, "");
if (!tapChanger.empty()) {
adder.setTapChanger(Enum::fromString<DiscreteMeasurement::TapChanger>(tapChanger));
Expand Down
5 changes: 4 additions & 1 deletion extensions/iidm/src/MeasurementsXmlSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ Extension& MeasurementsXmlSerializer::read(Extendable& extendable, converter::xm
context.getReader().readUntilEndElement("measurements", [&measurements, &context]() {
if (context.getReader().getLocalName() == "measurement") {
MeasurementAdder adder = measurements.newMeasurement()
.setId(context.getReader().getAttributeValue(converter::ID))
.setType(Enum::fromString<Measurement::Type>(context.getReader().getAttributeValue(converter::TYPE)))
.setValue(context.getReader().getOptionalAttributeValue(converter::VALUE, stdcxx::nan()))
.setStandardDeviation(context.getReader().getOptionalAttributeValue("standardDeviation", stdcxx::nan()))
.setValid(context.getReader().getAttributeValue<bool>("valid"));
const std::string& mId = context.getReader().getOptionalAttributeValue(converter::ID, "");
if (!mId.empty()) {
adder.setId(mId);
}
const std::string& side = context.getReader().getOptionalAttributeValue(converter::SIDE, "");
if (!side.empty()) {
adder.setSide(Enum::fromString<Measurement::Side>(side));
Expand Down
17 changes: 17 additions & 0 deletions extensions/iidm/test/DiscreteMeasurementsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,23 @@ BOOST_FIXTURE_TEST_CASE(DiscreteMeasurementsXmlSerializerTest, test::ResourceFix
.putProperty("source", "test2")
.add();

Switch& sw2 = network.getSwitch("S1VL1_BBS_TWT_DISCONNECTOR");
sw2.newExtension<DiscreteMeasurementsAdder>().add();
sw2.getExtension<DiscreteMeasurements>()
.newDiscreteMeasurement()
.setType(DiscreteMeasurement::Type::SWITCH_POSITION)
.setValue("CLOSED")
.setValid(false)
.putProperty("source", "test")
.add();
sw2.getExtension<DiscreteMeasurements>()
.newDiscreteMeasurement()
.setType(DiscreteMeasurement::Type::OTHER)
.setValue("CLOSED")
.setValid(false)
.putProperty("source", "test")
.add();

const std::string& networkStrRef = ResourceFixture::getResource("/disMeasRef.xml");

test::converter::RoundTrip::runXml(network, networkStrRef);
Expand Down
17 changes: 17 additions & 0 deletions extensions/iidm/test/MeasurementsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ BOOST_FIXTURE_TEST_CASE(MeasurementsXmlSerializerTest, test::ResourceFixture) {
.setValid(true)
.putProperty("source", "test2")
.add();
twt.getExtension<Measurements>()
.newMeasurement()
.setType(Measurement::Type::ACTIVE_POWER)
.setSide(Measurement::Side::TWO)
.setValue(-300.0)
.setStandardDeviation(10.2)
.setValid(true)
.add();
twt.getExtension<Measurements>()
.newMeasurement()
.setType(Measurement::Type::ACTIVE_POWER)
.setSide(Measurement::Side::ONE)
.setValue(301.2)
.setStandardDeviation(9.7)
.setValid(true)
.putProperty("source", "test2")
.add();

const std::string& networkStrRef = ResourceFixture::getResource("/measRef.xml");

Expand Down

0 comments on commit 04d4cf5

Please sign in to comment.