File size: 2,074 Bytes
58e6885
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
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()