Spaces:
Sleeping
Sleeping
| """ | |
| Rebuild PROGRESS.md and _summary.csv from an existing plan + _tasks.csv. | |
| Useful when: | |
| - The progress tracking logic changed (e.g. empty-svg threshold) and you | |
| want to recompute the summary without re-running any tasks. | |
| - You merged tasks from multiple runs and need a fresh rollup. | |
| Usage: | |
| python scripts/rebuild_progress.py \\ | |
| --plan scripts/_full_d3_plan.json \\ | |
| --output-dir output/quality_check | |
| """ | |
| import argparse | |
| import csv | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from scripts._progress import ProgressTracker | |
| def parse_args(): | |
| p = argparse.ArgumentParser() | |
| p.add_argument("--plan", required=True) | |
| p.add_argument("--output-dir", default="output/quality_check") | |
| p.add_argument("--match-csv", default="scripts/_template_match.csv") | |
| p.add_argument("--min-data-for-skipped", type=int, default=5) | |
| return p.parse_args() | |
| def main(): | |
| args = parse_args() | |
| with open(args.plan, "r") as fh: | |
| plan = json.load(fh) | |
| out_dir = Path(args.output_dir) | |
| tasks_csv = out_dir / "_tasks.csv" | |
| if not tasks_csv.exists(): | |
| raise FileNotFoundError(f"missing {tasks_csv}") | |
| tracker = ProgressTracker( | |
| plan=plan, | |
| output_dir=out_dir, | |
| match_csv_path=Path(args.match_csv) if args.match_csv else None, | |
| min_data_for_plan=args.min_data_for_skipped, | |
| ) | |
| # We don't reopen _tasks.csv for writing because we just want to recompute | |
| # the summary / progress from already-recorded rows. Read them into memory | |
| # and let the tracker do the rollup. | |
| with open(tasks_csv, "r") as fh: | |
| for row in csv.DictReader(fh): | |
| tracker.records.append(row) | |
| tracker._completed_keys.add((row["chart_name"], row["input"])) | |
| tracker._is_closed = True # report status as 'finished' or 'stopped' instead of 'running' | |
| tracker.flush() | |
| print(f"Rebuilt {tracker.summary_csv}") | |
| print(f"Rebuilt {tracker.progress_md}") | |
| if __name__ == "__main__": | |
| main() | |