116 lines
4.0 KiB
Python
116 lines
4.0 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
|
||
|
|
def convert_energy_projects():
|
||
|
|
"""
|
||
|
|
将能源项目案例数据转换为项目库Mock数据格式
|
||
|
|
"""
|
||
|
|
|
||
|
|
# 读取能源项目案例数据
|
||
|
|
with open("网页未导入数据/能源产业/能源项目案例.json", 'r', encoding='utf-8') as f:
|
||
|
|
energy_projects = json.load(f)
|
||
|
|
|
||
|
|
# 定义能源产业的项目分类
|
||
|
|
energy_categories = {
|
||
|
|
"电力工程巡检与运维": "电力工程巡检与运维",
|
||
|
|
"智能制造与新能源材料制备": "新能源材料制备与智能制造",
|
||
|
|
"电力系统调度与优化": "电力系统调度与优化",
|
||
|
|
"可再生能源发电": "可再生能源发电技术",
|
||
|
|
"储能技术应用": "储能技术与应用"
|
||
|
|
}
|
||
|
|
|
||
|
|
# 转换项目数据
|
||
|
|
converted_projects = []
|
||
|
|
|
||
|
|
for idx, project in enumerate(energy_projects, 1):
|
||
|
|
# 从项目案例名称提取岗位信息
|
||
|
|
resume_names = project.get("对应个人简历名称", "").split(",")
|
||
|
|
positions = [name.strip() for name in resume_names if name.strip()]
|
||
|
|
|
||
|
|
# 确定项目分类
|
||
|
|
vertical_direction = project.get("所属垂直方向", "")
|
||
|
|
if "电力工程巡检与运维" in vertical_direction:
|
||
|
|
direction = "电力工程巡检与运维"
|
||
|
|
category = "电力运维"
|
||
|
|
elif "智能制造与新能源材料制备" in vertical_direction:
|
||
|
|
direction = "新能源材料制备与智能制造"
|
||
|
|
category = "新能源制造"
|
||
|
|
else:
|
||
|
|
direction = "电力工程巡检与运维"
|
||
|
|
category = "能源技术"
|
||
|
|
|
||
|
|
# 提取对应单元名称
|
||
|
|
vertical_units = project.get("对应单元名称(垂直能力课)", "").split(",")
|
||
|
|
unit = vertical_units[0].strip() if vertical_units else "能源技术基础"
|
||
|
|
|
||
|
|
converted_project = {
|
||
|
|
"id": idx,
|
||
|
|
"name": project["案例名称"],
|
||
|
|
"description": direction,
|
||
|
|
"positions": positions if positions else ["能源工程师"],
|
||
|
|
"unit": unit,
|
||
|
|
"direction": direction,
|
||
|
|
"category": category
|
||
|
|
}
|
||
|
|
|
||
|
|
converted_projects.append(converted_project)
|
||
|
|
|
||
|
|
print(f"✅ 转换完成,共转换 {len(converted_projects)} 个能源项目")
|
||
|
|
|
||
|
|
# 输出前5个项目用于验证
|
||
|
|
print(f"\n📋 前5个转换后的项目:")
|
||
|
|
for i, proj in enumerate(converted_projects[:5], 1):
|
||
|
|
print(f" {i}. {proj['name']}")
|
||
|
|
print(f" 分类: {proj['direction']}")
|
||
|
|
print(f" 岗位: {', '.join(proj['positions'])}")
|
||
|
|
print(f" 单元: {proj['unit']}")
|
||
|
|
print()
|
||
|
|
|
||
|
|
return converted_projects
|
||
|
|
|
||
|
|
def update_project_mock_data(converted_projects):
|
||
|
|
"""
|
||
|
|
更新projectLibraryMock.js文件
|
||
|
|
"""
|
||
|
|
|
||
|
|
# 读取原始Mock文件
|
||
|
|
with open("src/mocks/projectLibraryMock.js", 'r', encoding='utf-8') as f:
|
||
|
|
content = f.read()
|
||
|
|
|
||
|
|
# 生成新的项目数据JavaScript格式
|
||
|
|
projects_js = "[\n"
|
||
|
|
for project in converted_projects:
|
||
|
|
positions_str = '",\n "'.join(project['positions'])
|
||
|
|
projects_js += f''' {{
|
||
|
|
"id": {project['id']},
|
||
|
|
"name": "{project['name']}",
|
||
|
|
"description": "{project['description']}",
|
||
|
|
"positions": [
|
||
|
|
"{positions_str}"
|
||
|
|
],
|
||
|
|
"unit": "{project['unit']}",
|
||
|
|
"direction": "{project['direction']}",
|
||
|
|
"category": "{project['category']}"
|
||
|
|
}},
|
||
|
|
'''
|
||
|
|
|
||
|
|
projects_js = projects_js.rstrip(',\n') + "\n ]"
|
||
|
|
|
||
|
|
# 替换projects数组
|
||
|
|
pattern = r'const projects = \[[\s\S]*?\];'
|
||
|
|
replacement = f'const projects = {projects_js};'
|
||
|
|
|
||
|
|
updated_content = re.sub(pattern, replacement, content)
|
||
|
|
|
||
|
|
# 写入更新后的内容
|
||
|
|
with open("src/mocks/projectLibraryMock.js", 'w', encoding='utf-8') as f:
|
||
|
|
f.write(updated_content)
|
||
|
|
|
||
|
|
print(f"✅ projectLibraryMock.js 项目列表数据已更新")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
converted_projects = convert_energy_projects()
|
||
|
|
update_project_mock_data(converted_projects)
|