85 lines
3.2 KiB
Python
85 lines
3.2 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
|
||
|
|
def verify_units_mapping():
|
||
|
|
"""验证项目单元映射数据是否正确"""
|
||
|
|
|
||
|
|
# 1. 读取大健康项目案例原始数据
|
||
|
|
with open('网页未导入数据/大健康产业/大健康项目案例.json', 'r', encoding='utf-8') as f:
|
||
|
|
health_data = json.load(f)
|
||
|
|
|
||
|
|
# 2. 读取生成的projectUnitsMapping.js文件
|
||
|
|
with open('src/data/projectUnitsMapping.js', 'r', encoding='utf-8') as f:
|
||
|
|
mapping_content = f.read()
|
||
|
|
|
||
|
|
# 3. 提取映射数据
|
||
|
|
pattern = r'export const projectUnitsMapping = ({[\s\S]*?});'
|
||
|
|
match = re.search(pattern, mapping_content)
|
||
|
|
|
||
|
|
if match:
|
||
|
|
mapping_json = match.group(1)
|
||
|
|
# 清理JSON格式
|
||
|
|
mapping_json = mapping_json.replace('\\n', '\n')
|
||
|
|
try:
|
||
|
|
mapping_data = json.loads(mapping_json)
|
||
|
|
except:
|
||
|
|
# 使用eval作为备选方案
|
||
|
|
safe_dict = {"true": True, "false": False, "null": None}
|
||
|
|
mapping_data = eval(mapping_json, {"__builtins__": {}}, safe_dict)
|
||
|
|
|
||
|
|
print("=" * 60)
|
||
|
|
print("项目单元映射验证报告")
|
||
|
|
print("=" * 60)
|
||
|
|
|
||
|
|
# 验证每个项目的单元映射
|
||
|
|
for project in health_data:
|
||
|
|
project_name = project.get('案例名称', '')
|
||
|
|
|
||
|
|
print(f"\n项目: {project_name}")
|
||
|
|
print("-" * 40)
|
||
|
|
|
||
|
|
# 原始数据中的单元
|
||
|
|
original_compound = project.get('对应单元名称(复合能力课)', '')
|
||
|
|
original_vertical = project.get('对应单元名称(垂直能力课)', '')
|
||
|
|
|
||
|
|
# 分割为列表
|
||
|
|
original_compound_units = [u.strip() for u in original_compound.split(',') if u.strip()]
|
||
|
|
original_vertical_units = [u.strip() for u in original_vertical.split(',') if u.strip()]
|
||
|
|
|
||
|
|
# 映射数据中的单元
|
||
|
|
if project_name in mapping_data:
|
||
|
|
mapped = mapping_data[project_name]
|
||
|
|
mapped_compound = mapped.get('compoundUnits', [])
|
||
|
|
mapped_vertical = mapped.get('verticalUnits', [])
|
||
|
|
|
||
|
|
# 比较复合能力课
|
||
|
|
print(" 复合能力课:")
|
||
|
|
if set(original_compound_units) == set(mapped_compound):
|
||
|
|
print(f" ✅ 一致: {', '.join(mapped_compound)}")
|
||
|
|
else:
|
||
|
|
print(f" ❌ 不一致!")
|
||
|
|
print(f" 原始: {', '.join(original_compound_units)}")
|
||
|
|
print(f" 映射: {', '.join(mapped_compound)}")
|
||
|
|
|
||
|
|
# 比较垂直能力课
|
||
|
|
print(" 垂直能力课:")
|
||
|
|
if set(original_vertical_units) == set(mapped_vertical):
|
||
|
|
print(f" ✅ 一致: {', '.join(mapped_vertical)}")
|
||
|
|
else:
|
||
|
|
print(f" ❌ 不一致!")
|
||
|
|
print(f" 原始: {', '.join(original_vertical_units)}")
|
||
|
|
print(f" 映射: {', '.join(mapped_vertical)}")
|
||
|
|
else:
|
||
|
|
print(" ⚠️ 项目未找到映射!")
|
||
|
|
|
||
|
|
print("\n" + "=" * 60)
|
||
|
|
print(f"验证完成: 共{len(health_data)}个项目")
|
||
|
|
|
||
|
|
else:
|
||
|
|
print("无法解析映射数据")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
verify_units_mapping()
|