155 lines
4.9 KiB
Python
155 lines
4.9 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
def generate_chemical_units_mapping():
|
|||
|
|
"""生成化工项目的单元映射数据"""
|
|||
|
|
|
|||
|
|
# 读取化工项目案例数据
|
|||
|
|
with open('网页未导入数据/化工产业/化工项目案例.json', 'r', encoding='utf-8') as f:
|
|||
|
|
data = json.load(f)
|
|||
|
|
|
|||
|
|
mapping_data = {}
|
|||
|
|
|
|||
|
|
for project in data:
|
|||
|
|
name = project.get('案例名称', '').strip()
|
|||
|
|
composite_courses = project.get('对应单元名称(复合能力课)', '').strip()
|
|||
|
|
vertical_courses = project.get('对应单元名称(垂直能力课)', '').strip()
|
|||
|
|
|
|||
|
|
# 处理复合能力课(用逗号分割)
|
|||
|
|
composite_list = []
|
|||
|
|
if composite_courses:
|
|||
|
|
composite_list = [course.strip() for course in composite_courses.split(',') if course.strip()]
|
|||
|
|
|
|||
|
|
# 处理垂直能力课(用逗号分割)
|
|||
|
|
vertical_list = []
|
|||
|
|
if vertical_courses:
|
|||
|
|
vertical_list = [course.strip() for course in vertical_courses.split(',') if course.strip()]
|
|||
|
|
|
|||
|
|
if name:
|
|||
|
|
mapping_data[name] = {
|
|||
|
|
"compoundUnits": composite_list,
|
|||
|
|
"verticalUnits": vertical_list
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return mapping_data
|
|||
|
|
|
|||
|
|
def create_project_units_mapping_file():
|
|||
|
|
"""创建新的projectUnitsMapping.js文件"""
|
|||
|
|
|
|||
|
|
mapping_data = generate_chemical_units_mapping()
|
|||
|
|
|
|||
|
|
# 生成JavaScript文件内容
|
|||
|
|
js_content = """// 项目案例对应单元映射数据 - 化工产业
|
|||
|
|
// 基于 网页未导入数据/化工产业/化工项目案例.json
|
|||
|
|
|
|||
|
|
export const projectUnitsMapping = {
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
# 添加每个项目的映射数据
|
|||
|
|
for project_name, units in mapping_data.items():
|
|||
|
|
js_content += f' "{project_name}": {{\n'
|
|||
|
|
|
|||
|
|
# 复合能力课
|
|||
|
|
js_content += ' "compoundUnits": [\n'
|
|||
|
|
for unit in units["compoundUnits"]:
|
|||
|
|
js_content += f' "{unit}",\n'
|
|||
|
|
js_content = js_content.rstrip(',\n') + '\n'
|
|||
|
|
js_content += ' ],\n'
|
|||
|
|
|
|||
|
|
# 垂直能力课
|
|||
|
|
js_content += ' "verticalUnits": [\n'
|
|||
|
|
for unit in units["verticalUnits"]:
|
|||
|
|
js_content += f' "{unit}",\n'
|
|||
|
|
js_content = js_content.rstrip(',\n') + '\n'
|
|||
|
|
js_content += ' ]\n'
|
|||
|
|
|
|||
|
|
js_content += ' },\n'
|
|||
|
|
|
|||
|
|
js_content = js_content.rstrip(',\n') + '\n'
|
|||
|
|
js_content += """};
|
|||
|
|
|
|||
|
|
// 获取项目的复合能力课程
|
|||
|
|
export const getCompoundUnits = (projectTitle) => {
|
|||
|
|
if (!projectTitle) return [];
|
|||
|
|
|
|||
|
|
// 直接匹配
|
|||
|
|
if (projectUnitsMapping[projectTitle]) {
|
|||
|
|
return projectUnitsMapping[projectTitle].compoundUnits || [];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 尝试去除后缀后匹配(如"详情")
|
|||
|
|
const cleanTitle = projectTitle.replace(/详情$/, '');
|
|||
|
|
if (projectUnitsMapping[cleanTitle]) {
|
|||
|
|
return projectUnitsMapping[cleanTitle].compoundUnits || [];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return [];
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 获取项目的垂直能力课程
|
|||
|
|
export const getVerticalUnits = (projectTitle) => {
|
|||
|
|
if (!projectTitle) return [];
|
|||
|
|
|
|||
|
|
// 直接匹配
|
|||
|
|
if (projectUnitsMapping[projectTitle]) {
|
|||
|
|
return projectUnitsMapping[projectTitle].verticalUnits || [];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 尝试去除后缀后匹配(如"详情")
|
|||
|
|
const cleanTitle = projectTitle.replace(/详情$/, '');
|
|||
|
|
if (projectUnitsMapping[cleanTitle]) {
|
|||
|
|
return projectUnitsMapping[cleanTitle].verticalUnits || [];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return [];
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 获取项目的所有对应单元
|
|||
|
|
export const getProjectUnits = (projectTitle) => {
|
|||
|
|
const mapping = projectUnitsMapping[projectTitle];
|
|||
|
|
if (!mapping) return [];
|
|||
|
|
|
|||
|
|
return [...mapping.compoundUnits, ...mapping.verticalUnits];
|
|||
|
|
};
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
# 写入文件
|
|||
|
|
with open('src/data/projectUnitsMapping.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(js_content)
|
|||
|
|
|
|||
|
|
print("✅ 已生成新的 projectUnitsMapping.js 文件")
|
|||
|
|
print(f"✅ 包含 {len(mapping_data)} 个化工项目的单元映射数据")
|
|||
|
|
|
|||
|
|
# 显示统计信息
|
|||
|
|
total_compound = sum(len(units["compoundUnits"]) for units in mapping_data.values())
|
|||
|
|
total_vertical = sum(len(units["verticalUnits"]) for units in mapping_data.values())
|
|||
|
|
|
|||
|
|
print(f"📊 统计信息:")
|
|||
|
|
print(f" - 总复合能力课: {total_compound} 个")
|
|||
|
|
print(f" - 总垂直能力课: {total_vertical} 个")
|
|||
|
|
|
|||
|
|
return mapping_data
|
|||
|
|
|
|||
|
|
def show_mapping_summary():
|
|||
|
|
"""显示映射数据摘要"""
|
|||
|
|
mapping_data = generate_chemical_units_mapping()
|
|||
|
|
|
|||
|
|
print("\n化工项目单元映射数据摘要:")
|
|||
|
|
print("=" * 80)
|
|||
|
|
|
|||
|
|
for i, (project_name, units) in enumerate(mapping_data.items(), 1):
|
|||
|
|
print(f"\n{i}. {project_name}")
|
|||
|
|
print(f" 复合能力课 ({len(units['compoundUnits'])}个): {', '.join(units['compoundUnits'])}")
|
|||
|
|
print(f" 垂直能力课 ({len(units['verticalUnits'])}个): {', '.join(units['verticalUnits'])}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
print("正在生成化工项目单元映射数据...")
|
|||
|
|
|
|||
|
|
# 先显示摘要
|
|||
|
|
show_mapping_summary()
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
|
|||
|
|
# 生成映射文件
|
|||
|
|
create_project_units_mapping_file()
|