- Removed trailing whitespace and ensured files end with a single newline in cleanup_unused_files.py. - Added fix_trailing_whitespace.py to batch remove trailing whitespace from Python files. - Updated install_dependencies.py to improve dependency installation prompts. - Cleaned up pick_coords.py by removing unnecessary whitespace and improving code readability. - Enhanced region_selector.py by disabling specific pylint checks for better compatibility with third-party libraries. - Improved WPS流程图生成工具.py by cleaning up whitespace and enhancing readability. - Updated __init__.py in typings to remove unnecessary lines. - Modified app.js to adjust default configuration values and clean up unused code.
92 lines
2.8 KiB
Python
92 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
测试OCR时停止后台截图服务的优化效果
|
||
"""
|
||
|
||
import time
|
||
import sys
|
||
import os
|
||
|
||
# 添加项目根目录到路径
|
||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
|
||
def test_screenshot_service_ocr_integration():
|
||
"""测试截图服务与OCR集成的优化"""
|
||
print("=" * 80)
|
||
print("测试OCR时停止后台截图服务的优化")
|
||
print("=" * 80)
|
||
|
||
# 1. 启动截图服务
|
||
print("\n1. 启动后台截图服务...")
|
||
from operations.screenshot_service import ScreenshotService
|
||
service = ScreenshotService.get_instance()
|
||
|
||
# 模拟设备ID(实际测试时需要替换为真实设备ID)
|
||
device_id = "emulator-5554"
|
||
|
||
if service.is_running():
|
||
print("服务已在运行")
|
||
else:
|
||
service.start(device_id, interval=1.5)
|
||
time.sleep(0.5) # 等待服务启动
|
||
|
||
if service.is_running():
|
||
print("[OK] 后台截图服务启动成功")
|
||
else:
|
||
print("[FAIL] 后台截图服务启动失败")
|
||
return
|
||
|
||
# 2. 模拟OCR密集操作
|
||
print("\n2. 模拟OCR密集操作(调用read_fudai_detail_once)...")
|
||
|
||
# 创建一个模拟的analyser对象
|
||
class MockAnalyser:
|
||
def __init__(self):
|
||
self.device_id = device_id
|
||
self._fudai_detail_task_count_from_stage = 2
|
||
|
||
def _log_kv(self, key, value, **kwargs):
|
||
timestamp = time.strftime("%H:%M:%S", time.localtime())
|
||
print(f"[{timestamp}] [{key}] {value}")
|
||
|
||
analyser = MockAnalyser()
|
||
|
||
# 调用read_fudai_detail_once,这应该会停止后台服务
|
||
start_time = time.time()
|
||
try:
|
||
from fudai_detail_modules.fudai_detail_reader import read_fudai_detail_once
|
||
result = read_fudai_detail_once(analyser)
|
||
elapsed = time.time() - start_time
|
||
print(".2f")
|
||
print(f" 返回状态: {result[0]}")
|
||
except Exception as e:
|
||
elapsed = time.time() - start_time
|
||
print(".2f")
|
||
print(f" 错误: {e}")
|
||
|
||
# 3. 检查服务是否重新启动
|
||
print("\n3. 检查后台截图服务是否重新启动...")
|
||
time.sleep(0.5) # 等待服务重新启动
|
||
|
||
if service.is_running():
|
||
print("[OK] 后台截图服务已自动重新启动")
|
||
info = service.get_cache_info()
|
||
print(f" 设备ID: {info['device_id']}")
|
||
print(f" 截图间隔: {info['interval']}秒")
|
||
print(f" 缓存有效期: {info['cache_valid_duration']}秒")
|
||
else:
|
||
print("[FAIL] 后台截图服务未重新启动")
|
||
|
||
# 4. 清理
|
||
if service.is_running():
|
||
service.stop()
|
||
print("\n4. 测试完成,停止后台截图服务")
|
||
|
||
print("\n" + "=" * 80)
|
||
print("测试完成")
|
||
print("=" * 80)
|
||
|
||
if __name__ == "__main__":
|
||
test_screenshot_service_ocr_integration()
|