add ai-user filter combinations

This commit is contained in:
2026-02-03 19:46:07 +01:00
parent 9a49d1c690
commit 9a587dcc4c
2 changed files with 53 additions and 3 deletions

View File

@@ -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}")