fixed consumer and ethnicity filter combinations
This commit is contained in:
@@ -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**"))
|
||||
# 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'
|
||||
|
||||
# %%
|
||||
|
||||
@@ -60,11 +60,24 @@ def get_filter_combinations(survey: QualtricsSurvey) -> list[dict]:
|
||||
'filters': {'gender': [gender]}
|
||||
})
|
||||
|
||||
# Ethnicity - one at a time
|
||||
for ethnicity in survey.options_ethnicity:
|
||||
# Ethnicity - grouped by individual values
|
||||
# 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({
|
||||
'name': f'Ethnicity-{ethnicity}',
|
||||
'filters': {'ethnicity': [ethnicity]}
|
||||
'name': f'Ethnicity-{ethnicity_value}',
|
||||
'filters': {'ethnicity': matching_options}
|
||||
})
|
||||
|
||||
# Income - one at a time
|
||||
@@ -74,11 +87,24 @@ def get_filter_combinations(survey: QualtricsSurvey) -> list[dict]:
|
||||
'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:
|
||||
# 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({
|
||||
'name': f'Consumer-{consumer}',
|
||||
'filters': {'consumer': [consumer]}
|
||||
'name': f'Consumer-{base_name}',
|
||||
'filters': {'consumer': options}
|
||||
})
|
||||
|
||||
return combinations
|
||||
|
||||
Reference in New Issue
Block a user