Files
ocr_data/tools/stats_jsonl.py
2026-09-28 16:09:31 +08:00

74 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
统计 数据.jsonl:成功条数、总条数、成功数据总秒数、全部数据总秒数。
用法: python stats_jsonl.py [数据.jsonl路径]
默认: python stats_jsonl.py 数据.jsonl
"""
import json
import sys
from collections import Counter
JSONL_PATH = sys.argv[1] if len(sys.argv) > 1 else "数据.jsonl"
def fmt(seconds):
"""秒 → H时M分S秒,便于阅读"""
seconds = int(round(seconds))
h, rem = divmod(seconds, 3600)
m, s = divmod(rem, 60)
return f"{h}时{m}分{s}秒"
def main():
total = 0
success = 0
total_sec = 0.0
success_sec = 0.0
status_counter = Counter()
try:
f = open(JSONL_PATH, encoding="utf-8")
except FileNotFoundError:
print(f"找不到文件: {JSONL_PATH}")
return
with f:
for line in f:
line = line.strip()
if not line:
continue
try:
rec = json.loads(line)
except json.JSONDecodeError:
continue
total += 1
status = rec.get("status")
status_counter[status] += 1
dur = rec.get("duration") or 0
try:
dur = float(dur)
except (TypeError, ValueError):
dur = 0.0
total_sec += dur
if status == "success":
success += 1
success_sec += dur
rate = (success / total * 100) if total else 0.0
print(f"文件: {JSONL_PATH}")
print("-" * 40)
print(f"总条数: {total}")
print(f"成功条数: {success} ({rate:.1f}%)")
print(f"各状态明细: {dict(status_counter)}")
print("-" * 40)
print(f"成功数据秒数: {success_sec:.2f} 秒 ({fmt(success_sec)})")
print(f"全部数据秒数: {total_sec:.2f} 秒 ({fmt(total_sec)})")
if __name__ == "__main__":
main()