Skip to content

Commit a163e2c

Browse files
committed
feat(simulator): choose the scenario from a dropdown in the dashboard
List the scenario folders found in the environment's chronics directory in a select box instead of a free-text field, so new scenarios show up without typing their exact name.
1 parent e22708d commit a163e2c

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

‎usecases_examples/PowerGrid/PowerGrid_poc_simulator_app.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def dashboard():
5555
username=username,
5656
server=server,
5757
config=simu.config,
58+
scenarios=simu.list_scenarios(),
5859
com=com,
5960
messages=messages)
6061

‎usecases_examples/PowerGrid/app/models/Simulator.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import time
23
from datetime import datetime, timedelta, timezone
34
import grid2op
@@ -41,6 +42,24 @@ def __init__(self, socketio):
4142
self.agent_reco = None
4243
self.socketio = socketio
4344

45+
def list_scenarios(self):
46+
"""
47+
List the scenarios (chronics folders) available in the environment.
48+
49+
Returns:
50+
list[str]: Sorted scenario names, always including the configured one.
51+
"""
52+
chronics_dir = os.path.join(self.config.get('env_name', ''), 'chronics')
53+
try:
54+
names = [d for d in os.listdir(chronics_dir)
55+
if os.path.isdir(os.path.join(chronics_dir, d))]
56+
except OSError:
57+
names = []
58+
current = self.config.get('scenario_name')
59+
if current and current not in names:
60+
names.append(current)
61+
return sorted(names)
62+
4463
def load_and_edit_config(self, params=None):
4564
"""
4665
Load and optionally edit the configuration from a TOML file.

‎usecases_examples/PowerGrid/app/templates/dashboard.html‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@
172172
margin-top: 8px;
173173
margin-bottom: 2px;
174174
}
175-
#user-info input {
175+
#user-info input,
176+
#user-info select {
176177
padding: 9px 12px;
177178
font-size: 14px;
178179
border: 1px solid var(--border);
@@ -183,7 +184,8 @@
183184
margin-bottom: 4px;
184185
transition: border-color 0.15s, box-shadow 0.15s;
185186
}
186-
#user-info input:focus {
187+
#user-info input:focus,
188+
#user-info select:focus {
187189
outline: none;
188190
border-color: var(--primary);
189191
box-shadow: 0 0 0 3px var(--primary-soft);
@@ -436,8 +438,12 @@ <h3>Simulator configuration</h3>
436438
<form action="{{ url_for('edit_config') }}" method="post">
437439
<label>Grid2Op environment's seed</label>
438440
<input type="text" name="env_seed" value="{{ config['env_seed'] }}">
439-
<label>Scenario name</label>
440-
<input type="text" name="scenario_name" value="{{ config['scenario_name'] }}">
441+
<label for="scenario_name">Scenario</label>
442+
<select id="scenario_name" name="scenario_name" required>
443+
{% for name in scenarios %}
444+
<option value="{{ name }}" {% if name == config['scenario_name'] %}selected{% endif %}>{{ name }}</option>
445+
{% endfor %}
446+
</select>
441447
<label>Assistant seed</label>
442448
<input type="text" name="assistant_seed" value="{{ config['assistant_seed'] }}">
443449
<button type="submit">Update</button>

0 commit comments

Comments
 (0)