Update app.py
Browse files
app.py
CHANGED
@@ -14,13 +14,13 @@ from plotting import (
|
|
14 |
# Function to load chunked data based on date range
|
15 |
def load_timeseries_data(start_date, end_date):
|
16 |
start_date_str = pd.to_datetime(start_date).strftime('%Y-%m-%d')
|
17 |
-
end_date_str = pd.to_datetime(start_date).strftime('%Y-%m')
|
18 |
file_name = f"enel_timeseries_data_{start_date_str}_{end_date_str}.csv"
|
19 |
return pd.read_csv(file_name, index_col=0, header=[0, 1, 2], parse_dates=True)
|
20 |
|
21 |
def load_other_features_data(start_date, end_date):
|
22 |
start_date_str = pd.to_datetime(start_date).strftime('%Y-%m-%d')
|
23 |
-
end_date_str = pd.to_datetime(start_date).strftime('%Y-%m')
|
24 |
file_name = f"enel_other_features_data_{start_date_str}_{end_date_str}.csv"
|
25 |
return pd.read_csv(file_name, index_col=0, header=0, parse_dates=True)
|
26 |
|
@@ -40,7 +40,7 @@ date_range_picker = pn.widgets.DateRangePicker(
|
|
40 |
name='Date Range',
|
41 |
start=start_date,
|
42 |
end=end_date,
|
43 |
-
value=(
|
44 |
)
|
45 |
|
46 |
inverter_ids = pn.widgets.MultiSelect(
|
@@ -75,32 +75,34 @@ loading_spinner = pn.indicators.LoadingSpinner(width=50, height=50)
|
|
75 |
date_range_picker.param.value
|
76 |
)
|
77 |
def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves, date_range):
|
|
|
|
|
|
|
78 |
start_date, end_date = date_range
|
79 |
timeseries_data = load_timeseries_data(start_date, end_date)
|
80 |
other_features_data = load_other_features_data(start_date, end_date)
|
|
|
|
|
|
|
81 |
|
82 |
if not inverter_ids:
|
83 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
84 |
else:
|
85 |
# Plot IV + Power + Temperature Curves
|
86 |
if plot_power_curves and plot_temperature_curves:
|
87 |
-
print("Plotting IV + Power + Temperature Curves")
|
88 |
return create_iv_plot_with_power_and_temperature_curves(
|
89 |
timeseries_data, other_features_data, inverter_ids
|
90 |
)
|
91 |
# Plot IV + Temperature Curves
|
92 |
elif (not plot_power_curves) and plot_temperature_curves:
|
93 |
-
print("Plot IV + Temperature Curves")
|
94 |
return create_iv_plot_with_temperature_curves(
|
95 |
timeseries_data, other_features_data, inverter_ids
|
96 |
)
|
97 |
# Plot IV + Power Curves
|
98 |
elif plot_power_curves and (not plot_temperature_curves):
|
99 |
-
print("Plot IV + Power Curves")
|
100 |
return create_iv_plot_with_power_curves(timeseries_data, inverter_ids)
|
101 |
# Plot only IV Curves
|
102 |
else:
|
103 |
-
print("Plot only IV Curves")
|
104 |
return create_iv_plot(timeseries_data, inverter_ids)
|
105 |
|
106 |
|
|
|
14 |
# Function to load chunked data based on date range
|
15 |
def load_timeseries_data(start_date, end_date):
|
16 |
start_date_str = pd.to_datetime(start_date).strftime('%Y-%m-%d')
|
17 |
+
end_date_str = (pd.to_datetime(start_date) + pd.offsets.MonthEnd()).strftime('%Y-%m-%d')
|
18 |
file_name = f"enel_timeseries_data_{start_date_str}_{end_date_str}.csv"
|
19 |
return pd.read_csv(file_name, index_col=0, header=[0, 1, 2], parse_dates=True)
|
20 |
|
21 |
def load_other_features_data(start_date, end_date):
|
22 |
start_date_str = pd.to_datetime(start_date).strftime('%Y-%m-%d')
|
23 |
+
end_date_str = (pd.to_datetime(start_date) + pd.offsets.MonthEnd()).strftime('%Y-%m-%d')
|
24 |
file_name = f"enel_other_features_data_{start_date_str}_{end_date_str}.csv"
|
25 |
return pd.read_csv(file_name, index_col=0, header=0, parse_dates=True)
|
26 |
|
|
|
40 |
name='Date Range',
|
41 |
start=start_date,
|
42 |
end=end_date,
|
43 |
+
value=(None, None)
|
44 |
)
|
45 |
|
46 |
inverter_ids = pn.widgets.MultiSelect(
|
|
|
75 |
date_range_picker.param.value
|
76 |
)
|
77 |
def update_iv_plot(inverter_ids, plot_power_curves, plot_temperature_curves, date_range):
|
78 |
+
if date_range[0] is None or date_range[1] is None:
|
79 |
+
return pn.pane.Markdown("Please select a date range to load data.")
|
80 |
+
|
81 |
start_date, end_date = date_range
|
82 |
timeseries_data = load_timeseries_data(start_date, end_date)
|
83 |
other_features_data = load_other_features_data(start_date, end_date)
|
84 |
+
|
85 |
+
if timeseries_data is None or other_features_data is None:
|
86 |
+
return pn.pane.Markdown("No data available for the selected date range.")
|
87 |
|
88 |
if not inverter_ids:
|
89 |
return pn.pane.Markdown("No Inverters selected for Plotting.")
|
90 |
else:
|
91 |
# Plot IV + Power + Temperature Curves
|
92 |
if plot_power_curves and plot_temperature_curves:
|
|
|
93 |
return create_iv_plot_with_power_and_temperature_curves(
|
94 |
timeseries_data, other_features_data, inverter_ids
|
95 |
)
|
96 |
# Plot IV + Temperature Curves
|
97 |
elif (not plot_power_curves) and plot_temperature_curves:
|
|
|
98 |
return create_iv_plot_with_temperature_curves(
|
99 |
timeseries_data, other_features_data, inverter_ids
|
100 |
)
|
101 |
# Plot IV + Power Curves
|
102 |
elif plot_power_curves and (not plot_temperature_curves):
|
|
|
103 |
return create_iv_plot_with_power_curves(timeseries_data, inverter_ids)
|
104 |
# Plot only IV Curves
|
105 |
else:
|
|
|
106 |
return create_iv_plot(timeseries_data, inverter_ids)
|
107 |
|
108 |
|