Skip to content

Commit 2d089f9

Browse files
committed
Make data generation method filter work
1 parent b977b55 commit 2d089f9

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

dashboard/main.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def construct_tabs(tab_list):
9494

9595
multi_choice = pn.widgets.MultiChoice(name="Filter by research field", value=["All"], options=FILTER_OPTIONS)#,
9696
#description="Select which data subset to be displayed.")
97-
multi_choice_method = pn.widgets.MultiChoice(name="Filter by data generation method", value=["All"], options=FILTER_OPTIONS_METHOD)
97+
multi_choice_method = pn.widgets.MultiChoice(name="Filter by data generation method", value=[], options=FILTER_OPTIONS_METHOD)
9898

9999

100100
# D: better than a Select would be to use the HMC template for this...
@@ -136,11 +136,19 @@ def select_data():#question_select=question_select, multi_choice=multi_choice):
136136

137137
data_filters = multi_choice.value
138138
data_filters_method = multi_choice_method.value
139-
# need something like [index: index_name, full question: '', title; '', 'key order' : [], 'skipped keys':[]]
139+
method_include = []
140+
method_exclude = []
141+
methods_dict = HCS_MCsubquestions['dataGenMethod_']
142+
for method in data_filters_method:
143+
for key, val in methods_dict.items():
144+
if val == method:
145+
method_include.append(key)
146+
# Filter out the one who provided False
147+
method_exclude.append((key, [False]))
140148

141149
# for now this is greedy, if to slow think of another way
142150
# we want to display anything in terms of researchArea, todo better was to d filter, generalize this
143-
df = filter_dataframe(survey_data, include=[q_index, "researchArea"], exclude=[(q_index, to_exclude)])
151+
df = filter_dataframe(survey_data, include=[q_index, "researchArea"]+ method_include, exclude=[(q_index, to_exclude)]+method_exclude)
144152
#df = filter_dataframe(df, include=[q_index, "researchArea"], exclude=[(q_index, to_exclude)])
145153
data_all = get_all_values(df, q_index)
146154

@@ -187,10 +195,27 @@ def select_data_corr():#question_select2=question_select2, question_select3=ques
187195

188196
data_filters = multi_choice.value
189197
data_filters_method = multi_choice_method.value
198+
199+
method_include = []
200+
method_exclude = []
201+
methods_dict = HCS_MCsubquestions['dataGenMethod_']
202+
for method in data_filters_method:
203+
for key, val in methods_dict.items():
204+
if val == method:
205+
method_include.append(key)
206+
# Filter out the one who provided False
207+
method_exclude.append((key, [False]))
208+
209+
exclude_area = []
210+
for field in re:
211+
if field not in data_filters:
212+
pass
213+
#exclude_area.append(("researchArea", [field]))
214+
#exclude_areas = ["researchArea", exclude_area]
190215

191216
# If this is slow to calculate each time, it might make sense to calculate all of these
192217
# at start up. i.e n^2 tables
193-
df = filter_dataframe(survey_data, include=[q1_key, q2_key, "researchArea"], exclude=[])
218+
df = filter_dataframe(survey_data, include=[q1_key, q2_key, "researchArea"] + method_include, exclude=[]+method_exclude+exclude_area)
194219

195220
cross_tab = calculate_crosstab(df, q1_key, q2_key)
196221
# marker size is radius, we want the Area to be proportional to the value
@@ -327,6 +352,6 @@ def generate_corr_controls():
327352
row2 = pn.Row(tabs)
328353
row3 = pn.Column(inputs_corr, pn.Row(fig_corr, leg_corr))
329354
row4 = pn.Row(button_bar)
330-
layout = pn.Column(row1, md_text_barchart, row2, md_text_corrchart, row3, md_text_button, row4, sizing_mode="scale_both")
355+
layout = pn.Column(row1, md_text_barchart, row2, md_text_corrchart, row3, md_text_button, row4, sizing_mode="scale_both", title='HMC Survey Dashboard')
331356

332-
layout.servable()
357+
layout.servable(title='HMC Survey Dashboard')

0 commit comments

Comments
 (0)