Files
ALL-teach_sys/frontend_能源/generate_energy_mock_data.py

270 lines
9.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import re
import datetime
import shutil
def parse_interview_questions(content):
"""解析面试题内容,提取问题和答案"""
questions = []
lines = content.split('\n')
current_question = None
current_answer = []
question_id = 1
in_answer = False
for line in lines:
line = line.strip()
# 检查是否是问题行(数字+句号开头)
question_match = re.match(r'^(\d+)\.[\s ]+(.+)$', line)
if question_match:
# 保存上一个问题
if current_question and current_answer:
answer_text = '\n'.join(current_answer).strip()
if answer_text:
current_question['answer'] = answer_text
questions.append(current_question)
current_answer = []
# 创建新问题
question_text = question_match.group(2).rstrip('?')
current_question = {
'id': f'q{question_id}',
'question': question_text,
'answer': ''
}
question_id += 1
in_answer = False
# 检查是否是答案开始标记
elif '示例答案' in line or '答案:' in line or '答案:' in line:
in_answer = True
answer_in_line = re.sub(r'^.*?(示例答案|答案)[:]?\s*', '', line).strip()
if answer_in_line:
current_answer.append(answer_in_line)
# 收集答案内容
elif in_answer and current_question and line:
if not line.startswith('#'):
current_answer.append(line)
# 检查是否到达下一个部分(标题)
elif line.startswith('#') and current_question and current_answer:
answer_text = '\n'.join(current_answer).strip()
if answer_text:
current_question['answer'] = answer_text
questions.append(current_question)
current_question = None
current_answer = []
in_answer = False
# 保存最后一个问题
if current_question and current_answer:
answer_text = '\n'.join(current_answer).strip()
if answer_text:
current_question['answer'] = answer_text
questions.append(current_question)
return questions
def generate_energy_data():
"""生成能源产业的完整数据"""
# 读取能源岗位简历数据
with open("网页未导入数据/能源产业/能源岗位简历.json", 'r', encoding='utf-8') as f:
energy_jobs = json.load(f)
# 岗位级别映射
level_mapping = {
"高级": "技术骨干岗",
"中级": "技术骨干岗",
"普通": "普通岗",
"": "普通岗"
}
# 默认头像
default_avatars = [
"https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/butler_position_avatar/recuPFYfYv4rBd.jpeg",
"https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/butler_position_avatar/recuPFYfYvF54F.jpeg",
"https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/butler_position_avatar/recuPFYfYvumAH.jpeg"
]
# 按岗位群分组
groups = {}
for job in energy_jobs:
group_name = job.get("简历岗位群", "")
if group_name:
if group_name not in groups:
groups[group_name] = {
"positions": [],
"questions": None,
"templates": []
}
# 添加岗位信息
position = {
"id": f"energy_{len(groups)}_{len(groups[group_name]['positions'])+1}",
"title": job.get("岗位名称", ""),
"level": level_mapping.get(job.get("岗位等级标签", ""), "普通岗"),
"avatar": job.get("简历头像url") or default_avatars[len(groups[group_name]['positions']) % 3],
"department": group_name,
"type": "全职",
"experience": "1-3年",
"education": "大专",
"salary": "8-15K",
"location": "北京",
"updateTime": "2024-01-20",
"description": f"负责{job.get('岗位名称', '')}相关工作",
"requirements": []
}
groups[group_name]["positions"].append(position)
# 添加简历模板
template = {
"position": job.get("岗位名称", ""),
"level": level_mapping.get(job.get("岗位等级标签", ""), "普通岗"),
"avatar": job.get("简历头像url") or default_avatars[0],
"content": {
"original": job.get("简历内容", ""),
"modified": "" # 如果有修改版本可以在这里添加
},
"studentInfo": {
"project_experience": {
"project_name": "",
"position": "",
"time_period": "XXXXXX",
"company": "XXXXXX",
"description": ""
},
"core_skills": [],
"compound_skills": [],
"personal_summary": ""
}
}
groups[group_name]["templates"].append(template)
# 提取面试题(只提取一次)
if not groups[group_name]["questions"] and "面试题内容" in job:
questions = parse_interview_questions(job["面试题内容"])
groups[group_name]["questions"] = questions
# 生成industries数组
industries = []
resumeTemplates = {}
group_id = 1
for group_name, data in groups.items():
# 生成industry对象
industry = {
"id": f"energy_{group_id}",
"name": group_name,
"positions": data["positions"],
"questions": [
{
"id": f"group_q{group_id}",
"question": f"# {group_name}面试题",
"subQuestions": data["questions"] if data["questions"] else []
}
]
}
industries.append(industry)
# 添加到resumeTemplates
resumeTemplates[group_name] = data["templates"]
group_id += 1
return industries, resumeTemplates
def update_mock_file():
"""更新mock文件"""
mock_file = "src/mocks/resumeInterviewMock.js"
# 备份文件
backup_path = f"{mock_file}.backup_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}"
shutil.copy(mock_file, backup_path)
print(f"✅ 已备份文件到:{backup_path}")
# 生成新数据
industries, resumeTemplates = generate_energy_data()
# 生成完整的mock文件内容
content = '''// 简历与面试题Mock数据
// 岗位群列表
const industries = %s;
// 简历模板数据
const resumeTemplates = %s;
// 我的简历数据
const myResume = {
personalInfo: {
name: "王强",
phone: "138****8888",
email: "wangqiang@example.com",
age: 22,
education: "苏州健雄职业技术学院 2020.9-2023.6",
experience: "应届毕业生",
location: "苏州"
},
workExperience: [
{
company: "苏州某智能制造企业",
position: "模具设计与制造实习生",
duration: "2023.03-2023.06",
description: "负责模具设计与制造相关工作"
}
],
skills: ["模具设计", "机械制图", "CAD/CAM", "数控编程"],
projects: []
};
export const resumeInterviewService = {
getIndustries: async () => {
// 模拟API调用延迟
await new Promise((resolve) => setTimeout(resolve, 500));
return industries;
},
};
// 导出合并的数据
export const resumeInterviewMockData = {
industries,
resumeTemplates,
myResume
};
export function getMockPageData() {
return resumeInterviewMockData;
}
export { myResume };
''' % (json.dumps(industries, ensure_ascii=False, indent=2),
json.dumps(resumeTemplates, ensure_ascii=False, indent=2))
# 写入新文件
with open(mock_file, 'w', encoding='utf-8') as f:
f.write(content)
print("✅ 成功生成能源产业mock数据")
# 统计结果
print("\n📊 数据统计:")
print(f" - 岗位群数量: {len(industries)}")
print(f" - 岗位总数: {sum(len(ind['positions']) for ind in industries)}")
print(f" - 面试题总数: {sum(len(ind['questions'][0]['subQuestions']) for ind in industries if ind['questions'])}")
print("\n📋 岗位群列表:")
for ind in industries:
q_count = len(ind['questions'][0]['subQuestions']) if ind['questions'] else 0
print(f" - {ind['name']}: {len(ind['positions'])}个岗位, {q_count}个面试题")
if __name__ == "__main__":
update_mock_file()