#!/usr/bin/env python3 """ Compute comprehensive dataset statistics for UnsolvedAstronomy v1.1.0 and write statistics.json. """ import json from collections import Counter from pathlib import Path ROOT = Path(__file__).resolve().parent.parent PROBLEMS_FILE = ROOT / "problems.json" ARCHIVED_FILE = ROOT / "archived_problems.json" RELATIONS_FILE = ROOT / "relations.jsonl" SOURCES_FILE = ROOT / "source_registry.json" STATS_ROOT = ROOT / "statistics.json" def load_jsonl(path: Path) -> list[dict]: if not path.exists(): return [] return [json.loads(line) for line in path.open("r", encoding="utf-8") if line.strip()] def load_json_array(path: Path) -> list[dict]: if not path.exists(): return [] return json.loads(path.read_text(encoding="utf-8")) def compute_stats() -> dict: published = load_json_array(PROBLEMS_FILE) archived = load_json_array(ARCHIVED_FILE) all_problems = published + archived sources = load_json_array(SOURCES_FILE) relations = load_jsonl(RELATIONS_FILE) gold = [p for p in published if p.get("is_gold_seed")] cat_counts = Counter() gold_cat_counts = Counter() subcat_counts = Counter() qtype_counts = Counter() status_counts = Counter(p["status"] for p in all_problems) pub_status_counts = Counter(p["status"] for p in published) ev_counts = Counter(p["evidence_state"] for p in published) cons_counts = Counter(p["consensus_state"] for p in published) vmode_counts = Counter(p["verification_mode"] for p in published) vhor_counts = Counter(p["verification_horizon"] for p in published) diff_counts = Counter(p["difficulty_level"] for p in published) obj_counts = Counter() scale_counts = Counter() wave_counts = Counter() source_usage = Counter() cross_domain_counts = Counter() for p in published: key = f"{p['category_number']:02d}_{p['category']}" cat_counts[key] += 1 if p.get("is_gold_seed"): gold_cat_counts[key] += 1 subcat_counts[p["subcategory"]] += 1 qtype_counts[p["question_type"]] += 1 for o in p.get("object_classes", []): obj_counts[o] += 1 for sc in p.get("scales", []): scale_counts[sc] += 1 for w in p.get("wavelengths_and_messengers", []): wave_counts[w] += 1 if p.get("sources"): source_usage[p["sources"][0]["source_id"]] += 1 for cd in p.get("cross_domain_links", []): cross_domain_counts[cd["dataset"]] += 1 max_src_id, max_src_cnt = source_usage.most_common(1)[0] if source_usage else ("NONE", 0) src_len_counts = Counter(len({s["source_id"] for s in p.get("sources", [])}) for p in published) total_src_links = sum(len({s["source_id"] for s in p.get("sources", [])}) for p in published) unique_titles = len({(p.get("title") or "").strip().lower() for p in published}) stats = { "dataset_name": "UnsolvedAstronomy", "version": "1.1.0", "release_date": "2026-10-16", "total_records_all_statuses": len(all_problems), "published_problems_count": len(published), "unique_titles_published_count": unique_titles, "gold_seed_problems_count": len(gold), "archived_and_excluded_count": len(archived), "distinct_sources_count": len(sources), "relations_count": len(relations), "min_sources_per_published_problem": min(src_len_counts.keys()) if src_len_counts else 0, "max_sources_per_published_problem": max(src_len_counts.keys()) if src_len_counts else 0, "average_sources_per_published_problem": round(total_src_links / max(1, len(published)), 3), "sources_count_distribution_published": dict(sorted(src_len_counts.items())), "max_single_source_id": max_src_id, "max_single_source_published_count": max_src_cnt, "max_single_source_share_percent": round(100.0 * max_src_cnt / max(1, len(published)), 3), "status_distribution_all": dict(status_counts), "status_distribution_published": dict(pub_status_counts), "category_distribution_published": dict(sorted(cat_counts.items())), "gold_seed_category_distribution": dict(sorted(gold_cat_counts.items())), "subcategory_distribution_published": dict(sorted(subcat_counts.items())), "question_type_distribution": dict(qtype_counts.most_common()), "evidence_state_distribution": dict(ev_counts.most_common()), "consensus_state_distribution": dict(cons_counts.most_common()), "object_class_distribution": dict(obj_counts.most_common()), "scale_distribution": dict(scale_counts.most_common()), "wavelength_and_messenger_distribution": dict(wave_counts.most_common()), "verification_mode_distribution": dict(vmode_counts.most_common()), "verification_horizon_distribution": dict(vhor_counts.most_common()), "difficulty_level_distribution": dict(sorted(diff_counts.items())), "source_tier_distribution": dict(Counter(s.get("tier") for s in sources)), "source_type_distribution": dict(Counter(s.get("source_type") for s in sources)), "cross_domain_links_distribution": dict(cross_domain_counts), } STATS_ROOT.write_text(json.dumps(stats, indent=2) + "\n", encoding="utf-8") print(f"Wrote statistics to {STATS_ROOT}") return stats if __name__ == "__main__": compute_stats()