From 04d4cf5d626127aa229ccd9efcaf213092fb5db8 Mon Sep 17 00:00:00 2001 From: gaouizer <159435571+gaouizer@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:41:59 +0200 Subject: [PATCH] Id attribute optional in measurement/discrete measurement extensions (#452) * Make measurement and discrete measurement extensions id attribute optional * Fix clang-tidy cognitive-complexity Signed-off-by: gaouizer --- .clang-tidy | 3 +++ extensions/iidm/resources/disMeasRef.xml | 10 ++++++++++ extensions/iidm/resources/measRef.xml | 4 ++++ .../src/DiscreteMeasurementsXmlSerializer.cpp | 5 ++++- .../iidm/src/MeasurementsXmlSerializer.cpp | 5 ++++- .../iidm/test/DiscreteMeasurementsTest.cpp | 17 +++++++++++++++++ extensions/iidm/test/MeasurementsTest.cpp | 17 +++++++++++++++++ 7 files changed, 59 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index cbb1e2f4..99f071ba 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -27,3 +27,6 @@ Checks: '-*, WarningsAsErrors: '*' HeaderFilterRegex: 'include/powsybl/.*|src/.*|extensions/.*|test/.*' + +CheckOptions: +- { key: readability-function-cognitive-complexity.IgnoreMacros, value: true } diff --git a/extensions/iidm/resources/disMeasRef.xml b/extensions/iidm/resources/disMeasRef.xml index 08a386e4..75e7040f 100644 --- a/extensions/iidm/resources/disMeasRef.xml +++ b/extensions/iidm/resources/disMeasRef.xml @@ -206,6 +206,16 @@ + + + + + + + + + + diff --git a/extensions/iidm/resources/measRef.xml b/extensions/iidm/resources/measRef.xml index 2ea5239b..a0f5252b 100644 --- a/extensions/iidm/resources/measRef.xml +++ b/extensions/iidm/resources/measRef.xml @@ -52,6 +52,10 @@ + + + + diff --git a/extensions/iidm/src/DiscreteMeasurementsXmlSerializer.cpp b/extensions/iidm/src/DiscreteMeasurementsXmlSerializer.cpp index a128544f..589f09b8 100644 --- a/extensions/iidm/src/DiscreteMeasurementsXmlSerializer.cpp +++ b/extensions/iidm/src/DiscreteMeasurementsXmlSerializer.cpp @@ -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(reader.getAttributeValue(TYPE))) .setValid(reader.getAttributeValue(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(tapChanger)); diff --git a/extensions/iidm/src/MeasurementsXmlSerializer.cpp b/extensions/iidm/src/MeasurementsXmlSerializer.cpp index f95c1168..8bd59188 100644 --- a/extensions/iidm/src/MeasurementsXmlSerializer.cpp +++ b/extensions/iidm/src/MeasurementsXmlSerializer.cpp @@ -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(context.getReader().getAttributeValue(converter::TYPE))) .setValue(context.getReader().getOptionalAttributeValue(converter::VALUE, stdcxx::nan())) .setStandardDeviation(context.getReader().getOptionalAttributeValue("standardDeviation", stdcxx::nan())) .setValid(context.getReader().getAttributeValue("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(side)); diff --git a/extensions/iidm/test/DiscreteMeasurementsTest.cpp b/extensions/iidm/test/DiscreteMeasurementsTest.cpp index d21b674b..c9b7c2f8 100644 --- a/extensions/iidm/test/DiscreteMeasurementsTest.cpp +++ b/extensions/iidm/test/DiscreteMeasurementsTest.cpp @@ -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().add(); + sw2.getExtension() + .newDiscreteMeasurement() + .setType(DiscreteMeasurement::Type::SWITCH_POSITION) + .setValue("CLOSED") + .setValid(false) + .putProperty("source", "test") + .add(); + sw2.getExtension() + .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); diff --git a/extensions/iidm/test/MeasurementsTest.cpp b/extensions/iidm/test/MeasurementsTest.cpp index bcce0104..fb2bac52 100644 --- a/extensions/iidm/test/MeasurementsTest.cpp +++ b/extensions/iidm/test/MeasurementsTest.cpp @@ -213,6 +213,23 @@ BOOST_FIXTURE_TEST_CASE(MeasurementsXmlSerializerTest, test::ResourceFixture) { .setValid(true) .putProperty("source", "test2") .add(); + twt.getExtension() + .newMeasurement() + .setType(Measurement::Type::ACTIVE_POWER) + .setSide(Measurement::Side::TWO) + .setValue(-300.0) + .setStandardDeviation(10.2) + .setValid(true) + .add(); + twt.getExtension() + .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");