dlaj commited on
Commit
ae596a8
·
verified ·
1 Parent(s): b2b4a5b

Update streamlit_simulation/app.py

Browse files
Files changed (1) hide show
  1. streamlit_simulation/app.py +27 -28
streamlit_simulation/app.py CHANGED
@@ -183,15 +183,14 @@ def predict_transformer_step(model, dataset, idx, device):
183
 
184
 
185
  def init_simulation_layout():
186
- """Creates layout containers for plot and info sections."""
187
- col1, spacer, col2 = st.columns([3, 0.2, 1])
188
- plot_title = col1.empty()
189
- plot_container = col1.empty()
190
- x_axis_label = col1.empty()
191
- info_container = col2.empty()
192
  return plot_title, plot_container, x_axis_label, info_container
193
 
194
 
 
195
  def create_prediction_plot(pred_timestamps, pred_vals, true_timestamps, true_vals, window_hours, y_min=None, y_max=None):
196
  """Generates the matplotlib figure for plotting prediction vs. actual."""
197
  fig, ax = plt.subplots(figsize=(8, 5), constrained_layout=False, facecolor=PLOT_COLOR)
@@ -243,37 +242,37 @@ def render_simulation_view(timestamp, prediction, actual, progress, fig, paused=
243
  unsafe_allow_html=True
244
  )
245
 
246
- with info_container.container():
247
- st.markdown("<div style='margin-top: 5rem;'></div>", unsafe_allow_html=True)
248
  st.markdown(
249
  f"<span style='font-size: 24px; font-weight: 600; color: {HEADER_COLOR} !important;'>Time: {timestamp}</span>",
250
  unsafe_allow_html=True
251
  )
252
-
253
  st.metric("Prediction", f"{prediction:,.0f} MW" if prediction is not None else "–")
254
  st.metric("Actual", f"{actual:,.0f} MW" if actual is not None else "–")
255
  st.caption("Simulation Progress")
256
  st.progress(progress)
257
 
258
- if len(st.session_state.true_vals) > 1:
259
- true_arr = np.array(st.session_state.true_vals)
260
- pred_arr = np.array(st.session_state.pred_vals[:-1])
261
-
262
- min_len = min(len(true_arr), len(pred_arr)) #just start if there are 2 actual values
263
- if min_len >= 1:
264
- errors = np.abs(true_arr[:min_len] - pred_arr[:min_len])
265
- mape = np.mean(errors / np.where(true_arr[:min_len] == 0, 1e-10, true_arr[:min_len])) * 100
266
- mae = np.mean(errors)
267
- max_error = np.max(errors)
268
-
269
- st.divider()
270
- st.markdown(
271
- f"<span style='font-size: 24px; font-weight: 600; color: {HEADER_COLOR} !important;'>Interim Metrics</span>",
272
- unsafe_allow_html=True
273
- )
274
- st.metric("MAPE (so far)", f"{mape:.2f} %")
275
- st.metric("MAE (so far)", f"{mae:,.0f} MW")
276
- st.metric("Max Error", f"{max_error:,.0f} MW")
277
 
278
 
279
 
 
183
 
184
 
185
  def init_simulation_layout():
186
+ plot_title = st.empty()
187
+ plot_container = st.empty()
188
+ x_axis_label = st.empty()
189
+ info_container = st.container()
 
 
190
  return plot_title, plot_container, x_axis_label, info_container
191
 
192
 
193
+
194
  def create_prediction_plot(pred_timestamps, pred_vals, true_timestamps, true_vals, window_hours, y_min=None, y_max=None):
195
  """Generates the matplotlib figure for plotting prediction vs. actual."""
196
  fig, ax = plt.subplots(figsize=(8, 5), constrained_layout=False, facecolor=PLOT_COLOR)
 
242
  unsafe_allow_html=True
243
  )
244
 
245
+ with info_container:
246
+ st.markdown("---")
247
  st.markdown(
248
  f"<span style='font-size: 24px; font-weight: 600; color: {HEADER_COLOR} !important;'>Time: {timestamp}</span>",
249
  unsafe_allow_html=True
250
  )
251
+
252
  st.metric("Prediction", f"{prediction:,.0f} MW" if prediction is not None else "–")
253
  st.metric("Actual", f"{actual:,.0f} MW" if actual is not None else "–")
254
  st.caption("Simulation Progress")
255
  st.progress(progress)
256
 
257
+ #if len(st.session_state.true_vals) > 1:
258
+ # true_arr = np.array(st.session_state.true_vals)
259
+ #pred_arr = np.array(st.session_state.pred_vals[:-1])
260
+
261
+ # min_len = min(len(true_arr), len(pred_arr)) #just start if there are 2 actual values
262
+ # if min_len >= 1:
263
+ # errors = np.abs(true_arr[:min_len] - pred_arr[:min_len])
264
+ #mape = np.mean(errors / np.where(true_arr[:min_len] == 0, 1e-10, true_arr[:min_len])) * 100
265
+ #mae = np.mean(errors)
266
+ #max_error = np.max(errors)
267
+
268
+ #st.divider()
269
+ #st.markdown(
270
+ # f"<span style='font-size: 24px; font-weight: 600; color: {HEADER_COLOR} !important;'>Interim Metrics</span>",
271
+ # unsafe_allow_html=True
272
+ # )
273
+ #st.metric("MAPE (so far)", f"{mape:.2f} %")
274
+ # st.metric("MAE (so far)", f"{mae:,.0f} MW")
275
+ #st.metric("Max Error", f"{max_error:,.0f} MW")
276
 
277
 
278