138 lines
5.7 KiB
Python
138 lines
5.7 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def verify_position_levels():
|
|||
|
|
"""验证项目库数据中的岗位等级是否与大健康岗位简历数据一致"""
|
|||
|
|
|
|||
|
|
# 1. 读取岗位等级映射
|
|||
|
|
position_level_map = {}
|
|||
|
|
with open('网页未导入数据/大健康产业/大健康岗位简历.json', 'r', encoding='utf-8') as f:
|
|||
|
|
resume_data = json.load(f)
|
|||
|
|
for item in resume_data:
|
|||
|
|
position_name = item.get('岗位名称', '')
|
|||
|
|
level = item.get('岗位等级标签', '')
|
|||
|
|
if position_name and level:
|
|||
|
|
position_level_map[position_name] = level
|
|||
|
|
|
|||
|
|
# 2. 读取生成的projectLibraryMock.js文件
|
|||
|
|
with open('src/mocks/projectLibraryMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
mock_content = f.read()
|
|||
|
|
|
|||
|
|
# 3. 提取项目详情数据
|
|||
|
|
# 查找getMockProjectDetail函数中的projects数组
|
|||
|
|
# 使用更宽松的正则表达式
|
|||
|
|
pattern = r'getMockProjectDetail[^{]*\{[^}]*const projects = (\[[^\]]+\]);'
|
|||
|
|
projects_match = re.search(pattern, mock_content, re.DOTALL)
|
|||
|
|
|
|||
|
|
if not projects_match:
|
|||
|
|
# 尝试另一种模式
|
|||
|
|
pattern = r'const projects = (\[\s*\{[\s\S]*?\}\s*\]);'
|
|||
|
|
projects_match = re.search(pattern, mock_content)
|
|||
|
|
|
|||
|
|
if projects_match:
|
|||
|
|
projects_json = projects_match.group(1)
|
|||
|
|
|
|||
|
|
# 清理JavaScript格式为JSON格式
|
|||
|
|
# 移除可能的尾随逗号
|
|||
|
|
projects_json = re.sub(r',(\s*[}\]])', r'\1', projects_json)
|
|||
|
|
|
|||
|
|
try:
|
|||
|
|
projects_data = json.loads(projects_json)
|
|||
|
|
except json.JSONDecodeError:
|
|||
|
|
# 如果JSON解析失败,尝试使用eval(不推荐但有效)
|
|||
|
|
# 先创建一个安全的执行环境
|
|||
|
|
safe_dict = {"true": True, "false": False, "null": None}
|
|||
|
|
try:
|
|||
|
|
projects_data = eval(projects_json, {"__builtins__": {}}, safe_dict)
|
|||
|
|
except:
|
|||
|
|
print("无法解析项目数据,尝试直接从文件提取...")
|
|||
|
|
|
|||
|
|
# 直接查找所有applicablePositions
|
|||
|
|
positions_pattern = r'"applicablePositions":\s*\[(.*?)\]'
|
|||
|
|
all_positions = re.findall(positions_pattern, mock_content, re.DOTALL)
|
|||
|
|
|
|||
|
|
print("=" * 60)
|
|||
|
|
print("项目库岗位等级验证报告")
|
|||
|
|
print("=" * 60)
|
|||
|
|
|
|||
|
|
error_count = 0
|
|||
|
|
correct_count = 0
|
|||
|
|
|
|||
|
|
for positions_str in all_positions:
|
|||
|
|
# 提取每个岗位
|
|||
|
|
pos_items = re.findall(r'\{\s*"level":\s*"([^"]+)",\s*"position":\s*"([^"]+)"\s*\}', positions_str)
|
|||
|
|
|
|||
|
|
for level_in_project, position in pos_items:
|
|||
|
|
expected_level = position_level_map.get(position, '未找到')
|
|||
|
|
|
|||
|
|
if expected_level == '未找到':
|
|||
|
|
print(f" ⚠️ {position}: 在简历数据中未找到")
|
|||
|
|
error_count += 1
|
|||
|
|
elif level_in_project != expected_level:
|
|||
|
|
print(f" ❌ {position}: {level_in_project} → 应为 {expected_level}")
|
|||
|
|
error_count += 1
|
|||
|
|
else:
|
|||
|
|
print(f" ✅ {position}: {level_in_project}")
|
|||
|
|
correct_count += 1
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 60)
|
|||
|
|
print("验证结果汇总:")
|
|||
|
|
print(f"✅ 正确: {correct_count} 个岗位")
|
|||
|
|
print(f"❌ 错误: {error_count} 个岗位")
|
|||
|
|
|
|||
|
|
if error_count == 0 and correct_count > 0:
|
|||
|
|
print("\n🎉 所有岗位等级都正确!")
|
|||
|
|
elif error_count > 0:
|
|||
|
|
print("\n⚠️ 发现岗位等级不一致,请检查!")
|
|||
|
|
else:
|
|||
|
|
print("\n⚠️ 未找到任何岗位数据!")
|
|||
|
|
|
|||
|
|
return error_count == 0
|
|||
|
|
|
|||
|
|
print("=" * 60)
|
|||
|
|
print("项目库岗位等级验证报告")
|
|||
|
|
print("=" * 60)
|
|||
|
|
|
|||
|
|
error_count = 0
|
|||
|
|
correct_count = 0
|
|||
|
|
|
|||
|
|
for project in projects_data:
|
|||
|
|
if 'applicablePositions' in project:
|
|||
|
|
print(f"\n项目: {project.get('name', 'Unknown')}")
|
|||
|
|
print("-" * 40)
|
|||
|
|
|
|||
|
|
for pos_item in project['applicablePositions']:
|
|||
|
|
position = pos_item['position']
|
|||
|
|
level_in_project = pos_item['level']
|
|||
|
|
expected_level = position_level_map.get(position, '未找到')
|
|||
|
|
|
|||
|
|
if expected_level == '未找到':
|
|||
|
|
print(f" ⚠️ {position}: 在简历数据中未找到")
|
|||
|
|
error_count += 1
|
|||
|
|
elif level_in_project != expected_level:
|
|||
|
|
print(f" ❌ {position}: {level_in_project} → 应为 {expected_level}")
|
|||
|
|
error_count += 1
|
|||
|
|
else:
|
|||
|
|
print(f" ✅ {position}: {level_in_project}")
|
|||
|
|
correct_count += 1
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 60)
|
|||
|
|
print("验证结果汇总:")
|
|||
|
|
print(f"✅ 正确: {correct_count} 个岗位")
|
|||
|
|
print(f"❌ 错误: {error_count} 个岗位")
|
|||
|
|
|
|||
|
|
if error_count == 0 and correct_count > 0:
|
|||
|
|
print("\n🎉 所有岗位等级都正确!")
|
|||
|
|
else:
|
|||
|
|
print("\n⚠️ 发现岗位等级不一致,请检查!")
|
|||
|
|
|
|||
|
|
return error_count == 0
|
|||
|
|
else:
|
|||
|
|
print("无法在文件中找到项目数据")
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
verify_position_levels()
|