整理项目文件分类
This commit is contained in:
1 parent
38e2b399d4
commit
1fdec7a548
20 files changed
+35
-13
No files matched your search
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
# 查找目标文件
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
target_dir = os.path.join(PROJECT_ROOT, "pic", "debug_captures", "2025-12-31")
|
||||
if os.path.exists(target_dir):
|
||||
files = os.listdir(target_dir)
|
||||
# 查找包含关键字的文件
|
||||
target_file = None
|
||||
for f in files:
|
||||
if "152118" in f and "福袋倒计时_分钟" in f and "识别后" in f and "390,1110" in f:
|
||||
target_file = f
|
||||
break
|
||||
|
||||
if target_file:
|
||||
# 使用绝对路径,避免编码问题
|
||||
full_path = os.path.abspath(os.path.join(target_dir, target_file))
|
||||
print(f"找到文件: {target_file}")
|
||||
print(f"完整路径: {full_path}")
|
||||
print(f"文件存在: {os.path.exists(full_path)}")
|
||||
print("\n开始运行测试...\n")
|
||||
|
||||
# 运行测试脚本
|
||||
cmd = [
|
||||
sys.executable,
|
||||
"-u",
|
||||
os.path.join(PROJECT_ROOT, "deleted_tests_backup", "test_real_parallel_ocr.py"),
|
||||
full_path,
|
||||
]
|
||||
env = os.environ.copy()
|
||||
env['PYTHONIOENCODING'] = 'utf-8'
|
||||
env['PYTHONUNBUFFERED'] = '1'
|
||||
# 实时显示输出
|
||||
process = subprocess.Popen(cmd, encoding='utf-8', stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
text=True, env=env, bufsize=1, universal_newlines=True)
|
||||
if process.stdout:
|
||||
for line in process.stdout:
|
||||
print(line, end='')
|
||||
process.wait()
|
||||
print(f"\n退出码: {process.returncode}")
|
||||
else:
|
||||
print("未找到目标文件")
|
||||
print("可用文件列表(前10个):")
|
||||
for f in files[:10]:
|
||||
if "152118" in f:
|
||||
print(f" {f}")
|
||||
else:
|
||||
print(f"目录不存在: {target_dir}")
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试养号延迟修改
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
|
||||
def test_delays():
|
||||
"""测试延迟设置是否正确"""
|
||||
print("=== 测试延迟设置 ===")
|
||||
|
||||
# 检查代码中是否包含正确的延迟调用
|
||||
with open(
|
||||
os.path.join(PROJECT_ROOT, "douyin", "other", "douyin_yanghao.py"),
|
||||
"r",
|
||||
encoding="utf-8",
|
||||
) as f:
|
||||
content = f.read()
|
||||
|
||||
# 检查点击爱心前的延迟
|
||||
if "analyser.operation.delay(1.0) # 点击前延迟1秒" in content:
|
||||
print("✅ 爱心点击前延迟1秒 - 正确")
|
||||
else:
|
||||
print("❌ 爱心点击前延迟未找到")
|
||||
|
||||
# 检查点击爱心后的延迟
|
||||
if "analyser.operation.delay(1.0) # 点击后延迟1秒" in content:
|
||||
print("✅ 爱心点击后延迟1秒 - 正确")
|
||||
else:
|
||||
print("❌ 爱心点击后延迟未找到")
|
||||
|
||||
# 检查点击收藏前的延迟
|
||||
if content.count("analyser.operation.delay(1.0) # 点击前延迟1秒") >= 2:
|
||||
print("✅ 收藏点击前延迟1秒 - 正确")
|
||||
else:
|
||||
print("❌ 收藏点击前延迟未找到")
|
||||
|
||||
# 检查点击收藏后的延迟
|
||||
if content.count("analyser.operation.delay(1.0) # 点击后延迟1秒") >= 2:
|
||||
print("✅ 收藏点击后延迟1秒 - 正确")
|
||||
else:
|
||||
print("❌ 收藏点击后延迟未找到")
|
||||
|
||||
# 检查推荐页流程的延迟
|
||||
if (
|
||||
content.count("analyser.operation.delay(1.0)") >= 4
|
||||
): # 2个点击延迟 + 2个推荐页延迟
|
||||
print("✅ 推荐页流程延迟1秒 - 正确")
|
||||
else:
|
||||
print("❌ 推荐页流程延迟不完整")
|
||||
|
||||
print("\n=== 延迟设置验证完成 ===")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_delays()
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
# 添加项目根目录到路径
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
from douyin.fudai.douyin_fudai_core import should_skip_fudai_by_config
|
||||
|
||||
|
||||
# 创建一个模拟的 analyser 对象
|
||||
class MockAnalyser:
|
||||
def _log_kv(self, category, message, **kwargs):
|
||||
print(f"[{category}] {message}")
|
||||
for key, value in kwargs.items():
|
||||
print(f" {key}: {value}")
|
||||
|
||||
|
||||
# 测试筛选逻辑
|
||||
analyser = MockAnalyser()
|
||||
|
||||
# 测试数据:detail 是一个元组,包含福袋的详细信息
|
||||
# 格式为 (prize_value_yuan, participants, copies, content, button_text, countdown_tuple, ...)
|
||||
detail = (
|
||||
75.0, # prize_value_yuan
|
||||
10, # participants
|
||||
1, # copies
|
||||
"", # content
|
||||
"一键发表评论", # button_text
|
||||
(time.time() + 120, time.time() + 120), # countdown (start, end)
|
||||
)
|
||||
|
||||
result, reason = should_skip_fudai_by_config(analyser=analyser, detail=detail)
|
||||
|
||||
print(f"\n筛选结果: {'跳过' if result else '参与'}, 原因: {reason}")
|
||||
@@ -0,0 +1,232 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OCR引擎性能对比测试
|
||||
测试 EasyOCR vs PaddleOCR 的各项性能参数
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import psutil
|
||||
import gc
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def get_memory_usage():
|
||||
"""获取当前内存使用情况"""
|
||||
process = psutil.Process(os.getpid())
|
||||
return process.memory_info().rss / 1024 / 1024 # MB
|
||||
|
||||
|
||||
def test_easyocr_performance():
|
||||
"""测试EasyOCR性能"""
|
||||
print("测试 EasyOCR 性能...")
|
||||
results = {
|
||||
"type": "EasyOCR",
|
||||
"init_time": 0,
|
||||
"recognition_times": [],
|
||||
"memory_usage": 0,
|
||||
}
|
||||
|
||||
try:
|
||||
# 测试初始化
|
||||
memory_before = get_memory_usage()
|
||||
start_time = time.time()
|
||||
|
||||
import easyocr
|
||||
|
||||
reader = easyocr.Reader(["ch_sim", "en"])
|
||||
|
||||
init_time = time.time() - start_time
|
||||
memory_after = get_memory_usage()
|
||||
|
||||
results["init_time"] = init_time
|
||||
results["memory_usage"] = memory_after - memory_before
|
||||
results["version"] = easyocr.__version__
|
||||
|
||||
print(f" 初始化时间: {init_time:.2f}秒")
|
||||
print(f" 内存增加: {memory_after - memory_before:.2f}MB")
|
||||
|
||||
# 查找测试图片
|
||||
pic_dir = PROJECT_ROOT / "pic"
|
||||
test_images = list(pic_dir.glob("*.png"))[:2] # 最多2张图片
|
||||
|
||||
if not test_images:
|
||||
# 创建测试图片
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
img = Image.new("RGB", (300, 100), color="white")
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.text((10, 30), "测试文本 123.45元", fill="black")
|
||||
test_path = pic_dir / "test_ocr.png"
|
||||
test_path.parent.mkdir(exist_ok=True)
|
||||
img.save(test_path)
|
||||
test_images = [test_path]
|
||||
|
||||
# 测试识别性能
|
||||
for img_path in test_images:
|
||||
print(f" 测试图片: {img_path.name}")
|
||||
for i in range(3): # 3次测试
|
||||
start_time = time.time()
|
||||
results_ocr = reader.readtext(str(img_path))
|
||||
elapsed = time.time() - start_time
|
||||
results["recognition_times"].append(elapsed)
|
||||
print(f" 第{i+1}次: {elapsed:.2f}秒")
|
||||
|
||||
# 清理
|
||||
del reader
|
||||
gc.collect()
|
||||
|
||||
except Exception as e:
|
||||
results["error"] = str(e)
|
||||
print(f" [ERROR] {e}")
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def test_paddleocr_performance():
|
||||
"""测试PaddleOCR性能"""
|
||||
print("测试 PaddleOCR 性能...")
|
||||
results = {
|
||||
"type": "PaddleOCR",
|
||||
"init_time": 0,
|
||||
"recognition_times": [],
|
||||
"memory_usage": 0,
|
||||
}
|
||||
|
||||
try:
|
||||
# 测试初始化
|
||||
memory_before = get_memory_usage()
|
||||
start_time = time.time()
|
||||
|
||||
from paddleocr import PaddleOCR
|
||||
|
||||
ocr = PaddleOCR(use_angle_cls=True, lang="ch")
|
||||
|
||||
init_time = time.time() - start_time
|
||||
memory_after = get_memory_usage()
|
||||
|
||||
results["init_time"] = init_time
|
||||
results["memory_usage"] = memory_after - memory_before
|
||||
results["version"] = getattr(PaddleOCR, "__version__", "3.3.2")
|
||||
|
||||
print(f" 初始化时间: {init_time:.2f}秒")
|
||||
print(f" 内存增加: {memory_after - memory_before:.2f}MB")
|
||||
|
||||
# 查找测试图片
|
||||
pic_dir = PROJECT_ROOT / "pic"
|
||||
test_images = list(pic_dir.glob("*.png"))[:2] # 最多2张图片
|
||||
|
||||
if not test_images:
|
||||
# 创建测试图片
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
img = Image.new("RGB", (300, 100), color="white")
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.text((10, 30), "测试文本 123.45元", fill="black")
|
||||
test_path = pic_dir / "test_ocr.png"
|
||||
test_path.parent.mkdir(exist_ok=True)
|
||||
img.save(test_path)
|
||||
test_images = [test_path]
|
||||
|
||||
# 测试识别性能
|
||||
for img_path in test_images:
|
||||
print(f" 测试图片: {img_path.name}")
|
||||
for i in range(3): # 3次测试
|
||||
start_time = time.time()
|
||||
results_ocr = ocr.ocr(str(img_path))
|
||||
elapsed = time.time() - start_time
|
||||
results["recognition_times"].append(elapsed)
|
||||
print(f" 第{i+1}次: {elapsed:.2f}秒")
|
||||
|
||||
# 清理
|
||||
del ocr
|
||||
gc.collect()
|
||||
|
||||
except Exception as e:
|
||||
results["error"] = str(e)
|
||||
print(f" [ERROR] {e}")
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print("OCR引擎性能对比测试")
|
||||
print("=" * 60)
|
||||
print(f"测试时间: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print(f"Python版本: {sys.version.split()[0]}")
|
||||
print(f"CPU核心数: {psutil.cpu_count()}")
|
||||
print(f"总内存: {psutil.virtual_memory().total / 1024 / 1024 / 1024:.1f}GB")
|
||||
print()
|
||||
|
||||
# 测试EasyOCR
|
||||
easyocr_results = test_easyocr_performance()
|
||||
print()
|
||||
|
||||
# 测试PaddleOCR
|
||||
paddleocr_results = test_paddleocr_performance()
|
||||
print()
|
||||
|
||||
# 结果对比
|
||||
print("性能对比结果")
|
||||
print("=" * 60)
|
||||
|
||||
def print_stats(name, results):
|
||||
if "error" in results:
|
||||
print(f"{name}: 失败 - {results['error']}")
|
||||
return
|
||||
|
||||
init_time = results["init_time"]
|
||||
memory = results["memory_usage"]
|
||||
times = results["recognition_times"]
|
||||
if times:
|
||||
avg_time = sum(times) / len(times)
|
||||
min_time = min(times)
|
||||
max_time = max(times)
|
||||
print(f"{name} (v{results.get('version', 'unknown')}):")
|
||||
print(f" 初始化: {init_time:.2f}秒, 内存: {memory:.1f}MB")
|
||||
print(
|
||||
f" 识别平均: {avg_time:.2f}秒 (范围: {min_time:.2f}-{max_time:.2f}秒)"
|
||||
)
|
||||
else:
|
||||
print(f"{name}: 无识别测试数据")
|
||||
|
||||
print_stats("EasyOCR", easyocr_results)
|
||||
print()
|
||||
print_stats("PaddleOCR", paddleocr_results)
|
||||
print()
|
||||
|
||||
# 推荐
|
||||
if (
|
||||
"error" not in easyocr_results
|
||||
and "error" not in paddleocr_results
|
||||
and easyocr_results["recognition_times"]
|
||||
and paddleocr_results["recognition_times"]
|
||||
):
|
||||
|
||||
easyocr_avg = sum(easyocr_results["recognition_times"]) / len(
|
||||
easyocr_results["recognition_times"]
|
||||
)
|
||||
paddleocr_avg = sum(paddleocr_results["recognition_times"]) / len(
|
||||
paddleocr_results["recognition_times"]
|
||||
)
|
||||
|
||||
print("推荐:")
|
||||
if easyocr_avg < paddleocr_avg:
|
||||
faster_ratio = paddleocr_avg / easyocr_avg
|
||||
print(f"• EasyOCR 更快 ({faster_ratio:.1f}倍), 适合速度优先场景")
|
||||
print("• PaddleOCR 更准, 适合准确率优先场景")
|
||||
else:
|
||||
faster_ratio = easyocr_avg / paddleocr_avg
|
||||
print(f"• PaddleOCR 更快 ({faster_ratio:.1f}倍), 推荐使用")
|
||||
print("• EasyOCR 作为备用选项")
|
||||
|
||||
print("• 当前项目策略 (EasyOCR优先+PaddleOCR备用) 是合理的")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,41 @@
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
# Add project root to path
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if project_root not in sys.path:
|
||||
sys.path.insert(0, project_root)
|
||||
|
||||
import gui.web_gui as wg
|
||||
|
||||
def test_server():
|
||||
# Start server in background thread
|
||||
def run_server():
|
||||
try:
|
||||
wg.main()
|
||||
except SystemExit:
|
||||
pass
|
||||
|
||||
server_thread = threading.Thread(target=run_server, daemon=True)
|
||||
server_thread.start()
|
||||
|
||||
# Wait for server to start
|
||||
time.sleep(2)
|
||||
|
||||
# Test API
|
||||
try:
|
||||
import requests
|
||||
response = requests.get('http://localhost:8001/api/config', timeout=5)
|
||||
print(f"Status: {response.status_code}")
|
||||
print(f"Response length: {len(response.text)}")
|
||||
data = response.json()
|
||||
print(f"Config keys: {len(data)}")
|
||||
print(f"Sample keys: {list(data.keys())[:5]}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_server()
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
验证福袋详情识别完成后映射表记录功能的脚本
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
|
||||
def validate_fudai_mapping_recording():
|
||||
"""验证福袋详情识别完成后映射表记录功能"""
|
||||
print("开始验证福袋详情识别完成后映射表记录功能...")
|
||||
|
||||
# 检查代码模式
|
||||
patterns_to_check = [
|
||||
"analyser._current_fudai_content = content",
|
||||
"analyser._last_fudai_detail_tuple = detail",
|
||||
"basic_join_decision:设置福袋信息并记录映射表",
|
||||
"_record_room_title_and_pos",
|
||||
]
|
||||
|
||||
# 读取文件内容
|
||||
file_path = os.path.join(PROJECT_ROOT, "douyin", "fudai", "douyin_fudai_core.py")
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
except Exception as e:
|
||||
print(f"❌ 无法读取文件 {file_path}: {e}")
|
||||
return False
|
||||
|
||||
# 检查每个模式
|
||||
missing_patterns = []
|
||||
for pattern in patterns_to_check:
|
||||
if pattern not in content:
|
||||
missing_patterns.append(pattern)
|
||||
|
||||
if missing_patterns:
|
||||
print("❌ 缺少以下代码模式:")
|
||||
for pattern in missing_patterns:
|
||||
print(f" - {pattern}")
|
||||
return False
|
||||
|
||||
print("✅ 福袋详情识别完成后映射表记录功能验证通过")
|
||||
print(" - 福袋属性设置代码存在")
|
||||
print(" - 映射表记录调用存在")
|
||||
print(" - 记录时机正确(在basic_join_decision开始时)")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = validate_fudai_mapping_recording()
|
||||
sys.exit(0 if success else 1)
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
验证预约福袋参与成功后锁定期保护逻辑
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
|
||||
def validate_reservation_lock_protection():
|
||||
"""验证预约福袋参与成功后锁定期保护逻辑"""
|
||||
print("开始验证预约福袋参与成功后锁定期保护逻辑...")
|
||||
|
||||
# 检查代码模式
|
||||
patterns_to_check = [
|
||||
"参与成功,处理锁定期并移除预约",
|
||||
"has_other_reservations",
|
||||
"设置保护期确保依次参与",
|
||||
"protection_seconds=10",
|
||||
"参与成功,清除锁定期(无其他预约)",
|
||||
]
|
||||
|
||||
# 读取文件内容
|
||||
file_path = os.path.join(PROJECT_ROOT, "douyin", "core", "douyin_fudai.py")
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
except Exception as e:
|
||||
print(f"❌ 无法读取文件 {file_path}: {e}")
|
||||
return False
|
||||
|
||||
# 检查每个模式
|
||||
missing_patterns = []
|
||||
for pattern in patterns_to_check:
|
||||
if pattern not in content:
|
||||
missing_patterns.append(pattern)
|
||||
|
||||
if missing_patterns:
|
||||
print("❌ 缺少以下代码模式:")
|
||||
for pattern in missing_patterns:
|
||||
print(f" - {pattern}")
|
||||
return False
|
||||
|
||||
# 检查保护期逻辑是否存在
|
||||
protection_logic_found = (
|
||||
"has_other_reservations = False" in content
|
||||
and "if has_other_reservations:" in content
|
||||
and "protection_until = time.time() + 10.0" in content
|
||||
and "max(self.reservation_focus_until_ts, protection_until)" in content
|
||||
)
|
||||
|
||||
if not protection_logic_found:
|
||||
print("❌ 保护期设置逻辑不完整")
|
||||
return False
|
||||
|
||||
print("✅ 预约福袋参与成功后锁定期保护逻辑验证通过")
|
||||
print(" - 参与成功后检查是否有其他预约")
|
||||
print(" - 有其他预约时设置10秒保护期")
|
||||
print(" - 无其他预约时清除锁定期")
|
||||
print(" - 确保预约福袋依次参与,不被其他预约打断")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = validate_reservation_lock_protection()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in new issue
Block a user