76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
import json
|
||
|
|
from collections.abc import Sequence
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from .config import DEFAULT_RANDOM_SEED, GeneratorConfig
|
||
|
|
|
||
|
|
|
||
|
|
def _parser() -> argparse.ArgumentParser:
|
||
|
|
parser = argparse.ArgumentParser(
|
||
|
|
prog="generate-beihai-shipyard-aps",
|
||
|
|
description="Generate deterministic Beihai Shipyard APS SYNTHETIC validation data.",
|
||
|
|
)
|
||
|
|
parser.add_argument("--seed", type=int, default=DEFAULT_RANDOM_SEED)
|
||
|
|
parser.add_argument(
|
||
|
|
"--scale",
|
||
|
|
choices=("small", "standard", "full"),
|
||
|
|
default="full",
|
||
|
|
)
|
||
|
|
parser.add_argument("--project-count", type=int, choices=range(1, 5))
|
||
|
|
parser.add_argument(
|
||
|
|
"--output",
|
||
|
|
type=Path,
|
||
|
|
default=Path("beihai-shipyard-aps-data"),
|
||
|
|
)
|
||
|
|
parser.add_argument(
|
||
|
|
"--scenario",
|
||
|
|
default="all",
|
||
|
|
help="Generate all scenarios or freeze one scenario selector in dataset metadata.",
|
||
|
|
)
|
||
|
|
parser.add_argument("--incremental", action="store_true")
|
||
|
|
parser.add_argument(
|
||
|
|
"--validate-only",
|
||
|
|
action="store_true",
|
||
|
|
help="Build and run independent validation without exporting a directory.",
|
||
|
|
)
|
||
|
|
return parser
|
||
|
|
|
||
|
|
|
||
|
|
def main(argv: Sequence[str] | None = None) -> int:
|
||
|
|
"""CLI entrypoint; pipeline and validation are imported only during execution."""
|
||
|
|
args = _parser().parse_args(argv)
|
||
|
|
config = GeneratorConfig.for_scale(
|
||
|
|
args.scale,
|
||
|
|
project_count=args.project_count,
|
||
|
|
seed=args.seed,
|
||
|
|
scenario=args.scenario,
|
||
|
|
incremental=args.incremental,
|
||
|
|
)
|
||
|
|
if args.validate_only:
|
||
|
|
from .pipeline import build_synthetic_dataset
|
||
|
|
from .validation import validate_bundle
|
||
|
|
|
||
|
|
bundle = build_synthetic_dataset(config, validate=False)
|
||
|
|
report = validate_bundle(bundle, config)
|
||
|
|
print(json.dumps(report, ensure_ascii=False, indent=2, sort_keys=True))
|
||
|
|
return 0 if report.get("valid") else 2
|
||
|
|
|
||
|
|
from .pipeline import generate_to_directory
|
||
|
|
|
||
|
|
manifest = generate_to_directory(config, args.output, validate=True)
|
||
|
|
summary = {
|
||
|
|
"businessDigest": manifest.get("businessDigest"),
|
||
|
|
"fileCount": manifest.get("fileCount"),
|
||
|
|
"output": str(args.output.expanduser().resolve(strict=False)),
|
||
|
|
"tableRowCounts": manifest.get("tableRowCounts", {}),
|
||
|
|
}
|
||
|
|
print(json.dumps(summary, ensure_ascii=False, indent=2, sort_keys=True))
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
raise SystemExit(main())
|