Files
ALL-teach_sys/frontend_视觉设计/update_project_mock_with_levels.py

225 lines
7.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import json
# 读取视觉设计岗位简历数据,建立岗位等级映射
with open('网页未导入数据/视觉设计产业/视觉设计岗位简历.json', 'r', encoding='utf-8') as f:
positions_data = json.load(f)
# 建立岗位名称与等级的映射
position_levels = {}
for item in positions_data:
position_name = item.get('岗位名称', '')
level = item.get('岗位等级标签', '')
if position_name and level:
position_levels[position_name] = level
print(f"已建立 {len(position_levels)} 个岗位等级映射")
# 读取视觉设计项目案例数据
with open('网页未导入数据/视觉设计产业/视觉设计项目案例.json', 'r', encoding='utf-8') as f:
visual_design_data = json.load(f)
# 生成项目列表数据
projects_js = []
for idx, item in enumerate(visual_design_data[:30], 1): # 取前30个项目
project = {
'id': idx,
'name': item['案例名称'],
'description': item.get('所属垂直方向', ''),
'positions': [pos.strip() for pos in item.get('对应个人简历名称', '').split(',') if pos.strip()],
'unit': item.get('对应单元名称(复合能力课)', ''),
'direction': item.get('所属垂直方向', ''),
'category': item.get('对应单元名称(垂直能力课)', '')
}
projects_js.append(project)
# 生成项目详情数据选择前15个有内容的项目
project_details = {}
for idx, item in enumerate(visual_design_data[:15], 1):
# 解析项目内容
content = item.get('项目案例内容', '')
sections = []
# 简单解析Markdown内容提取章节
if content:
lines = content.split('\n')
current_section = None
for line in lines:
if line.startswith('# '):
if current_section:
sections.append(current_section)
current_section = {
'title': line[2:].strip(),
'content': ''
}
elif current_section:
current_section['content'] += line + '\\n'
if current_section:
sections.append(current_section)
# 处理适用岗位,使用真实的岗位等级
positions = item.get('对应个人简历名称', '').split(',')
applicable_positions = []
for pos in positions:
pos = pos.strip()
if pos:
# 使用映射表查找实际等级
level = position_levels.get(pos, '技术骨干岗') # 默认为技术骨干岗
applicable_positions.append({
'position': pos,
'level': level
})
# 处理对应单元
corresponding_units = {
'compound': [item.get('对应单元名称(复合能力课)', '')] if item.get('对应单元名称(复合能力课)') else [],
'vertical': [item.get('对应单元名称(垂直能力课)', '')] if item.get('对应单元名称(垂直能力课)') else []
}
# 处理附件
attachments = []
if item.get('附件'):
files = item['附件'].split(',')
for file in files[:5]: # 最多显示5个附件
file = file.strip()
if file:
# 根据文件扩展名确定类型
ext = file.split('.')[-1].lower()
file_type = 'document'
if ext in ['jpg', 'jpeg', 'png', 'gif']:
file_type = 'image'
elif ext in ['mp4', 'avi', 'mov']:
file_type = 'video'
elif ext == 'pdf':
file_type = 'pdf'
elif ext in ['doc', 'docx']:
file_type = 'word'
elif ext in ['psd', 'aep']:
file_type = 'design'
elif ext in ['zip', 'rar', '7z']:
file_type = 'archive'
elif ext in ['mp3', 'wav']:
file_type = 'audio'
attachments.append({
'name': file,
'type': file_type,
'size': '2.3MB' # 模拟文件大小
})
# 截取内容摘要
overview = ''
if sections:
overview = sections[0]['content'][:300] if sections[0]['content'] else '暂无项目概述'
process = ''
if len(sections) > 1:
# 截取流程介绍的前500个字符
process = sections[1]['content'][:500] if sections[1]['content'] else '暂无流程介绍'
keyPoints = ''
if len(sections) > 2:
# 截取关键技术点的前500个字符
keyPoints = sections[2]['content'][:500] if sections[2]['content'] else '暂无关键技术点'
project_details[idx] = {
'title': item['案例名称'],
'category': item.get('所属垂直方向', ''),
'overview': overview,
'applicablePositions': applicable_positions,
'correspondingUnits': corresponding_units,
'process': process,
'keyPoints': keyPoints,
'attachments': attachments
}
# 生成JavaScript代码
js_code = '''// 项目库Mock数据
export const getMockProjectsList = (params = {}) => {
const { search = "", page = 1, pageSize = 10 } = params;
// 完整项目列表数据
const projects = '''
# 添加项目列表数组
js_code += json.dumps(projects_js, ensure_ascii=False, indent=2)
js_code += ''';
// 根据搜索条件过滤
let filteredProjects = projects;
if (search) {
filteredProjects = projects.filter(p =>
p.name.toLowerCase().includes(search.toLowerCase()) ||
p.description.toLowerCase().includes(search.toLowerCase())
);
}
// 分页
const startIndex = (page - 1) * pageSize;
const endIndex = startIndex + pageSize;
const paginatedProjects = filteredProjects.slice(startIndex, endIndex);
return {
success: true,
data: paginatedProjects,
total: filteredProjects.length,
page,
pageSize
};
};
// 获取项目详情
export const getMockProjectDetail = (id) => {
// 项目详情数据
const projectDetails = '''
# 添加项目详情对象
js_code += json.dumps(project_details, ensure_ascii=False, indent=2)
js_code += ''';
const detail = projectDetails[id];
if (detail) {
return {
success: true,
data: detail
};
}
// 如果没有找到详情返回默认数据
return {
success: true,
data: {
title: "项目详情",
category: "视觉设计",
overview: "暂无详细信息",
applicablePositions: [],
correspondingUnits: { compound: [], vertical: [] },
process: "暂无流程介绍",
keyPoints: "暂无关键技术点",
attachments: []
}
};
};
'''
# 写入文件
with open('src/mocks/projectLibraryMock.js', 'w', encoding='utf-8') as f:
f.write(js_code)
print("Mock文件已更新完成岗位等级已正确设置")
# 统计等级分布
level_stats = {}
for detail in project_details.values():
for pos in detail['applicablePositions']:
level = pos['level']
if level not in level_stats:
level_stats[level] = 0
level_stats[level] += 1
print("\n岗位等级分布统计:")
for level, count in level_stats.items():
print(f" {level}: {count}")