Refactor and clean up code across multiple scripts

- 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.
This commit is contained in:
Your Name committed 2026-01-02 23:57:03 +08:00
1 parent 9131c48633
commit 0b5f150691
149 files changed
+2437 -4913

No files matched your search

+36 -45
View File
@@ -29,26 +29,26 @@ def analyze_latest_log():
if not os.path.exists(log_dir):
print("日志目录不存在")
return None
# 查找最新的 unified_*.log 文件
log_files = [f for f in os.listdir(log_dir) if f.startswith('unified_') and f.endswith('.log')]
if not log_files:
print("未找到日志文件")
return None
log_files.sort(key=lambda f: os.path.getmtime(os.path.join(log_dir, f)), reverse=True)
latest_log = os.path.join(log_dir, log_files[0])
print(f"分析日志: {latest_log}")
print()
try:
with open(latest_log, 'r', encoding='utf-8', errors='replace') as f:
lines = f.readlines()
except Exception as e:
print(f"读取日志失败: {e}")
return None
return lines, latest_log
def check_service_startup(lines):
@@ -56,15 +56,15 @@ def check_service_startup(lines):
print("=" * 60)
print("1. 检查服务启动状态")
print("=" * 60)
service_started = False
service_logs = []
for line in lines:
if '截图服务' in line or 'ScreenshotService' in line or '后台截图' in line:
service_started = True
service_logs.append(line.strip())
if service_started:
print("✅ 服务已启动")
print("\n服务启动日志:")
@@ -76,7 +76,7 @@ def check_service_startup(lines):
print(" 可能原因:")
print(" 1. 程序还未重新运行(需要运行新代码)")
print(" 2. 服务启动时发生异常(被静默捕获)")
return service_started
def analyze_screenshot_performance(lines, service_started):
@@ -84,11 +84,11 @@ def analyze_screenshot_performance(lines, service_started):
print("\n" + "=" * 60)
print("2. 分析截图性能")
print("=" * 60)
# 提取截图耗时
screenshot_times = []
screenshot_logs = []
for line in lines:
# 查找截图耗时
if 'screenshot_elapsed_seconds' in line:
@@ -97,24 +97,24 @@ def analyze_screenshot_performance(lines, service_started):
elapsed = float(match.group(1))
screenshot_times.append(elapsed)
screenshot_logs.append((elapsed, line.strip()[:100]))
# 查找截图成功日志(用于分析时间间隔)
if '[截图]' in line and ('成功' in line or '✓' in line):
timestamp_match = re.search(r'(\d{2}:\d{2}:\d{2})', line)
if timestamp_match:
screenshot_logs.append(('log', line.strip()[:100]))
if screenshot_times:
avg_time = sum(screenshot_times) / len(screenshot_times)
min_time = min(screenshot_times)
max_time = max(screenshot_times)
print(f"截图耗时统计(共 {len(screenshot_times)} 次):")
print(f" 平均耗时: {avg_time:.2f} 秒")
print(f" 最短耗时: {min_time:.2f} 秒")
print(f" 最长耗时: {max_time:.2f} 秒")
print()
# 分析优化效果
if service_started:
print("优化效果分析(服务已启动):")
@@ -141,7 +141,7 @@ def analyze_screenshot_performance(lines, service_started):
print(" - 缓存命中: < 0.01秒")
print(" - 缓存未命中: 0.5-1秒")
print(" - 平均耗时: 0.3-0.8秒")
# 显示最近的截图耗时
print("\n最近的截图耗时(最后5次):")
recent_times = [t for t, _ in screenshot_logs if isinstance(t, float)][-5:]
@@ -157,10 +157,10 @@ def check_cache_effectiveness(lines):
print("\n" + "=" * 60)
print("3. 检查缓存效果")
print("=" * 60)
# 查找连续的截图操作,分析时间间隔
screenshot_timestamps = []
for line in lines:
if '[截图]' in line and ('成功' in line or '✓' in line):
# 提取时间戳
@@ -174,23 +174,23 @@ def check_cache_effectiveness(lines):
screenshot_timestamps.append(timestamp)
except Exception:
pass
if len(screenshot_timestamps) >= 2:
intervals = []
for i in range(1, len(screenshot_timestamps)):
interval = screenshot_timestamps[i] - screenshot_timestamps[i-1]
if interval > 0: # 避免负数
intervals.append(interval)
if intervals:
avg_interval = sum(intervals) / len(intervals)
min_interval = min(intervals)
print(f"截图时间间隔分析(共 {len(intervals)} 个间隔):")
print(f" 平均间隔: {avg_interval:.2f} 秒")
print(f" 最短间隔: {min_interval:.2f} 秒")
print()
if min_interval < 1.0:
print(" ✅ 发现快速连续截图(间隔 < 1秒)")
print(" 说明缓存可能生效,响应速度很快")
@@ -208,26 +208,26 @@ def check_code_integration():
print("\n" + "=" * 60)
print("4. 检查代码集成")
print("=" * 60)
# 检查 douyin_fudai.py
douyin_fudai_path = "douyin/core/douyin_fudai.py"
if os.path.exists(douyin_fudai_path):
with open(douyin_fudai_path, 'r', encoding='utf-8') as f:
content = f.read()
if 'ScreenshotService' in content and 'service.start' in content:
print("✅ douyin_fudai.py 已包含服务启动代码")
else:
print("❌ douyin_fudai.py 未包含服务启动代码")
else:
print(f"❌ 文件不存在: {douyin_fudai_path}")
# 检查 screenshot_operations.py
screenshot_ops_path = "operations/screenshot_operations.py"
if os.path.exists(screenshot_ops_path):
with open(screenshot_ops_path, 'r', encoding='utf-8') as f:
content = f.read()
if 'use_service' in content:
print("✅ screenshot_operations.py 已支持服务模式")
else:
@@ -241,31 +241,31 @@ def main():
print("截图优化效果检查")
print("=" * 60)
print()
# 分析最新日志
result = analyze_latest_log()
if not result:
return 1
lines, log_file = result
# 检查服务启动
service_started = check_service_startup(lines)
# 分析性能
analyze_screenshot_performance(lines, service_started)
# 检查缓存效果
check_cache_effectiveness(lines)
# 检查代码集成
check_code_integration()
# 总结
print("\n" + "=" * 60)
print("检查总结")
print("=" * 60)
if service_started:
print("✅ 服务已启动")
print(" 如果截图耗时仍然较长,可能原因:")
@@ -276,24 +276,15 @@ def main():
print("❌ 服务未启动")
print(" 请重新运行程序,服务会在启动时自动启动")
print(" 查看日志中是否有 '[截图服务] 已启动后台截图服务'")
print()
print("优化效果验证方法:")
print("1. 重新运行程序")
print("2. 观察首次截图后的后续截图速度")
print("3. 如果缓存命中,响应时间应该 < 0.1秒")
print("4. 运行: python tools/analyze_screenshot_logs.py")
return 0
if __name__ == '__main__':
sys.exit(main())