Add spike_classifier/src/spike_classifier/cli.py
This commit is contained in:
parent
272302699a
commit
6d3e66951d
1 changed files with 47 additions and 0 deletions
47
spike_classifier/src/spike_classifier/cli.py
Normal file
47
spike_classifier/src/spike_classifier/cli.py
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from spike_classifier.core import classify_spikes
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""Command-line interface for classifying CPU spike events."""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Classify CPU spike events based on reorder metrics and CPU transitions."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--input",
|
||||||
|
required=True,
|
||||||
|
help="Path to input JSON file containing spike events."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=True,
|
||||||
|
help="Path to output JSON file for classified spikes."
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
output_path = Path(args.output)
|
||||||
|
|
||||||
|
if not input_path.exists() or not input_path.is_file():
|
||||||
|
parser.error(f"Input file not found: {input_path}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with input_path.open('r', encoding='utf-8') as infile:
|
||||||
|
json_data = json.load(infile)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
parser.error(f"Invalid JSON in input file: {e}")
|
||||||
|
|
||||||
|
classified = classify_spikes(json_data)
|
||||||
|
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with output_path.open('w', encoding='utf-8') as outfile:
|
||||||
|
json.dump(classified, outfile, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
print(f"Classified {len(classified)} spikes written to {output_path}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue