From 9b4ca5bd8024db6088456259006bbc80aa2d6bdd Mon Sep 17 00:00:00 2001 From: BOUHOURS Antoine Date: Wed, 26 Jun 2024 16:45:53 +0200 Subject: [PATCH] Add parameter logs before the computation Signed-off-by: BOUHOURS Antoine --- dynaflow/pom.xml | 9 +++++++ .../powsybl/dynaflow/DynaFlowParameters.java | 25 +++++++++++++++++++ .../powsybl/dynaflow/DynaFlowProvider.java | 1 + 3 files changed, 35 insertions(+) diff --git a/dynaflow/pom.xml b/dynaflow/pom.xml index 8bf8cbf88..c85415d4f 100644 --- a/dynaflow/pom.xml +++ b/dynaflow/pom.xml @@ -20,6 +20,10 @@ DynaFlow DynaFlow integration module for powsybl + + 0.3.2 + + @@ -42,6 +46,11 @@ ${project.groupId} powsybl-dynawo-commons + + de.vandermeer + asciitable + ${asciitable.version} + diff --git a/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowParameters.java b/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowParameters.java index fd5cf7eec..78314fe1f 100644 --- a/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowParameters.java +++ b/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowParameters.java @@ -19,6 +19,10 @@ import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.dynaflow.DynaFlowConstants.ActivePowerCompensation; import com.powsybl.dynaflow.DynaFlowConstants.StartingPointMode; +import de.vandermeer.asciitable.AsciiTable; +import de.vandermeer.asciitable.CWC_LongestWord; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.*; @@ -33,6 +37,8 @@ */ public class DynaFlowParameters extends AbstractExtension { + private static final Logger LOGGER = LoggerFactory.getLogger(DynaFlowParameters.class); + /** * Inner class dedicated to Security Analysis (SA) namespace */ @@ -353,6 +359,25 @@ private static void load(DynaFlowParameters parameters, ModuleConfig config) { config.getOptionalBooleanProperty(MERGE_LOADS).ifPresent(parameters::setMergeLoads); } + public static void log(LoadFlowParameters parameters, DynaFlowParameters parametersExt) { + if (LOGGER.isInfoEnabled()) { + AsciiTable at = new AsciiTable(); + at.addRule(); + at.addRow("Name", "Value"); + at.addRule(); + for (var e : parameters.toMap().entrySet()) { + at.addRow(e.getKey(), e.getValue()); + } + for (var e : parametersExt.createMapFromParameters().entrySet()) { + at.addRow(e.getKey(), Objects.toString(e.getValue(), "")); + } + at.addRule(); + at.getRenderer().setCWC(new CWC_LongestWord()); + at.setPaddingLeftRight(1, 1); + LOGGER.info("Parameters:\n{}", at.render()); + } + } + public void update(Map properties) { Objects.requireNonNull(properties); Optional.ofNullable(properties.get(SVC_REGULATION_ON)).ifPresent(prop -> setSvcRegulationOn(Boolean.parseBoolean(prop))); diff --git a/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowProvider.java b/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowProvider.java index e7581daac..1c3064884 100644 --- a/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowProvider.java +++ b/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowProvider.java @@ -115,6 +115,7 @@ public CompletableFuture run(Network network, ComputationManager Objects.requireNonNull(workingStateId); Objects.requireNonNull(loadFlowParameters); DynaFlowParameters dynaFlowParameters = getParametersExt(loadFlowParameters); + DynaFlowParameters.log(loadFlowParameters, dynaFlowParameters); DynaFlowConfig config = Objects.requireNonNull(configSupplier.get()); ExecutionEnvironment env = new ExecutionEnvironment(config.createEnv(), WORKING_DIR_PREFIX, config.isDebug()); Command versionCmd = getVersionCommand(config);