""" File I/O utilities and output formatting for the startpakket processing script. """ import json import logging from typing import Dict, Any from process_predelib_file import print_students_with_fail_ar_summary logger = logging.getLogger(__name__) def save_results(results: Dict[str, Any], output_path: str) -> None: """Save results to a JSON file""" try: with open(output_path, 'w', encoding='utf-8') as f: json.dump(results, f, indent=2, ensure_ascii=False) logger.info(f"Results saved to: {output_path}") except Exception as e: logger.error(f"Error saving results to {output_path}: {e}") raise def print_summary(results: Dict[str, Any]) -> None: """Print a summary of the results to console""" print(f"\n{'='*60}") print("STARTPAKKET PROCESSING SUMMARY") print(f"{'='*60}") print(f"Predelib file: {results['predelib_file']}") print(f"Dashboard file: {results['dashboard_file']}") print(f"Predelib records processed: {results['predelib_records']}") print(f"Dashboard records processed: {results['dashboard_records']}") print(f"Students with FAIL adviesrapport found: {results['students_with_fail_count']}") print(f"Mismatches found: {results['mismatches_count']}") if results['students_with_fail_count'] > 0: print_students_with_fail_ar_summary(results['students_with_fail'], results['predelib_file']) if results['mismatches']: print(f"\nDetailed mismatches between SP predeliberatierapport and Dashboard Inschrijvingen:") for mismatch in results['mismatches']: print(f"Mismatch - ID {mismatch['ID']} ({mismatch['Name']}): " f"Predeliberatierapport SP={mismatch['Predelib_SP']}, " f"Dashboard Inschrijvingen SP={mismatch['Dashboard_SP']}") else: print("\n✅ All SP values match perfectly!") print(f"Status: {results['status']}") print(f"{'='*60}")