From 9a587dcc4c2205153fe5f08b044e9edb23bae055 Mon Sep 17 00:00:00 2001 From: Luigi Maiorano Date: Tue, 3 Feb 2026 19:46:07 +0100 Subject: [PATCH] add ai-user filter combinations --- plots.py | 42 +++++++++++++++++++++++++++++++++++--- run_filter_combinations.py | 14 +++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/plots.py b/plots.py index 066f8b5..897ffa1 100644 --- a/plots.py +++ b/plots.py @@ -136,9 +136,45 @@ class QualtricsPlotsMixin: if master_list and set(value) == set(master_list): continue - # Use original values for display (full list) - clean_values = [str(v) for v in value] - val_str = ", ".join(clean_values) + # Special handling for Ethnicity: detect single-value ethnicity filters + # When filtering by one ethnicity (e.g., "White or Caucasian"), multiple options + # may be selected (all options containing that value). Display just the common value + # only if ALL options containing that value are selected. + if display_name.lower() == 'ethnicity' and len(value) > 1 and master_list: + # Find common individual ethnicity values across all selected options + # Each option may be comma-separated (e.g., "White or Caucasian, Hispanic or Latino") + value_sets = [ + set(v.strip() for v in opt.split(',')) + for opt in value + ] + # Intersect all sets to find common values + common_values = value_sets[0] + for vs in value_sets[1:]: + common_values = common_values.intersection(vs) + + # If exactly one common value, check if ALL options containing it are selected + if len(common_values) == 1: + common_val = common_values.pop() + # Find all options in master list that contain this common value + all_options_with_value = [ + opt for opt in master_list + if common_val in [v.strip() for v in opt.split(',')] + ] + # Only simplify if we selected ALL options containing this value + if set(value) == set(all_options_with_value): + val_str = common_val + else: + clean_values = [str(v) for v in value] + val_str = ", ".join(clean_values) + else: + # No single common value - fall back to full list + clean_values = [str(v) for v in value] + val_str = ", ".join(clean_values) + else: + # Use original values for display (full list) + clean_values = [str(v) for v in value] + val_str = ", ".join(clean_values) + # Use UPPERCASE for category name to distinguish from values parts.append(f"{display_name.upper()}: {val_str}") diff --git a/run_filter_combinations.py b/run_filter_combinations.py index ec85cc2..f05527a 100644 --- a/run_filter_combinations.py +++ b/run_filter_combinations.py @@ -130,6 +130,20 @@ def get_filter_combinations(survey: QualtricsSurvey) -> list[dict]: 'filters': {'ai_user': [ai_user]} }) + # AI user daily, more than once daily, en multiple times a week = frequent + combinations.append({ + 'name': 'AIUser-Frequent', + 'filters': {'ai_user': [ + 'Daily', 'More than once daily', 'Multiple times per week' + ]} + }) + combinations.append({ + 'name': 'AIUser-Infrequent', + 'filters': {'ai_user': [ + 'Once a month', 'Less than once a month', 'Once a week' + ]} + }) + # Investable Assets - one at a time for investable_assets in survey.options_investable_assets: combinations.append({