Add off_by_3_fix/src/off_by_3_fix/cli.py

This commit is contained in:
Mika 2025-12-11 11:56:25 +00:00
parent 8b1fcca4c9
commit e585141214

View file

@ -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()