From e5851412142da5b18b70f22eeec4204eecf856de Mon Sep 17 00:00:00 2001 From: Mika Date: Thu, 11 Dec 2025 11:56:25 +0000 Subject: [PATCH] Add off_by_3_fix/src/off_by_3_fix/cli.py --- off_by_3_fix/src/off_by_3_fix/cli.py | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 off_by_3_fix/src/off_by_3_fix/cli.py diff --git a/off_by_3_fix/src/off_by_3_fix/cli.py b/off_by_3_fix/src/off_by_3_fix/cli.py new file mode 100644 index 0000000..f61efb4 --- /dev/null +++ b/off_by_3_fix/src/off_by_3_fix/cli.py @@ -0,0 +1,36 @@ +import argparse +import json +from pathlib import Path +from off_by_3_fix.core import fix_off_by_3 + + +def main(): + """Command-line interface for applying the Off-By-3 fix to JSON trace data files.""" + parser = argparse.ArgumentParser(description="Apply Off-By-3 integer bucket fix to trace data.") + parser.add_argument("--input", required=True, help="Path to input JSON file with trace data.") + parser.add_argument("--output", required=True, help="Path to output JSON file for corrected data.") + + args = parser.parse_args() + + input_path = Path(args.input) + output_path = Path(args.output) + + # Validate input path + if not input_path.exists(): + raise FileNotFoundError(f"Input file not found: {input_path}") + + # Load trace data from JSON + with input_path.open("r", encoding="utf-8") as f: + trace_data = json.load(f) + + # Apply the off-by-3 fix + corrected_data = fix_off_by_3(trace_data) + + # Write corrected data to output JSON + output_path.parent.mkdir(parents=True, exist_ok=True) + with output_path.open("w", encoding="utf-8") as f: + json.dump(corrected_data, f, indent=2) + + +if __name__ == "__main__": + main() \ No newline at end of file