Download utils/test_data_layer.py from pamoai/dqa: direct link, hf CLI and curl.
- Browser
- Download file 4.08 kB
-
https://huggingface.co/spaces/pamoai/dqa/resolve/main/utils/test_data_layer.py
- Command line
-
hf download hf://spaces/pamoai/dqa/utils/test_data_layer.py
-
curl -L -o test_data_layer.py https://huggingface.co/spaces/pamoai/dqa/resolve/main/utils/test_data_layer.py
4.08 kB
| """ | |
| 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) | |
| # Step 1: Find and load report | |
| 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") | |
| # Step 2: Get metadata | |
| 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']}") | |
| # Step 3: Summarize users | |
| print("\n3. User Summaries...") | |
| summaries = summarize_users(results) | |
| print(f" β Processed {len(summaries)} users") | |
| # Show quality distribution | |
| 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") | |
| # Step 4: Load alert config | |
| print("\n4. Alert Configuration...") | |
| config = load_alert_config() | |
| print(f" β Loaded thresholds for {len(config)} sections") | |
| # Step 5: Evaluate alerts for all users | |
| print("\n5. Alert Evaluation...") | |
| all_alerts = [] | |
| # Get layer details once | |
| 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") | |
| # Show alert breakdown | |
| 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") | |
| # Step 6: Sample alert output | |
| 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) | |