#!/usr/bin/env python3 """ Analyze Schema v4 Metrics Coverage from JSON Report """ import json import sys from pathlib import Path def analyze_coverage(json_path: str): """Analyze advanced metrics coverage from JSON report""" with open(json_path, 'r', encoding='utf-8') as f: data = json.load(f) stocks = data.get('stocks', []) total = len(stocks) if total == 0: print("āŒ No stocks found in JSON") return # Count metrics roic_count = 0 interest_cov_count = 0 fscore_count = 0 missing_roic = [] missing_int_cov = [] missing_fscore = [] for stock in stocks: ticker = stock['ticker'] fundamentals = stock.get('fundamental_data', {}) advanced = fundamentals.get('advanced_quality_metrics', {}) # ROIC if advanced.get('roic_percent') is not None: roic_count += 1 else: missing_roic.append(ticker) # Interest Coverage if advanced.get('interest_coverage_ratio') is not None: interest_cov_count += 1 else: missing_int_cov.append(ticker) # F-Score if advanced.get('piotroski_fscore') is not None: fscore_count += 1 else: missing_fscore.append(ticker) # Print results print("=" * 80) print(f"SCHEMA v4 METRICS COVERAGE ANALYSIS") market_name = data.get('metadata', {}).get('market', 'Unknown') print(f"Market: {market_name}") print(f"Total Stocks: {total}") print("=" * 80) print(f"\nšŸ“Š ROIC Coverage: {roic_count}/{total} ({roic_count/total*100:.1f}%)") if missing_roic: print(f" Missing ({len(missing_roic)}): {', '.join(missing_roic)}") print(f"\nšŸ“Š Interest Coverage: {interest_cov_count}/{total} ({interest_cov_count/total*100:.1f}%)") if missing_int_cov: print(f" Missing ({len(missing_int_cov)}): {', '.join(missing_int_cov)}") print(f"\nšŸ“Š Piotroski F-Score: {fscore_count}/{total} ({fscore_count/total*100:.1f}%)") if missing_fscore: print(f" Missing ({len(missing_fscore)}): {', '.join(missing_fscore)}") # Summary print("\n" + "=" * 80) print("SUMMARY") print("=" * 80) roic_pct = roic_count/total*100 int_cov_pct = interest_cov_count/total*100 fscore_pct = fscore_count/total*100 roic_status = "āœ…" if roic_pct >= 90 else "āš ļø " if roic_pct >= 80 else "āŒ" int_cov_status = "āœ…" if int_cov_pct >= 85 else "āš ļø " if int_cov_pct >= 75 else "āŒ" fscore_status = "āœ…" if fscore_pct >= 90 else "āš ļø " if fscore_pct >= 80 else "āŒ" print(f"{roic_status} ROIC: {roic_pct:.1f}% (Target: ≄90%)") print(f"{int_cov_status} Interest Coverage: {int_cov_pct:.1f}% (Target: ≄85%)") print(f"{fscore_status} F-Score: {fscore_pct:.1f}% (Target: ≄90%)") all_pass = roic_pct >= 90 and int_cov_pct >= 85 and fscore_pct >= 90 print("\n" + "=" * 80) if all_pass: print("āœ… ALL TARGETS ACHIEVED!") else: print("āš ļø Some targets not yet achieved") print("=" * 80) if __name__ == "__main__": json_file = "reports/latest/warren_scan_IT_latest.json" if len(sys.argv) > 1: json_file = sys.argv[1] if not Path(json_file).exists(): print(f"āŒ File not found: {json_file}") sys.exit(1) analyze_coverage(json_file)