176 lines
6.1 KiB
Python
176 lines
6.1 KiB
Python
|
|
#!/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_clean_mock():
|
|||
|
|
"""生成干净的mock文件"""
|
|||
|
|
|
|||
|
|
# 读取能源岗位简历数据
|
|||
|
|
with open("网页未导入数据/能源产业/能源岗位简历.json", 'r', encoding='utf-8') as f:
|
|||
|
|
energy_jobs = json.load(f)
|
|||
|
|
|
|||
|
|
# 按岗位群分组
|
|||
|
|
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
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 添加岗位信息
|
|||
|
|
position = {
|
|||
|
|
"id": f"energy_{len(groups)}_{len(groups[group_name]['positions'])+1}",
|
|||
|
|
"title": job.get("岗位名称", ""),
|
|||
|
|
"level": job.get("岗位级别", "基础岗"),
|
|||
|
|
"avatar": job.get("岗位头像", "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/butler_position_avatar/recuPFYfYv4rBd.jpeg"),
|
|||
|
|
"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)
|
|||
|
|
|
|||
|
|
# 提取面试题
|
|||
|
|
if not groups[group_name]["questions"] and "面试题内容" in job:
|
|||
|
|
questions = parse_interview_questions(job["面试题内容"])
|
|||
|
|
# 自动化控制只保留10个问题
|
|||
|
|
if group_name == "自动化控制" and len(questions) > 10:
|
|||
|
|
questions = questions[:10]
|
|||
|
|
groups[group_name]["questions"] = questions
|
|||
|
|
|
|||
|
|
# 生成industries数组
|
|||
|
|
industries = []
|
|||
|
|
group_id = 1
|
|||
|
|
for group_name, data in groups.items():
|
|||
|
|
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)
|
|||
|
|
group_id += 1
|
|||
|
|
|
|||
|
|
# 生成完整的mock文件内容
|
|||
|
|
content = '''// 简历与面试题Mock数据
|
|||
|
|
|
|||
|
|
// 岗位群列表
|
|||
|
|
const industries = %s;
|
|||
|
|
|
|||
|
|
export const resumeInterviewService = {
|
|||
|
|
getIndustries: async () => {
|
|||
|
|
// 模拟API调用延迟
|
|||
|
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|||
|
|
return industries;
|
|||
|
|
},
|
|||
|
|
};
|
|||
|
|
''' % json.dumps(industries, ensure_ascii=False, indent=2)
|
|||
|
|
|
|||
|
|
# 备份当前文件
|
|||
|
|
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}")
|
|||
|
|
|
|||
|
|
# 写入新文件
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print("✅ 成功生成干净的mock文件")
|
|||
|
|
|
|||
|
|
# 统计结果
|
|||
|
|
print("\n📊 各岗位群统计:")
|
|||
|
|
total_questions = 0
|
|||
|
|
for industry in industries:
|
|||
|
|
q_count = len(industry["questions"][0]["subQuestions"]) if industry["questions"] else 0
|
|||
|
|
total_questions += q_count
|
|||
|
|
print(f" - {industry['name']}: {len(industry['positions'])}个岗位, {q_count}个面试题")
|
|||
|
|
|
|||
|
|
print(f"\n📈 总计:{len(industries)}个岗位群,{total_questions}个面试题")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
generate_clean_mock()
|