saving plots to subdirectories grouped by filter

This commit is contained in:
2026-01-28 15:58:38 +01:00
parent 365e70b834
commit 62e75fe899
3 changed files with 88 additions and 29 deletions

View File

@@ -39,7 +39,6 @@ def _():
def _(JPMCSurvey, QSF_FILE, RESULTS_FILE):
S = JPMCSurvey(RESULTS_FILE, QSF_FILE)
data_all = S.load_data()
data_all.collect()
return S, data_all
@@ -96,22 +95,9 @@ def _(mo):
@app.cell(hide_code=True)
def _(data_all, mo):
data_all_collected = data_all.collect()
age = mo.ui.multiselect(options=data_all_collected["QID1"], value=data_all_collected["QID1"].unique(), label="Select Age Group(s):")
income = mo.ui.multiselect(data_all_collected["QID15"], value=data_all_collected["QID15"], label="Select Income Group(s):")
gender = mo.ui.multiselect(data_all_collected["QID2"], value=data_all_collected["QID2"], label="Select Gender(s)")
ethnicity = mo.ui.multiselect(data_all_collected["QID3"], value=data_all_collected["QID3"], label="Select Ethnicities:")
consumer = mo.ui.multiselect(data_all_collected["Consumer"], value=data_all_collected["Consumer"], label="Select Consumer Groups:")
return age, consumer, ethnicity, gender, income
@app.cell
def _(age, consumer, ethnicity, gender, income, mo):
mo.md(f"""
# Data Filters
def _(S, mo):
filter_form = mo.md('''
# Data Filter
{age}
@@ -122,16 +108,26 @@ def _(age, consumer, ethnicity, gender, income, mo):
{income}
{consumer}
""")
return
'''
).batch(
age=mo.ui.multiselect(options=S.options_age, value=S.options_age, label="Select Age Group(s):"),
gender=mo.ui.multiselect(options=S.options_gender, value=S.options_gender, label="Select Gender(s):"),
ethnicity=mo.ui.multiselect(options=S.options_ethnicity, value=S.options_ethnicity, label="Select Ethnicities:"),
income=mo.ui.multiselect(options=S.options_income, value=S.options_income, label="Select Income Group(s):"),
consumer=mo.ui.multiselect(options=S.options_consumer, value=S.options_consumer, label="Select Consumer Groups:")
).form()
filter_form
return (filter_form,)
@app.cell
def _(S, age, consumer, data_all, ethnicity, gender, income):
data = S.filter_data(data_all, age=age.value, gender=gender.value, income=income.value, ethnicity=ethnicity.value, consumer=consumer.value)
def _(S, data_all, filter_form, mo):
_d = S.filter_data(data_all, age=filter_form.value['age'], gender=filter_form.value['gender'], income=filter_form.value['income'], ethnicity=filter_form.value['ethnicity'], consumer=filter_form.value['consumer'])
# Stop execution and prevent other cells from running if no data is selected
mo.stop(len(_d.collect()) == 0, mo.md("**No Data available for current filter combination**"))
data = _d
data.collect()
return (data,)