Daniel Varga commited on
Commit
d58b6ea
·
1 Parent(s): b9dfd27

uploadable data files doing something, flaky yet

Browse files
Files changed (2) hide show
  1. app.py +34 -7
  2. data_processing.py +6 -16
app.py CHANGED
@@ -21,9 +21,17 @@ from bess import BatteryParameters, BatteryModel
21
  # !wget "https://static.renyi.hu/ai-shared/daniel/pq/pq_terheles_2021_adatok.tsv"
22
 
23
  OLD_DATASET = False
 
24
 
 
 
 
 
 
 
25
 
26
- met_2021_data, cons_2021_data = read_datasets(old_dataset=OLD_DATASET)
 
27
 
28
 
29
  # TODO some gui to upload consumption data.
@@ -35,20 +43,39 @@ def recalculate(ui):
35
 
36
  solar_parameters = SolarParameters(solar_cell_num=ui.solar_cell_num, panel_power_at_NOCT=ui.solar_cell_nominal_capacity)
37
 
 
 
 
 
 
 
 
 
 
 
38
  if ui.consumption_csv is not None:
39
  print("Hm, we should do something with this CSV.", ui.consumption_csv.name)
 
 
 
 
 
 
 
 
 
40
 
41
- add_production_field(met_2021_data, solar_parameters)
42
 
43
  if OLD_DATASET:
44
  # i've obsoleted this, but it's not a 100% replacement,
45
  # it treats daylight savings changes differently.
46
  # new version drops repeated hour and interpolates skipped hour.
47
- all_data = interpolate_and_join(met_2021_data, cons_2021_data)
48
  else:
49
  all_data = join_consumption_meteorology(
50
- cons_2021_data,
51
- met_2021_data,
52
  target_freq="5min",
53
  )
54
 
@@ -207,8 +234,8 @@ with gr.Blocks() as ui:
207
  base_price_HUFpkWh = gr.Number(value=60, label="Base energy price [HUF/kWh]")
208
 
209
  with gr.Accordion("Custom consumption/meteorology data", open=False):
210
- consumption_csv = gr.File(label="Upload consumption CSV", file_types=[".csv"])
211
- meteorology_csv = gr.File(label="Upload meteorology CSV", file_types=[".csv"])
212
 
213
  run_btn = gr.Button("Run Simulation")
214
 
 
21
  # !wget "https://static.renyi.hu/ai-shared/daniel/pq/pq_terheles_2021_adatok.tsv"
22
 
23
  OLD_DATASET = False
24
+ MINI = False
25
 
26
+ if MINI:
27
+ met_default_filename = 'PL_44527.2101.csv.gz'
28
+ cons_default_filename = 'pq_terheles_202101_adatok.tsv'
29
+ else:
30
+ met_default_filename = 'PL_44527.19-21.csv.gz'
31
+ cons_default_filename = 'pq_terheles_2021_adatok.tsv'
32
 
33
+
34
+ met_2021_data, cons_2021_data = read_datasets(met_default_filename, cons_default_filename, old_dataset=OLD_DATASET)
35
 
36
 
37
  # TODO some gui to upload consumption data.
 
43
 
44
  solar_parameters = SolarParameters(solar_cell_num=ui.solar_cell_num, panel_power_at_NOCT=ui.solar_cell_nominal_capacity)
45
 
46
+ met_data = met_2021_data
47
+ cons_data = cons_2021_data
48
+
49
+ changed_datasource = False
50
+
51
+ if ui.meteorology_csv is not None:
52
+ met_filename = ui.meteorology_csv.name
53
+ changed_datasource = True
54
+ else:
55
+ met_filename = met_default_filename
56
  if ui.consumption_csv is not None:
57
  print("Hm, we should do something with this CSV.", ui.consumption_csv.name)
58
+ cons_filename = ui.consumption_csv.name
59
+ changed_datasource = True
60
+ else:
61
+ cons_filename = cons_default_filename
62
+
63
+ if changed_datasource:
64
+ met_data, cons_data = read_datasets(met_filename, cons_filename, old_dataset=OLD_DATASET)
65
+ else:
66
+ met_data, cons_data = met_2021_data, cons_2021_data
67
 
68
+ add_production_field(met_data, solar_parameters)
69
 
70
  if OLD_DATASET:
71
  # i've obsoleted this, but it's not a 100% replacement,
72
  # it treats daylight savings changes differently.
73
  # new version drops repeated hour and interpolates skipped hour.
74
+ all_data = interpolate_and_join(met_data, cons_data)
75
  else:
76
  all_data = join_consumption_meteorology(
77
+ met_data,
78
+ cons_data,
79
  target_freq="5min",
80
  )
81
 
 
234
  base_price_HUFpkWh = gr.Number(value=60, label="Base energy price [HUF/kWh]")
235
 
236
  with gr.Accordion("Custom consumption/meteorology data", open=False):
237
+ consumption_csv = gr.File(label="Upload consumption CSV", file_types=[".csv", ".gz", ".tsv"])
238
+ meteorology_csv = gr.File(label="Upload meteorology CSV", file_types=[".csv", ".gz", ".tsv"])
239
 
240
  run_btn = gr.Button("Run Simulation")
241
 
data_processing.py CHANGED
@@ -4,32 +4,22 @@ import pandas as pd
4
  from scipy.interpolate import interp1d
5
 
6
 
7
- PATH_PREFIX = "./"
8
-
9
  START = f"2021-01-01"
10
  END = f"2022-01-01"
11
 
12
 
13
- def read_datasets(mini=False, old_dataset=False):
14
  # old_dataset mode is needed if we plug this into interpolate_and_join()
15
  # rather than join_consumption_meteorology().
16
 
17
- if mini:
18
- met_filename = 'PL_44527.2101.csv.gz'
19
- cons_filename = 'pq_terheles_202101_adatok.tsv'
20
- else:
21
- met_filename = 'PL_44527.19-21.csv.gz'
22
- cons_filename = 'pq_terheles_2021_adatok.tsv'
23
-
24
- #@title ### Preprocessing meteorologic data
25
- met_data = pd.read_csv(PATH_PREFIX + met_filename, compression='gzip', sep=';', skipinitialspace=True, na_values='n/a', skiprows=[0, 1, 2, 3, 4])
26
  met_data['Time'] = met_data['Time'].astype(str)
27
  date_time = met_data['Time'] = pd.to_datetime(met_data['Time'], format='%Y%m%d%H%M')
28
  met_data = met_data.set_index('Time')
29
 
30
-
31
- #@title ### Preprocessing consumption data
32
- cons_data = pd.read_csv(PATH_PREFIX + cons_filename, sep='\t', skipinitialspace=True, na_values='n/a', decimal=',')
33
  cons_data['Time'] = pd.to_datetime(cons_data['Korrigált időpont'], format='%m/%d/%y %H:%M')
34
  cons_data = cons_data.set_index('Time')
35
  cons_data['Consumption'] = cons_data['Hatásos teljesítmény [kW]']
@@ -57,8 +47,8 @@ def interpolate(df, target_idx):
57
 
58
 
59
  def join_consumption_meteorology(
60
- cons_data: pd.DataFrame,
61
  met_data: pd.DataFrame,
 
62
  target_freq: str = "5min",
63
  ) -> pd.DataFrame:
64
  interp_method = "time"
 
4
  from scipy.interpolate import interp1d
5
 
6
 
 
 
7
  START = f"2021-01-01"
8
  END = f"2022-01-01"
9
 
10
 
11
+ def read_datasets(met_filename, cons_filename, old_dataset=False):
12
  # old_dataset mode is needed if we plug this into interpolate_and_join()
13
  # rather than join_consumption_meteorology().
14
 
15
+ # Preprocessing meteorologic data
16
+ met_data = pd.read_csv(met_filename, compression='gzip', sep=';', skipinitialspace=True, na_values='n/a', skiprows=[0, 1, 2, 3, 4])
 
 
 
 
 
 
 
17
  met_data['Time'] = met_data['Time'].astype(str)
18
  date_time = met_data['Time'] = pd.to_datetime(met_data['Time'], format='%Y%m%d%H%M')
19
  met_data = met_data.set_index('Time')
20
 
21
+ # Preprocessing consumption data
22
+ cons_data = pd.read_csv(cons_filename, sep='\t', skipinitialspace=True, na_values='n/a', decimal=',')
 
23
  cons_data['Time'] = pd.to_datetime(cons_data['Korrigált időpont'], format='%m/%d/%y %H:%M')
24
  cons_data = cons_data.set_index('Time')
25
  cons_data['Consumption'] = cons_data['Hatásos teljesítmény [kW]']
 
47
 
48
 
49
  def join_consumption_meteorology(
 
50
  met_data: pd.DataFrame,
51
+ cons_data: pd.DataFrame,
52
  target_freq: str = "5min",
53
  ) -> pd.DataFrame:
54
  interp_method = "time"