Daniel Varga commited on
Commit
02d3062
1 Parent(s): 53f6150
Files changed (1) hide show
  1. app.py +56 -7
app.py CHANGED
@@ -288,6 +288,15 @@ def visualize_simulation(results, date_range):
288
  return fig
289
 
290
 
 
 
 
 
 
 
 
 
 
291
  def plotly_visualize_simulation(results, date_range):
292
  start_date, end_date = date_range
293
  results = results.loc[start_date: end_date]
@@ -319,12 +328,49 @@ def plotly_visualize_simulation(results, date_range):
319
  name='BESS',
320
  stackgroup='one'
321
  ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  fig.update_layout(
 
323
  height=400
324
  )
325
  return fig
326
 
327
 
 
328
  def monthly_analysis(results):
329
  consumptions = []
330
  for month in range(1, 13):
@@ -435,22 +481,25 @@ def ui_refresh(solar_cell_num, bess_nominal_capacity, fixed_consumption):
435
  # (12, 3), the 3 indexed with (network, solar, bess):
436
  consumptions_in_mwh = monthly_analysis(results)
437
 
 
 
438
  network, solar, bess = consumptions_in_mwh.sum(axis=0)
439
- html = ""
440
  for column, column_name in zip((network, solar, bess), ("network", "solar", "BESS")):
441
- html += f"Yearly consumption satisfied by {column_name}: {column:0.2f} MWh<br>"
 
442
 
443
- return (fig1, fig2, html)
444
 
445
 
446
  ui = gr.Interface(
447
  ui_refresh,
448
  inputs = [
449
  gr.Slider(0, 2000, 114, label="Solar cell number"),
450
- gr.Slider(0, 1000, 330, label="BESS nominal capacity"),
451
- gr.Checkbox(value=False, label="Fixed consumption")],
452
- outputs = ["plot", "plot", "html"],
453
  live=True,
454
  )
455
 
456
- ui.launch()
 
288
  return fig
289
 
290
 
291
+ MARGIN = dict(
292
+ l=0,
293
+ r=0,
294
+ b=0,
295
+ t=0,
296
+ pad=0
297
+ )
298
+
299
+
300
  def plotly_visualize_simulation(results, date_range):
301
  start_date, end_date = date_range
302
  results = results.loc[start_date: end_date]
 
328
  name='BESS',
329
  stackgroup='one'
330
  ))
331
+ # could not kill the huge padding this introduces:
332
+ # fig.update_layout(title=f"Simulation for {start_date} - {end_date}")
333
+ fig.update_layout(height=400, yaxis_title="Consumption in [kW]")
334
+
335
+ return fig
336
+
337
+
338
+ def plotly_visualize_monthly(consumption):
339
+ # months = monthly_results.index
340
+ months = list(range(1, 13))
341
+ fig = go.Figure()
342
+ fig.add_trace(go.Scatter(
343
+ x=months, y=consumption[:, 0], # monthly_results['consumption_from_network'],
344
+ hoverinfo='x+y',
345
+ mode='lines',
346
+ line=dict(width=0.5, color='blue'),
347
+ name='Network',
348
+ stackgroup='one' # define stack group
349
+ ))
350
+ fig.add_trace(go.Scatter(
351
+ x=months, y=consumption[:, 1], # y=monthly_results['consumption_from_solar'],
352
+ hoverinfo='x+y',
353
+ mode='lines',
354
+ line=dict(width=0.5, color='orange'),
355
+ name='Solar',
356
+ stackgroup='one'
357
+ ))
358
+ fig.add_trace(go.Scatter(
359
+ x=months, y=consumption[:, 2], # y=monthly_results['consumption_from_bess'],
360
+ hoverinfo='x+y',
361
+ mode='lines',
362
+ line=dict(width=0.5, color='green'),
363
+ name='BESS',
364
+ stackgroup='one'
365
+ ))
366
  fig.update_layout(
367
+ yaxis_title="Monthly consumption in [MWh]",
368
  height=400
369
  )
370
  return fig
371
 
372
 
373
+ # TODO build a dataframe instead
374
  def monthly_analysis(results):
375
  consumptions = []
376
  for month in range(1, 13):
 
481
  # (12, 3), the 3 indexed with (network, solar, bess):
482
  consumptions_in_mwh = monthly_analysis(results)
483
 
484
+ fig_monthly = plotly_visualize_monthly(consumptions_in_mwh)
485
+
486
  network, solar, bess = consumptions_in_mwh.sum(axis=0)
487
+ html = "<table>\n"
488
  for column, column_name in zip((network, solar, bess), ("network", "solar", "BESS")):
489
+ html += f"<tr><td>Yearly consumption satisfied by {column_name}:&nbsp;&nbsp;&nbsp;</td><td>{column:0.2f} MWh</td></tr>\n"
490
+ html += "</table>"
491
 
492
+ return (html, fig_monthly, fig1, fig2)
493
 
494
 
495
  ui = gr.Interface(
496
  ui_refresh,
497
  inputs = [
498
  gr.Slider(0, 2000, 114, label="Solar cell number"),
499
+ gr.Slider(0, 2000, 330, label="BESS nominal capacity in [Ah]"),
500
+ gr.Checkbox(value=False, label="Use fixed consumption (10 kW)")],
501
+ outputs = ["html", "plot", "plot", "plot"],
502
  live=True,
503
  )
504
 
505
+ ui.launch(show_api=False)