Daniel Varga commited on
Commit
a75dce3
·
1 Parent(s): cd31c8b

settable date ranges

Browse files
Files changed (1) hide show
  1. v2/app.py +38 -8
v2/app.py CHANGED
@@ -5,6 +5,8 @@ import numpy as np
5
  import pandas as pd
6
  import gradio as gr
7
  from types import SimpleNamespace
 
 
8
 
9
  # from simulation import *
10
  from data_processing import *
@@ -115,7 +117,8 @@ def ui_refresh(
115
  solar_cell_num, solar_cell_nominal_capacity,
116
  bess_capacity_Ah, bess_voltage_V, bess_charge_kW, bess_discharge_kW,
117
  fixed_consumption_checkbox, fixed_consumption_kW,
118
- base_price_HUFpkWh, peak_price_HUFpkWh):
 
119
 
120
  if not fixed_consumption_checkbox:
121
  fixed_consumption_kW = None # None means use dataframe.
@@ -128,9 +131,22 @@ def ui_refresh(
128
 
129
  results = recalculate(ui)
130
 
131
- # TODO generalize to other input ranges
132
- fig1 = plotly_visualize_simulation(results, date_range=("2021-02-01", "2021-02-07"))
133
- fig2 = plotly_visualize_simulation(results, date_range=("2021-08-02", "2021-08-08"))
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
  # (12, 3), the 3 indexed with (network, solar, bess):
136
  consumptions_in_mwh = monthly_analysis(results)
@@ -175,18 +191,32 @@ with gr.Blocks() as ui:
175
 
176
  run_btn = gr.Button("Run Simulation")
177
 
 
 
 
178
  # RIGHT: Output display
179
  with gr.Column(scale=2): # wider column
180
  html_out = gr.HTML()
181
- plot1 = gr.Plot()
182
- plot2 = gr.Plot()
183
- plot3 = gr.Plot()
 
 
 
 
 
 
 
 
 
 
184
 
185
  inputs = [
186
  solar_cell_num, solar_cell_nominal_capacity,
187
  bess_capacity_Ah, bess_voltage_V, bess_charge_kW, bess_discharge_kW,
188
  fixed_consumption_checkbox, fixed_consumption_kW,
189
- base_price_HUFpkWh, peak_price_HUFpkWh
 
190
  ]
191
 
192
  run_btn.click(
 
5
  import pandas as pd
6
  import gradio as gr
7
  from types import SimpleNamespace
8
+ import datetime
9
+
10
 
11
  # from simulation import *
12
  from data_processing import *
 
117
  solar_cell_num, solar_cell_nominal_capacity,
118
  bess_capacity_Ah, bess_voltage_V, bess_charge_kW, bess_discharge_kW,
119
  fixed_consumption_checkbox, fixed_consumption_kW,
120
+ base_price_HUFpkWh, peak_price_HUFpkWh,
121
+ week_a, week_b):
122
 
123
  if not fixed_consumption_checkbox:
124
  fixed_consumption_kW = None # None means use dataframe.
 
131
 
132
  results = recalculate(ui)
133
 
134
+
135
+ # TODO this is a bit too vibey
136
+ start_a = (week_a if isinstance(week_a, datetime.datetime) else
137
+ datetime.datetime.fromisoformat(week_a))
138
+ end_a = start_a + datetime.timedelta(days=6)
139
+
140
+ start_b = (week_b if isinstance(week_b, datetime.datetime) else
141
+ datetime.datetime.fromisoformat(week_b))
142
+ end_b = start_b + datetime.timedelta(days=6)
143
+
144
+ date_range_a = (start_a.strftime("%Y-%m-%d"), end_a.strftime("%Y-%m-%d"))
145
+ date_range_b = (start_b.strftime("%Y-%m-%d"), end_b.strftime("%Y-%m-%d"))
146
+
147
+ fig1 = plotly_visualize_simulation(results, date_range=date_range_a)
148
+ fig2 = plotly_visualize_simulation(results, date_range=date_range_b)
149
+
150
 
151
  # (12, 3), the 3 indexed with (network, solar, bess):
152
  consumptions_in_mwh = monthly_analysis(results)
 
191
 
192
  run_btn = gr.Button("Run Simulation")
193
 
194
+ week_a_default = "2021-02-01" ; week_b_default = "2021-08-02"
195
+ # week_b_default = datetime.date(2021, 2, 1) ; week_b_default = datetime.date(2021, 8, 2)
196
+
197
  # RIGHT: Output display
198
  with gr.Column(scale=2): # wider column
199
  html_out = gr.HTML()
200
+ plot1 = gr.Plot(label="Monthly energy use")
201
+
202
+ # date selector + Plot 2
203
+ week_a = gr.DateTime(
204
+ value=week_a_default, include_time=False, label="Start date for Week A", type="string"
205
+ )
206
+ plot2 = gr.Plot(label="Week A")
207
+
208
+ # date selector + Plot 3
209
+ week_b = gr.DateTime(
210
+ value=week_b_default, include_time=False, label="Start date for Week B", type="string"
211
+ )
212
+ plot3 = gr.Plot(label="Week B")
213
 
214
  inputs = [
215
  solar_cell_num, solar_cell_nominal_capacity,
216
  bess_capacity_Ah, bess_voltage_V, bess_charge_kW, bess_discharge_kW,
217
  fixed_consumption_checkbox, fixed_consumption_kW,
218
+ base_price_HUFpkWh, peak_price_HUFpkWh,
219
+ week_a, week_b
220
  ]
221
 
222
  run_btn.click(