| """ |
| Test script to validate data layer integration with actual JSON report. |
| """ |
|
|
| from results_loader import ( |
| find_latest_full_report, |
| load_full_results, |
| summarize_users, |
| get_layer_details, |
| get_report_metadata |
| ) |
| from alert_config import ( |
| load_alert_config, |
| evaluate_alerts, |
| format_alert_summary |
| ) |
|
|
|
|
| def test_full_integration(): |
| """Test complete data layer with actual report.""" |
| |
| print("="*70) |
| print("DATA LAYER INTEGRATION TEST") |
| print("="*70) |
| |
| |
| print("\n1. Loading Report...") |
| report_path = find_latest_full_report() |
| if not report_path: |
| print("β No report found") |
| return False |
| |
| print(f" β
Found: {report_path.name}") |
| |
| results = load_full_results(report_path) |
| print(f" β
Loaded {len(results)} sections") |
| |
| |
| print("\n2. Report Metadata...") |
| metadata = get_report_metadata(report_path, results) |
| print(f" β’ File size: {metadata['file_size_mb']:.1f} MB") |
| print(f" β’ Users: {metadata['user_count']}") |
| print(f" β’ Modified: {metadata['modified_time']}") |
| |
| |
| print("\n3. User Summaries...") |
| summaries = summarize_users(results) |
| print(f" β
Processed {len(summaries)} users") |
| |
| |
| quality_bands = {'Excellent (>0.9)': 0, 'Good (0.8-0.9)': 0, |
| 'Fair (0.7-0.8)': 0, 'Poor (<0.7)': 0} |
| |
| for summary in summaries: |
| score = summary['overall_mean_score'] |
| if score: |
| if score > 0.9: |
| quality_bands['Excellent (>0.9)'] += 1 |
| elif score > 0.8: |
| quality_bands['Good (0.8-0.9)'] += 1 |
| elif score > 0.7: |
| quality_bands['Fair (0.7-0.8)'] += 1 |
| else: |
| quality_bands['Poor (<0.7)'] += 1 |
| |
| print("\n Quality Distribution:") |
| for band, count in quality_bands.items(): |
| print(f" β’ {band}: {count} users") |
| |
| |
| print("\n4. Alert Configuration...") |
| config = load_alert_config() |
| print(f" β
Loaded thresholds for {len(config)} sections") |
| |
| |
| print("\n5. Alert Evaluation...") |
| all_alerts = [] |
| |
| |
| layer1_details = get_layer_details(results, 1) |
| layer2_details = get_layer_details(results, 2) |
| layer3_details = get_layer_details(results, 3) |
| |
| combined_details = { |
| 'layer1': layer1_details, |
| 'layer2': layer2_details, |
| 'layer3': layer3_details |
| } |
| |
| for summary in summaries: |
| user_alerts = evaluate_alerts(summary, combined_details, config) |
| all_alerts.extend(user_alerts) |
| |
| print(f" β
Evaluated {len(summaries)} users") |
| print(f" β οΈ Found {len(all_alerts)} total alerts") |
| |
| |
| if all_alerts: |
| severity_counts = {'HIGH': 0, 'MEDIUM': 0, 'LOW': 0} |
| layer_counts = {'Global': 0, 'Layer 1': 0, 'Layer 2': 0, 'Layer 3': 0} |
| |
| for alert in all_alerts: |
| severity_counts[alert['severity']] += 1 |
| layer_counts[alert['layer']] += 1 |
| |
| print("\n Alert Severity:") |
| for severity, count in severity_counts.items(): |
| if count > 0: |
| print(f" β’ {severity}: {count} alerts") |
| |
| print("\n Alerts by Layer:") |
| for layer, count in layer_counts.items(): |
| if count > 0: |
| print(f" β’ {layer}: {count} alerts") |
| |
| |
| if all_alerts: |
| print("\n6. Sample Alerts (first 3)...") |
| for alert in all_alerts[:3]: |
| print(f" β’ [{alert['severity']}] {alert['user_id']}: {alert['message']}") |
| |
| print("\n" + "="*70) |
| print("β
DATA LAYER TEST COMPLETE - ALL SYSTEMS OPERATIONAL") |
| print("="*70) |
| |
| return True |
|
|
|
|
| if __name__ == "__main__": |
| success = test_full_integration() |
| exit(0 if success else 1) |
|
|