-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallbacks.py
248 lines (212 loc) · 7.17 KB
/
callbacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import json
import pandas as pd
from dash import Input, Output, State, html
from app import app
from app_components import (
create_select_demand_profile_fig,
create_selected_profile_fig,
simulation_tab_content,
)
from summaryTab import summaryTabContent
@app.callback(Output("Visible-content", "children"), Input("tabs", "active_tab"))
def switch_tab(tab):
if tab == "summary-tab":
return summaryTabContent
elif tab == "simulation-tab":
return simulation_tab_content
# Callback to make construction weight menu expand
@app.callback(
Output("construction-weight-collapse", "is_open"),
[Input("construction-weight-button", "n_clicks")],
[State("construction-weight-collapse", "is_open")],
)
def toggle_construction_weight_collapse(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open
# Callback to make demand profile menu expand
@app.callback(
Output("thermal-comfort-collapse", "is_open"),
[Input("thermal-comfort-button", "n_clicks")],
[State("thermal-comfort-collapse", "is_open")],
)
def toggle_comfort_collapse(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open
# Callback to make star rating menu expand
@app.callback(
Output("building-type-collapse", "is_open"),
[Input("building-type-button", "n_clicks")],
[State("building-type-collapse", "is_open")],
)
def toggle_star_rating_collapse(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open
# Callback to make occupancy patterns menu expand
@app.callback(
Output("occupancy-pattern-collapse", "is_open"),
[Input("occupancy-pattern-button", "n_clicks")],
[State("occupancy-pattern-collapse", "is_open")],
)
def toggle_occupancy_pattern_collapse(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open
# Callback to make tariff menu expand
@app.callback(
Output("tariff-collapse", "is_open"),
[Input("tariff-button", "n_clicks")],
[State("tariff-collapse", "is_open")],
)
def toggle_tariff_collapse(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open
# Callback to make demand profile menu expand
@app.callback(
Output("demand-profile-collapse", "is_open"),
[Input("demand-profile-button", "n_clicks")],
[State("demand-profile-collapse", "is_open")],
)
def toggle_demand_profile_collapse(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open
# Callback to make demand profile menu expand
@app.callback(
Output("PV-AC-spec-collapse", "is_open"),
[Input("PV-AC-spec-button", "n_clicks")],
[State("PV-AC-spec-collapse", "is_open")],
)
def toggle_shape_collapse(n_clicks, is_open):
if n_clicks:
return not is_open
return is_open
@app.callback(
[Output("floor-area-radio", "options"), Output("floor-area-radio", "value")],
[Input("dwelling-type-radio", "value")],
)
def floor_area_radio_item_update(dwelling_type):
options_dictionary = {
"Apartment": [
{
"label": "Small (1-bed, 50-75 m2 floor area)",
"value": "Small",
},
{"label": "Medium (3-bed, 80-105 m2 floor area)", "value": "Medium"},
{"label": "Large (3-bed, 110-130 m2 floor area)", "value": "Large"},
],
"House": [
{
"label": "Small (3-bed, 90-110 m2 floor area",
"value": "Small",
},
{"label": "Medium (4-bed, 140-160 m2 floor area)", "value": "Medium"},
{"label": "Large (5-bed, 170-300 m2 floor area)", "value": "Large"},
],
}
return options_dictionary[dwelling_type], "Small"
@app.callback(
Output("demand-selection-top-div", "children"),
[
# Input("demand-profile-availability-radio", "value"),
Input("demand-profile-collapse", "is_open"),
Input("net-demand-questions", "value"),
],
)
def update_graphs(
# availability,
is_open,
answer_cluster_question,
):
cluster_dic = {
"no-surplus": [4],
"surpluss-available": [2],
"modest-surplus": [1],
}
cluster = cluster_dic[answer_cluster_question]
if is_open == True:
df = pd.read_csv("Data/average_demand_and_clusters_for_demand_selection.csv")
df = df[df["Cluster"].isin(cluster)]
if (cluster == [1]) | (cluster == [2]):
unique_ids = df["site_ID"].unique()
unique_ids = unique_ids[:40]
df = df[df["site_ID"].isin(unique_ids)]
fig = create_select_demand_profile_fig(
df,
title="Click on the most similar net demand profile to your average hourly net demand profile",
)
return fig
elif is_open == False:
return []
@app.callback(
# [
# Output("dump-selected-div", "children"),
Output("selected-demand-div", "children"),
Output("selected-demand-div-id", "children"),
# ],
[
Input("select-demand-profile-fig", "clickData"),
Input("demand-profile-collapse", "is_open"),
],
[
State("select-demand-profile-fig", "selectedData"),
State("net-demand-questions", "value"),
# State("demand-profile-availability-radio", "value"),
],
)
def display_selected_data(
clickData,
is_open,
selectedData,
asnwer_net_demand,
):
if clickData is not None:
# if clickData["points"][0]["customdata"][0] is not None:
site_id = clickData["points"][0]["customdata"][0]
df = pd.read_csv("Data/average_demand_and_clusters_for_demand_selection.csv")
df = df[df["site_ID"] == site_id]
fig = create_selected_profile_fig(df)
if is_open == True:
return fig, site_id
elif is_open == False:
return [], site_id
# # Upload Data component
# @app.callback(
# # [
# # Output("dump-selected-div", "children"),
# # # Output("selected-demand-div", "children"),
# Output("selected-demand-div-id", "children"),
# # ],
# Input('upload-demand-data', 'filename'),
# [State("demand-profile-collapse", "is_open"),
# State("demand-profile-availability-radio", "value"),
# State('upload-demand-data', 'contents'),
# State('upload-demand-data', 'last_modified')]
# )
# def upload_data(upload_content_list,is_open, availability,upload_name,last_modified):
# if upload_content_list is not None:
# df = pd.read_csv("Data/average_demand_and_clusters_for_demand_selection.csv")
# # df = df[df["site_ID"] == site_id]
# fig = create_selected_profile_fig(df)
#
# if (is_open == True) & (availability == "available"):
# return ["Hi"],
#
# elif (is_open == False) & (availability == "available"):
# # print(file_name,content)
# return [],
@app.callback(
Output("table-test", "children"),
Input("tariff-table", "data"),
)
def update_tables(data):
"""This function return the updated tariff tables when the user edits it"""
tariff_df = pd.DataFrame.from_records(data)
tariff_df.rename(columns={"Rate-weekdays": "Tariff"}, inplace=True)
# print(tariff_df.columns)
return data
if __name__ == "__main__":
app.run_server(debug=False)