SL filter

This commit is contained in:
2026-02-09 17:57:04 +01:00
parent 6c16993cb3
commit 8e181e193a
4 changed files with 62 additions and 5 deletions

View File

@@ -182,7 +182,7 @@ def get_filter_combinations(survey: QualtricsSurvey, category: str = None) -> li
return combinations
def run_report(filters: dict, name: str = None, dry_run: bool = False) -> bool:
def run_report(filters: dict, name: str = None, dry_run: bool = False, sl_threshold: int = None) -> bool:
"""
Run the report script with given filters.
@@ -190,6 +190,7 @@ def run_report(filters: dict, name: str = None, dry_run: bool = False) -> bool:
filters: Dict of filter_name -> list of values
name: Name for this filter combination (used for .txt description file)
dry_run: If True, just print command without running
sl_threshold: If set, exclude respondents with >= N straight-lined question groups
Returns:
True if successful, False otherwise
@@ -200,6 +201,10 @@ def run_report(filters: dict, name: str = None, dry_run: bool = False) -> bool:
if name:
cmd.extend(['--filter-name', name])
# Pass straight-liner threshold if specified
if sl_threshold is not None:
cmd.extend(['--sl-threshold', str(sl_threshold)])
for filter_name, values in filters.items():
if values:
cmd.extend([f'--{filter_name}', json.dumps(values)])
@@ -234,6 +239,7 @@ def main():
default='all_filters',
help='Filter category to run combinations for (default: all_filters)'
)
parser.add_argument('--sl-threshold', type=int, default=None, help='Exclude respondents who straight-lined >= N question groups (passed to report script)')
args = parser.parse_args()
# Load survey to get available filter options
@@ -246,11 +252,14 @@ def main():
category_desc = f" for category '{args.category}'" if args.category != 'all' else ''
print(f"Generated {len(combinations)} filter combinations{category_desc}")
if args.sl_threshold is not None:
print(f"Straight-liner threshold: excluding respondents with ≥{args.sl_threshold} straight-lined question groups")
if args.dry_run:
print("\nDRY RUN - Commands that would be executed:")
for combo in combinations:
print(f"\n{combo['name']}:")
run_report(combo['filters'], name=combo['name'], dry_run=True)
run_report(combo['filters'], name=combo['name'], dry_run=True, sl_threshold=args.sl_threshold)
return
# Run each combination with progress bar
@@ -259,7 +268,7 @@ def main():
for combo in tqdm(combinations, desc="Running reports", unit="filter"):
tqdm.write(f"Running: {combo['name']}")
if run_report(combo['filters'], name=combo['name']):
if run_report(combo['filters'], name=combo['name'], sl_threshold=args.sl_threshold):
successful += 1
else:
failed.append(combo['name'])