File size: 1,927 Bytes
2b86c60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Run the offline retail study. Downloads occur only with --download-uci.

Example: python scripts/study_retail.py --input data/online_retail_II.xlsx
CSV input avoids the optional openpyxl dependency. All output is local study data.
"""
from pathlib import Path
import argparse
import json
import sys
import time

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from backend.flagship.ml import download_uci, run_retail_study
from study_evidence import write_evidence


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--input", type=Path)
    parser.add_argument("--output", type=Path, default=Path(".local/studies/retail"))
    parser.add_argument("--max-items", type=int, default=50)
    parser.add_argument("--evidence-output", type=Path, help="Write measured runtime, source hashes, and complete results")
    parser.add_argument("--download-uci", action="store_true", help="Explicitly download UCI's 43.5 MB archive")
    args = parser.parse_args()
    if args.download_uci:
        path = download_uci(args.output / "online_retail_II.xlsx")
        kind = "public_dataset"
    elif args.input:
        path, kind = args.input, "user_input"
    else:
        parser.error("Provide --input, or explicitly opt in to --download-uci")
    started = time.perf_counter()
    result = run_retail_study(path, args.output, max_items=args.max_items, source_kind=kind)
    elapsed = time.perf_counter() - started
    if args.evidence_output:
        write_evidence(args.evidence_output, study="retail", result=result,
                       elapsed_seconds=elapsed, input_path=path)
    print(json.dumps(result, indent=2, allow_nan=False))
    # A negative quality-gate result remains a completed, reproducible experiment.
    return 0 if result["status"] in {"EVALUATED", "REJECTED"} else 1


if __name__ == "__main__":
    raise SystemExit(main())