fixed consumer and ethnicity filter combinations

This commit is contained in:
2026-02-03 14:43:03 +01:00
parent 8dd41dfc96
commit e44251c3d6
2 changed files with 34 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ cli_args = parse_cli_args()
# mo.stop(file_browser.path(index=0) is None, mo.md("**⚠️ Please select a `_Labels.csv` file above to proceed**")) # mo.stop(file_browser.path(index=0) is None, mo.md("**⚠️ Please select a `_Labels.csv` file above to proceed**"))
# RESULTS_FILE = Path(file_browser.path(index=0)) # RESULTS_FILE = Path(file_browser.path(index=0))
RESULTS_FILE = 'data/exports/2-2-26/JPMC_Chase Brand Personality_Quant Round 1_February 2, 2026_Labels.csv' RESULTS_FILE = 'data/exports/2-3-26_Copy-2-2-26/JPMC_Chase Brand Personality_Quant Round 1_February 2, 2026_Labels.csv'
QSF_FILE = 'data/exports/OneDrive_2026-01-21/Soft Launch Data/JPMC_Chase_Brand_Personality_Quant_Round_1.qsf' QSF_FILE = 'data/exports/OneDrive_2026-01-21/Soft Launch Data/JPMC_Chase_Brand_Personality_Quant_Round_1.qsf'
# %% # %%

View File

@@ -60,11 +60,24 @@ def get_filter_combinations(survey: QualtricsSurvey) -> list[dict]:
'filters': {'gender': [gender]} 'filters': {'gender': [gender]}
}) })
# Ethnicity - one at a time # Ethnicity - grouped by individual values
for ethnicity in survey.options_ethnicity: # Ethnicity options are comma-separated (e.g., "White or Caucasian, Hispanic or Latino")
# Create filters that include ALL options containing each individual ethnicity value
ethnicity_values = set()
for ethnicity_option in survey.options_ethnicity:
# Split by comma and strip whitespace
values = [v.strip() for v in ethnicity_option.split(',')]
ethnicity_values.update(values)
for ethnicity_value in sorted(ethnicity_values):
# Find all options that contain this value
matching_options = [
opt for opt in survey.options_ethnicity
if ethnicity_value in [v.strip() for v in opt.split(',')]
]
combinations.append({ combinations.append({
'name': f'Ethnicity-{ethnicity}', 'name': f'Ethnicity-{ethnicity_value}',
'filters': {'ethnicity': [ethnicity]} 'filters': {'ethnicity': matching_options}
}) })
# Income - one at a time # Income - one at a time
@@ -74,11 +87,24 @@ def get_filter_combinations(survey: QualtricsSurvey) -> list[dict]:
'filters': {'income': [income]} 'filters': {'income': [income]}
}) })
# Consumer segments - one at a time # Consumer segments - combine _A and _B options
# Group options by base name (removing _A/_B suffix)
consumer_groups = {}
for consumer in survey.options_consumer: for consumer in survey.options_consumer:
# Check if ends with _A or _B
if consumer.endswith('_A') or consumer.endswith('_B'):
base_name = consumer[:-2] # Remove last 2 chars (_A or _B)
if base_name not in consumer_groups:
consumer_groups[base_name] = []
consumer_groups[base_name].append(consumer)
else:
# Not an _A/_B option, keep as-is
consumer_groups[consumer] = [consumer]
for base_name, options in consumer_groups.items():
combinations.append({ combinations.append({
'name': f'Consumer-{consumer}', 'name': f'Consumer-{base_name}',
'filters': {'consumer': [consumer]} 'filters': {'consumer': options}
}) })
return combinations return combinations