Skip to content

Commit ff7ee00

Browse files
ahmeriqueabdratsd
authored andcommitted
Issue #2: Improve line name readability by formatting the displayed line name as {origin_subid}:{origin_extremity}:{line_name}
1 parent 4d02f8f commit ff7ee00

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

usecases_examples/PowerGrid/PowerGrid_poc_simulator_consol.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ def _stop_if_anticipation_security_analysis(self, obs, env, contingency_line_ids
9292
rho = []
9393
for j, value in enumerate(flow):
9494
if value / thermal_limit[j] >= 1.0:
95-
impacted_lines = obs.name_line[j]
95+
impacted_lines = get_formatted_name_line(obs,j)
9696
rho.append(value / thermal_limit[j])
9797
if len(impacted_lines) > 0:
98-
line_name = obs.name_line[c_value]
98+
line_name = get_formatted_name_line(obs,c_value)
9999
anticipation.append((line_name, impacted_lines, rho))
100100

101101
self._anticipation = None
@@ -688,17 +688,19 @@ def search_chronic_num_from_name(scenario_name,
688688

689689

690690
def get_curent_lines_in_bad_KPI(obs):
691-
"""Identify the line with the worst KPI in the grid."""
692-
res = np.where(obs.rho == obs.rho.max())
693-
name = obs.name_line[res[0]]
694-
return name[0]
691+
"""Identify the line with the worst KPI in the grid in the following format: {line_or_to_subid}:{line_ex_to_subid}:{name_line}."""
692+
res = (obs.rho == obs.rho.max()).tolist().index(True)
693+
return get_formatted_name_line(obs, res)
695694

696695

697696
def get_curent_lines_lost(obs):
698-
"""Identify disconnected lines in the grid."""
699-
res = np.where(obs.line_status is False)
700-
name = obs.name_line[res[0]]
701-
return name[0]
697+
"""Identify disconnected lines in the grid in the following format: {line_or_to_subid}:{line_ex_to_subid}:{name_line}."""
698+
res = (obs.line_status is False).tolist().index(True)
699+
return get_formatted_name_line(obs, res)
700+
701+
def get_formatted_name_line(obs, idx):
702+
"""Format line name to {line_or_to_subid}:{line_ex_to_subid}:{name_line}"""
703+
return f"{obs.line_or_to_subid[idx]}:{obs.line_ex_to_subid[idx]}:{obs.name_line[idx]}"
702704

703705

704706
def get_zone_where_alarm_occured(obs):

usecases_examples/PowerGrid/app/models/Listener.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from config.config import logging
33
from lightsim2grid import SecurityAnalysis
44

5+
from app.models.utils import get_formatted_name_line
6+
7+
58
class Listener:
69
"""This class has all the simulator's functions
710
that will stream and diagnose any Grid2Op selected data and events."""
@@ -104,12 +107,12 @@ def _stop_if_anticipation_security_analysis(self, obs, env, contingency_line_ids
104107

105108
for i, c_value in enumerate(contingency_line_ids):
106109
flow = np.array(res_a[i])
107-
impacted_lines = [(obs.name_line[j], value / thermal_limit[j])
110+
impacted_lines = [(get_formatted_name_line(obs,j), value / thermal_limit[j])
108111
for j, value in enumerate(flow)
109112
if value / thermal_limit[j] >= 1.0]
110113

111114
if impacted_lines:
112-
line_name = obs.name_line[c_value]
115+
line_name = get_formatted_name_line(obs,c_value)
113116
anticipation.append((line_name, *zip(*impacted_lines)))
114117

115118
self._anticipation = anticipation if anticipation else None

usecases_examples/PowerGrid/app/models/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ def get_curent_lines_in_bad_kpi(obs):
6767
obs: The current observation.
6868
6969
Returns:
70-
str: Name of the line with the worst KPI.
70+
str: Name of the line with the worst KPI in the following format: {line_or_to_subid}:{line_ex_to_subid}:{name_line}
7171
"""
72-
res = np.where(obs.rho == obs.rho.max())
73-
name = obs.name_line[res[0]]
74-
return name[0]
72+
res = (obs.rho == obs.rho.max()).tolist().index(True)
73+
return get_formatted_name_line(obs, res)
7574

7675

7776
def get_curent_lines_lost(obs):
@@ -82,12 +81,13 @@ def get_curent_lines_lost(obs):
8281
obs: The current observation.
8382
8483
Returns:
85-
str: Name of the first lost line.
84+
str: Name of the first lost line in the following format: {line_or_to_subid}:{line_ex_to_subid}:{name_line}.
8685
"""
87-
res = np.where(obs.line_status is False)
88-
name = obs.name_line[res[0]]
89-
return name[0]
86+
res = (obs.line_status is False).tolist().index(True)
87+
return get_formatted_name_line(obs, res)
9088

89+
def get_formatted_name_line(obs, idx):
90+
return f"{obs.line_or_to_subid[idx]}:{obs.line_ex_to_subid[idx]}:{obs.name_line[idx]}"
9191

9292
def get_zone_where_alarm_occured(obs):
9393
"""

0 commit comments

Comments
 (0)