|
| 1 | +package com.powsybl.openrao.monitoring.voltagemonitoring; |
| 2 | + |
| 3 | +import com.powsybl.commons.report.ReportNode; |
| 4 | +import com.powsybl.commons.report.TypedValue; |
| 5 | +import com.powsybl.openrao.data.cracapi.State; |
| 6 | + |
| 7 | +import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.*; |
| 8 | + |
| 9 | +public final class Reports { |
| 10 | + private Reports() { |
| 11 | + } |
| 12 | + |
| 13 | + private static String formatDouble(double doubleValue) { |
| 14 | + return String.format("%.0f", doubleValue); |
| 15 | + } |
| 16 | + |
| 17 | + public static ReportNode reportVoltageMonitoringStart(ReportNode reportNode) { |
| 18 | + ReportNode addedNode = reportNode.newReportNode() |
| 19 | + .withMessageTemplate("voltageMonitoringStart", "Voltage monitoring") |
| 20 | + .withSeverity(TypedValue.INFO_SEVERITY) |
| 21 | + .add(); |
| 22 | + BUSINESS_LOGS.info("----- Voltage monitoring [start]"); |
| 23 | + return addedNode; |
| 24 | + } |
| 25 | + |
| 26 | + public static ReportNode reportVoltageMonitoringEnd(ReportNode reportNode) { |
| 27 | + ReportNode addedNode = reportNode.newReportNode() |
| 28 | + .withMessageTemplate("voltageMonitoringEnd", "End of voltage monitoring") |
| 29 | + .withSeverity(TypedValue.INFO_SEVERITY) |
| 30 | + .add(); |
| 31 | + BUSINESS_LOGS.info("----- Voltage monitoring [end]"); |
| 32 | + return addedNode; |
| 33 | + } |
| 34 | + |
| 35 | + public static ReportNode reportNoVoltageCnecsDefined(ReportNode reportNode) { |
| 36 | + ReportNode addedNode = reportNode.newReportNode() |
| 37 | + .withMessageTemplate("noVoltageCnecsDefined", "No VoltageCnecs defined.") |
| 38 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 39 | + .add(); |
| 40 | + BUSINESS_WARNS.warn("No VoltageCnecs defined."); |
| 41 | + return addedNode; |
| 42 | + } |
| 43 | + |
| 44 | + public static ReportNode reportMonitoringVoltagesAtState(ReportNode reportNode, State state) { |
| 45 | + ReportNode addedNode = reportNode.newReportNode() |
| 46 | + .withMessageTemplate("monitoringVoltagesAtState", "Monitoring voltages at state '${state}'") |
| 47 | + .withUntypedValue("state", state.getId()) |
| 48 | + .withSeverity(TypedValue.INFO_SEVERITY) |
| 49 | + .add(); |
| 50 | + BUSINESS_LOGS.info("-- Monitoring voltages at state \"{}\" [start]", state); |
| 51 | + return addedNode; |
| 52 | + } |
| 53 | + |
| 54 | + public static ReportNode reportMonitoringVoltagesAtStateEnd(ReportNode reportNode, State state) { |
| 55 | + ReportNode addedNode = reportNode.newReportNode() |
| 56 | + .withMessageTemplate("monitoringVoltagesAtStateEnd", "End of monitoring voltages at state '${state}'") |
| 57 | + .withUntypedValue("state", state.getId()) |
| 58 | + .withSeverity(TypedValue.INFO_SEVERITY) |
| 59 | + .add(); |
| 60 | + BUSINESS_LOGS.info("-- Monitoring voltages at state \"{}\" [end]", state); |
| 61 | + return addedNode; |
| 62 | + } |
| 63 | + |
| 64 | + public static ReportNode reportNoConstrainedElements(ReportNode reportNode) { |
| 65 | + ReportNode addedNode = reportNode.newReportNode() |
| 66 | + .withMessageTemplate("noConstrainedElements", "All voltage CNECs are secure.") |
| 67 | + .withSeverity(TypedValue.INFO_SEVERITY) |
| 68 | + .add(); |
| 69 | + BUSINESS_LOGS.info("All voltage CNECs are secure."); |
| 70 | + return addedNode; |
| 71 | + } |
| 72 | + |
| 73 | + public static ReportNode reportSomeConstrainedElements(ReportNode reportNode) { |
| 74 | + ReportNode addedNode = reportNode.newReportNode() |
| 75 | + .withMessageTemplate("someConstrainedElements", "Some voltage CNECs are not secure:") |
| 76 | + .withSeverity(TypedValue.INFO_SEVERITY) |
| 77 | + .add(); |
| 78 | + BUSINESS_LOGS.info("Some voltage CNECs are not secure:"); |
| 79 | + return addedNode; |
| 80 | + } |
| 81 | + |
| 82 | + public static ReportNode reportConstrainedElement(ReportNode reportNode, String networkElementId, String stateId, double min, double max) { |
| 83 | + ReportNode addedNode = reportNode.newReportNode() |
| 84 | + .withMessageTemplate("constrainedElement", "Network element ${networkElementId} at state ${stateId} has a voltage of ${min} - ${max} kV.") |
| 85 | + .withUntypedValue("networkElementId", networkElementId) |
| 86 | + .withUntypedValue("stateId", stateId) |
| 87 | + .withUntypedValue("min", formatDouble(min)) |
| 88 | + .withUntypedValue("max", formatDouble(max)) |
| 89 | + .withSeverity(TypedValue.INFO_SEVERITY) |
| 90 | + .add(); |
| 91 | + BUSINESS_LOGS.info( |
| 92 | + String.format("Network element %s at state %s has a voltage of %.0f - %.0f kV.", |
| 93 | + networkElementId, |
| 94 | + stateId, |
| 95 | + min, |
| 96 | + max |
| 97 | + )); |
| 98 | + return addedNode; |
| 99 | + } |
| 100 | + |
| 101 | + public static ReportNode reportLoadflowComputationFailed(ReportNode reportNode, String stateId) { |
| 102 | + ReportNode addedNode = reportNode.newReportNode() |
| 103 | + .withMessageTemplate("loadflowComputationFailed", "Load-flow computation failed at state ${stateId} after applying RAs. Skipping this state.") |
| 104 | + .withUntypedValue("stateId", stateId) |
| 105 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 106 | + .add(); |
| 107 | + BUSINESS_WARNS.warn("Load-flow computation failed at state {} after applying RAs. Skipping this state.", stateId); |
| 108 | + return addedNode; |
| 109 | + } |
| 110 | + |
| 111 | + public static ReportNode reportNoRaAvailable(ReportNode reportNode, String cnecId, String stateId) { |
| 112 | + ReportNode addedNode = reportNode.newReportNode() |
| 113 | + .withMessageTemplate("noRaAvailable", "VoltageCnec ${cnecId} in state ${stateId} has no associated RA. Voltage constraint cannot be secured.") |
| 114 | + .withUntypedValue("cnecId", cnecId) |
| 115 | + .withUntypedValue("stateId", stateId) |
| 116 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 117 | + .add(); |
| 118 | + BUSINESS_WARNS.warn("VoltageCnec {} in state {} has no associated RA. Voltage constraint cannot be secured.", cnecId, stateId); |
| 119 | + return addedNode; |
| 120 | + } |
| 121 | + |
| 122 | + public static ReportNode reportConstraintInPreventive(ReportNode reportNode, String cnecId) { |
| 123 | + ReportNode addedNode = reportNode.newReportNode() |
| 124 | + .withMessageTemplate("constraintInPreventive", "VoltageCnec ${cnecId} is constrained in preventive state, it cannot be secured.") |
| 125 | + .withUntypedValue("cnecId", cnecId) |
| 126 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 127 | + .add(); |
| 128 | + BUSINESS_WARNS.warn("VoltageCnec {} is constrained in preventive state, it cannot be secured.", cnecId); |
| 129 | + return addedNode; |
| 130 | + } |
| 131 | + |
| 132 | + public static ReportNode reportIgnoredRemedialAction(ReportNode reportNode, String remedialActionId, String cnecId, String stateId) { |
| 133 | + ReportNode addedNode = reportNode.newReportNode() |
| 134 | + .withMessageTemplate("ignoredRemedialAction", "Remedial action ${remedialActionId} of VoltageCnec ${cnecId} in state ${stateId} is ignored : it's not a network action.") |
| 135 | + .withUntypedValue("remedialActionId", remedialActionId) |
| 136 | + .withUntypedValue("cnecId", cnecId) |
| 137 | + .withUntypedValue("stateId", stateId) |
| 138 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 139 | + .add(); |
| 140 | + BUSINESS_WARNS.warn("Remedial action {} of VoltageCnec {} in state {} is ignored : it's not a network action.", remedialActionId, cnecId, stateId); |
| 141 | + return addedNode; |
| 142 | + } |
| 143 | + |
| 144 | + public static ReportNode reportAppliedNetworkActions(ReportNode reportNode, String cnecId, String appliedRasList) { |
| 145 | + ReportNode addedNode = reportNode.newReportNode() |
| 146 | + .withMessageTemplate("appliedNetworkActions", "Applying the following remedial action(s) in order to reduce constraints on CNEC '${cnecId}': ${appliedRasList}") |
| 147 | + .withUntypedValue("cnecId", cnecId) |
| 148 | + .withUntypedValue("appliedRasList", appliedRasList) |
| 149 | + .withSeverity(TypedValue.INFO_SEVERITY) |
| 150 | + .add(); |
| 151 | + BUSINESS_LOGS.info("Applying the following remedial action(s) in order to reduce constraints on CNEC \"{}\": {}", cnecId, appliedRasList); |
| 152 | + return addedNode; |
| 153 | + } |
| 154 | + |
| 155 | + public static ReportNode reportLoadflowComputationStart(ReportNode reportNode) { |
| 156 | + ReportNode addedNode = reportNode.newReportNode() |
| 157 | + .withMessageTemplate("loadflowComputationStart", "Load-flow computation") |
| 158 | + .withSeverity(TypedValue.DEBUG_SEVERITY) |
| 159 | + .add(); |
| 160 | + TECHNICAL_LOGS.info("Load-flow computation [start]"); |
| 161 | + return addedNode; |
| 162 | + } |
| 163 | + |
| 164 | + public static ReportNode reportLoadflowComputationEnd(ReportNode reportNode) { |
| 165 | + ReportNode addedNode = reportNode.newReportNode() |
| 166 | + .withMessageTemplate("loadflowComputationEnd", "End of load-flow computation") |
| 167 | + .withSeverity(TypedValue.DEBUG_SEVERITY) |
| 168 | + .add(); |
| 169 | + TECHNICAL_LOGS.info("Load-flow computation [end]"); |
| 170 | + return addedNode; |
| 171 | + } |
| 172 | + |
| 173 | + public static ReportNode reportLoadflowError(ReportNode reportNode) { |
| 174 | + ReportNode addedNode = reportNode.newReportNode() |
| 175 | + .withMessageTemplate("loadflowError", "LoadFlow error.") |
| 176 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 177 | + .add(); |
| 178 | + BUSINESS_WARNS.warn("LoadFlow error."); |
| 179 | + return addedNode; |
| 180 | + } |
| 181 | + |
| 182 | + public static ReportNode reportVoltageMonitoringFailureAtState(ReportNode reportNode, String stateId) { |
| 183 | + ReportNode addedNode = reportNode.newReportNode() |
| 184 | + .withMessageTemplate("voltageMonitoringFailureAtState", "Load-flow computation failed at state ${stateId}. Skipping this state.") |
| 185 | + .withUntypedValue("stateId", stateId) |
| 186 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 187 | + .add(); |
| 188 | + BUSINESS_WARNS.warn("Load-flow computation failed at state {}. Skipping this state.", stateId); |
| 189 | + return addedNode; |
| 190 | + } |
| 191 | + |
| 192 | + static ReportNode reportPostContingencyTask(State state, ReportNode rootReportNode) { |
| 193 | + ReportNode scenarioReportNode = rootReportNode.newReportNode() |
| 194 | + .withMessageTemplate("postContingencyScenarioVoltageMonitoring", "Voltage monitoring post-contingency ${contingencyId}.") |
| 195 | + .withUntypedValue("contingencyId", state.getContingency().orElseThrow().getId()) |
| 196 | + .withSeverity(TypedValue.DEBUG_SEVERITY) |
| 197 | + .add(); |
| 198 | + return scenarioReportNode; |
| 199 | + } |
| 200 | + |
| 201 | + static ReportNode generatePostContingencyRootReportNode() { |
| 202 | + ReportNode rootReportNode = ReportNode.newRootReportNode() |
| 203 | + .withMessageTemplate("postContingencyVoltageMonitoring", "Voltage monitoring post-contingency.") |
| 204 | + .build(); |
| 205 | + return rootReportNode; |
| 206 | + } |
| 207 | +} |
0 commit comments