Add pathology report scraper and lymphoma data enrichment scripts
Scripts for batch-scraping pathology reports from the hospital PACS system (by inpatient + outpatient number, across pathology and bone marrow exam categories) and using the results to fill in blank fields in a lymphoma patient dataset.
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
实时查看 extract_pathology_reports.py 的抓取进度
|
||||
用法: python watch_progress.py [刷新间隔秒数,默认2]
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import sys
|
||||
|
||||
PROGRESS_FILE = r"C:\Users\senqu\Desktop\尚安迪\2026.8.25\progress.json"
|
||||
|
||||
|
||||
def fmt_time(sec):
|
||||
sec = int(sec)
|
||||
h, rem = divmod(sec, 3600)
|
||||
m, s = divmod(rem, 60)
|
||||
if h:
|
||||
return f"{h}时{m}分{s}秒"
|
||||
if m:
|
||||
return f"{m}分{s}秒"
|
||||
return f"{s}秒"
|
||||
|
||||
|
||||
def main():
|
||||
interval = float(sys.argv[1]) if len(sys.argv) > 1 else 2.0
|
||||
|
||||
while True:
|
||||
if not os.path.exists(PROGRESS_FILE):
|
||||
print("等待任务启动...(还没有 progress.json)")
|
||||
time.sleep(interval)
|
||||
continue
|
||||
|
||||
try:
|
||||
with open(PROGRESS_FILE, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
except (json.JSONDecodeError, OSError):
|
||||
time.sleep(0.5)
|
||||
continue
|
||||
|
||||
processed = data.get('processed', 0)
|
||||
total = data.get('total', 0)
|
||||
elapsed = data.get('elapsed_sec', 0)
|
||||
done = data.get('done', False)
|
||||
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
|
||||
pct = (processed / total * 100) if total else 0
|
||||
rate = processed / elapsed if elapsed > 0 else 0
|
||||
remaining = (total - processed) / rate if rate > 0 else 0
|
||||
|
||||
bar_len = 40
|
||||
filled = int(bar_len * pct / 100)
|
||||
|
||||
print("=" * 60)
|
||||
print("病理报告抓取进度")
|
||||
print("=" * 60)
|
||||
print(f"进度: {processed}/{total} ({pct:.1f}%)")
|
||||
print("[" + "#" * filled + "-" * (bar_len - filled) + "]")
|
||||
print()
|
||||
print(f"当前患者: {data.get('current_patient', '') or '(已完成)'}")
|
||||
print(f"已用时间: {fmt_time(elapsed)}")
|
||||
if not done and rate > 0:
|
||||
print(f"预计剩余: {fmt_time(remaining)} (速度: {rate:.2f}人/秒)")
|
||||
print()
|
||||
print(f"有病理报告的患者: {data.get('success', 0)}")
|
||||
print(f"无病理报告: {data.get('no_patho', 0)}")
|
||||
print(f"抓取失败: {data.get('failed', 0)}")
|
||||
print(f"病理报告总数: {data.get('report_count', 0)}")
|
||||
print(f"找到门诊号的患者: {data.get('outpatient_found', 0)}")
|
||||
print(f"门诊号额外补到的报告数: {data.get('outpatient_extra_reports', 0)}")
|
||||
print(f"可能截断(单次超20条/1页): {data.get('truncated', 0)}")
|
||||
print()
|
||||
|
||||
if done:
|
||||
print("=" * 60)
|
||||
print("任务已完成!")
|
||||
break
|
||||
|
||||
print(f"(每{interval}秒自动刷新,Ctrl+C退出)")
|
||||
time.sleep(interval)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
print("\n已停止监控。")
|
||||
Reference in New Issue
Block a user