feat: round output JSON floats to 2dp + unify ensure_ascii for asr/asrx
This commit is contained in:
@@ -87,10 +87,21 @@ def _cleanup(tmp_dir):
|
||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||
|
||||
|
||||
def round_json_numbers(obj):
|
||||
"""Recursively round all float values to 2 decimal places (JSON output only)."""
|
||||
if isinstance(obj, float):
|
||||
return round(obj, 2)
|
||||
if isinstance(obj, dict):
|
||||
return {k: round_json_numbers(v) for k, v in obj.items()}
|
||||
if isinstance(obj, list):
|
||||
return [round_json_numbers(v) for v in obj]
|
||||
return obj
|
||||
|
||||
|
||||
def _atomic_write(path: str, data: dict):
|
||||
tmp = path + ".tmp"
|
||||
with open(tmp, "w") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
json.dump(round_json_numbers(data), f, indent=2, ensure_ascii=False)
|
||||
os.rename(tmp, path)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user