90 lines
3.3 KiB
Python
90 lines
3.3 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
|
||
|
|
def verify_units_mapping():
|
||
|
|
"""验证单元映射数据是否正确"""
|
||
|
|
|
||
|
|
# 读取化工项目案例数据
|
||
|
|
with open('网页未导入数据/化工产业/化工项目案例.json', 'r', encoding='utf-8') as f:
|
||
|
|
source_data = json.load(f)
|
||
|
|
|
||
|
|
# 读取生成的映射文件
|
||
|
|
with open('src/data/projectUnitsMapping.js', 'r', encoding='utf-8') as f:
|
||
|
|
mapping_content = f.read()
|
||
|
|
|
||
|
|
print("验证化工项目单元映射数据:")
|
||
|
|
print("=" * 80)
|
||
|
|
|
||
|
|
all_correct = True
|
||
|
|
total_projects = 0
|
||
|
|
|
||
|
|
for project in source_data:
|
||
|
|
total_projects += 1
|
||
|
|
name = project.get('案例名称', '').strip()
|
||
|
|
expected_composite = project.get('对应单元名称(复合能力课)', '').strip()
|
||
|
|
expected_vertical = project.get('对应单元名称(垂直能力课)', '').strip()
|
||
|
|
|
||
|
|
# 处理期望的课程列表
|
||
|
|
expected_composite_list = []
|
||
|
|
if expected_composite:
|
||
|
|
expected_composite_list = [course.strip() for course in expected_composite.split(',') if course.strip()]
|
||
|
|
|
||
|
|
expected_vertical_list = []
|
||
|
|
if expected_vertical:
|
||
|
|
expected_vertical_list = [course.strip() for course in expected_vertical.split(',') if course.strip()]
|
||
|
|
|
||
|
|
print(f"\n项目: {name}")
|
||
|
|
|
||
|
|
# 在映射文件中查找该项目
|
||
|
|
project_pattern = rf'"{re.escape(name)}":\s*\{{\s*"compoundUnits":\s*\[(.*?)\],\s*"verticalUnits":\s*\[(.*?)\]\s*\}}'
|
||
|
|
match = re.search(project_pattern, mapping_content, re.DOTALL)
|
||
|
|
|
||
|
|
if match:
|
||
|
|
# 提取复合能力课
|
||
|
|
compound_block = match.group(1)
|
||
|
|
compound_matches = re.findall(r'"([^"]+)"', compound_block)
|
||
|
|
|
||
|
|
# 提取垂直能力课
|
||
|
|
vertical_block = match.group(2)
|
||
|
|
vertical_matches = re.findall(r'"([^"]+)"', vertical_block)
|
||
|
|
|
||
|
|
# 验证复合能力课
|
||
|
|
compound_correct = set(compound_matches) == set(expected_composite_list)
|
||
|
|
if compound_correct:
|
||
|
|
print(f" ✅ 复合能力课 ({len(expected_composite_list)}个): {', '.join(expected_composite_list)}")
|
||
|
|
else:
|
||
|
|
print(f" ❌ 复合能力课不匹配:")
|
||
|
|
print(f" 期望: {expected_composite_list}")
|
||
|
|
print(f" 实际: {compound_matches}")
|
||
|
|
all_correct = False
|
||
|
|
|
||
|
|
# 验证垂直能力课
|
||
|
|
vertical_correct = set(vertical_matches) == set(expected_vertical_list)
|
||
|
|
if vertical_correct:
|
||
|
|
print(f" ✅ 垂直能力课 ({len(expected_vertical_list)}个): {', '.join(expected_vertical_list)}")
|
||
|
|
else:
|
||
|
|
print(f" ❌ 垂直能力课不匹配:")
|
||
|
|
print(f" 期望: {expected_vertical_list}")
|
||
|
|
print(f" 实际: {vertical_matches}")
|
||
|
|
all_correct = False
|
||
|
|
|
||
|
|
else:
|
||
|
|
print(f" ❌ 在映射文件中未找到项目: {name}")
|
||
|
|
all_correct = False
|
||
|
|
|
||
|
|
print("\n" + "=" * 80)
|
||
|
|
print("验证结果汇总")
|
||
|
|
print("=" * 80)
|
||
|
|
print(f"总项目数: {total_projects}")
|
||
|
|
|
||
|
|
if all_correct:
|
||
|
|
print("✅ 所有项目的单元映射数据完全正确!")
|
||
|
|
else:
|
||
|
|
print("❌ 部分项目的单元映射数据有问题")
|
||
|
|
|
||
|
|
return all_correct
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
verify_units_mapping()
|