131 lines
4.4 KiB
Python
131 lines
4.4 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
def update_units_mapping():
|
|||
|
|
# 读取土木水利项目案例数据
|
|||
|
|
with open('网页未导入数据/土木水利产业/土木水利项目案例.json', 'r', encoding='utf-8') as f:
|
|||
|
|
civil_data = json.load(f)
|
|||
|
|
|
|||
|
|
print(f"处理{len(civil_data)}个土木水利项目的单元映射")
|
|||
|
|
|
|||
|
|
# 创建项目到单元的映射
|
|||
|
|
project_units_map = {}
|
|||
|
|
|
|||
|
|
for item in civil_data:
|
|||
|
|
project_name = item.get('案例名称', '')
|
|||
|
|
compound_units = item.get('对应单元名称(复合能力课)', '')
|
|||
|
|
vertical_units = item.get('对应单元名称(垂直能力课)', '')
|
|||
|
|
|
|||
|
|
if project_name:
|
|||
|
|
# 处理复合能力课单元(可能有多个,用逗号分隔)
|
|||
|
|
compound_list = []
|
|||
|
|
if compound_units:
|
|||
|
|
compound_list = [unit.strip() for unit in compound_units.split(',') if unit.strip()]
|
|||
|
|
|
|||
|
|
# 处理垂直能力课单元(可能有多个,用逗号分隔)
|
|||
|
|
vertical_list = []
|
|||
|
|
if vertical_units:
|
|||
|
|
vertical_list = [unit.strip() for unit in vertical_units.split(',') if unit.strip()]
|
|||
|
|
|
|||
|
|
project_units_map[project_name] = {
|
|||
|
|
"compoundUnits": compound_list,
|
|||
|
|
"verticalUnits": vertical_list
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 显示前几个映射示例
|
|||
|
|
print("\n单元映射示例:")
|
|||
|
|
for idx, (name, units) in enumerate(list(project_units_map.items())[:3], 1):
|
|||
|
|
print(f"\n{idx}. {name}")
|
|||
|
|
print(f" 复合能力课: {units['compoundUnits']}")
|
|||
|
|
print(f" 垂直能力课: {units['verticalUnits']}")
|
|||
|
|
|
|||
|
|
# 生成JavaScript代码
|
|||
|
|
output = """// 项目案例对应单元映射数据 - 土木水利
|
|||
|
|
// 基于 网页未导入数据/土木水利产业/土木水利项目案例.json
|
|||
|
|
|
|||
|
|
export const projectUnitsMapping = """
|
|||
|
|
|
|||
|
|
output += json.dumps(project_units_map, ensure_ascii=False, indent=2)
|
|||
|
|
output += """;\n
|
|||
|
|
// 获取项目的复合能力课程
|
|||
|
|
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(output)
|
|||
|
|
|
|||
|
|
# 统计信息
|
|||
|
|
total_compound = sum(len(v['compoundUnits']) for v in project_units_map.values())
|
|||
|
|
total_vertical = sum(len(v['verticalUnits']) for v in project_units_map.values())
|
|||
|
|
|
|||
|
|
print(f"\n✅ 项目单元映射已更新完成")
|
|||
|
|
print(f" - 共{len(project_units_map)}个项目")
|
|||
|
|
print(f" - 复合能力课单元: {total_compound}个")
|
|||
|
|
print(f" - 垂直能力课单元: {total_vertical}个")
|
|||
|
|
|
|||
|
|
# 找出所有独特的单元名称
|
|||
|
|
all_compound = set()
|
|||
|
|
all_vertical = set()
|
|||
|
|
for units in project_units_map.values():
|
|||
|
|
all_compound.update(units['compoundUnits'])
|
|||
|
|
all_vertical.update(units['verticalUnits'])
|
|||
|
|
|
|||
|
|
print(f"\n独特的复合能力课单元({len(all_compound)}个):")
|
|||
|
|
for unit in sorted(all_compound)[:5]:
|
|||
|
|
print(f" - {unit}")
|
|||
|
|
if len(all_compound) > 5:
|
|||
|
|
print(f" ... 还有{len(all_compound) - 5}个")
|
|||
|
|
|
|||
|
|
print(f"\n独特的垂直能力课单元({len(all_vertical)}个):")
|
|||
|
|
for unit in sorted(all_vertical)[:5]:
|
|||
|
|
print(f" - {unit}")
|
|||
|
|
if len(all_vertical) > 5:
|
|||
|
|
print(f" ... 还有{len(all_vertical) - 5}个")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
update_units_mapping()
|