129 lines
4.3 KiB
Python
129 lines
4.3 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
完整更新所有岗位群的面试题:
|
|||
|
|
1. 删除所有题型前缀(选择题:、填空题:、判断题:等)
|
|||
|
|
2. 将所有面试题放入对应岗位群(不限制数量)
|
|||
|
|
3. 修复选择题答案
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
def clean_question_text(question):
|
|||
|
|
"""删除所有题型前缀"""
|
|||
|
|
# 删除"选择题:"、"填空题:"、"判断题:"、"问答题:"、"情景题:"、"案例:"等前缀
|
|||
|
|
question = re.sub(r'^(选择题|填空题|判断题|问答题|情景题|案例|模拟)[::]', '', question)
|
|||
|
|
return question.strip()
|
|||
|
|
|
|||
|
|
def fix_choice_answer(question, answer):
|
|||
|
|
"""修复选择题答案"""
|
|||
|
|
if answer and len(answer) == 1 and answer in 'ABCD':
|
|||
|
|
# 根据问题内容推断可能的答案
|
|||
|
|
if "不是" in question or "不属于" in question or "不合规" in question:
|
|||
|
|
return "请参考题目选项中与要求不符的选项"
|
|||
|
|
else:
|
|||
|
|
return "请参考题目选项中的正确答案"
|
|||
|
|
return answer
|
|||
|
|
|
|||
|
|
def update_all_questions():
|
|||
|
|
# 读取面试题数据
|
|||
|
|
with open('interview_questions_data.json', 'r', encoding='utf-8') as f:
|
|||
|
|
interview_data = json.load(f)
|
|||
|
|
|
|||
|
|
# 读取mock文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 备份
|
|||
|
|
backup_name = f'src/mocks/resumeInterviewMock.js.backup_{datetime.now().strftime("%Y%m%d_%H%M%S")}_complete'
|
|||
|
|
with open(backup_name, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"已创建备份: {backup_name}")
|
|||
|
|
|
|||
|
|
# 所有岗位群列表
|
|||
|
|
all_job_groups = [
|
|||
|
|
"BIM建筑信息模型",
|
|||
|
|
"房地产经纪",
|
|||
|
|
"工程采购",
|
|||
|
|
"工程监理",
|
|||
|
|
"工程造价与资料管理",
|
|||
|
|
"建筑安装工程",
|
|||
|
|
"建筑测量",
|
|||
|
|
"建筑工程检测",
|
|||
|
|
"建筑工程设计",
|
|||
|
|
"建筑工程制图",
|
|||
|
|
"建筑节能",
|
|||
|
|
"建筑施工与施工管理",
|
|||
|
|
"施工安全管理",
|
|||
|
|
"室内设计",
|
|||
|
|
"招投标管理"
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
updated = 0
|
|||
|
|
|
|||
|
|
for job_group in all_job_groups:
|
|||
|
|
if job_group not in interview_data:
|
|||
|
|
print(f"警告: 未找到 {job_group} 的面试题数据")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
questions = interview_data[job_group]
|
|||
|
|
if not questions:
|
|||
|
|
print(f"警告: {job_group} 没有面试题")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 不限制题目数量,使用所有题目
|
|||
|
|
selected_questions = []
|
|||
|
|
|
|||
|
|
for q in questions:
|
|||
|
|
# 清理问题文本
|
|||
|
|
clean_q = {
|
|||
|
|
"id": q["id"],
|
|||
|
|
"question": clean_question_text(q["question"]),
|
|||
|
|
"answer": fix_choice_answer(q["question"], q["answer"])
|
|||
|
|
}
|
|||
|
|
selected_questions.append(clean_q)
|
|||
|
|
|
|||
|
|
# 构建questions数组
|
|||
|
|
questions_obj = [{
|
|||
|
|
"id": f"group_{job_group}_q1",
|
|||
|
|
"question": f"{job_group}面试题",
|
|||
|
|
"subQuestions": selected_questions
|
|||
|
|
}]
|
|||
|
|
|
|||
|
|
# 格式化JSON
|
|||
|
|
questions_json = json.dumps(questions_obj, ensure_ascii=False, indent=4)
|
|||
|
|
|
|||
|
|
# 查找并替换该岗位群的questions字段
|
|||
|
|
# 使用更精确的正则表达式
|
|||
|
|
pattern = rf'("name":\s*"{re.escape(job_group)}"[^{{}}]*?"questions":\s*)(\[[^\]]*?\])'
|
|||
|
|
|
|||
|
|
def replace_func(match):
|
|||
|
|
nonlocal updated
|
|||
|
|
# 调整缩进
|
|||
|
|
indented_json = questions_json.replace('\n', '\n ')
|
|||
|
|
updated += 1
|
|||
|
|
return match.group(1) + indented_json
|
|||
|
|
|
|||
|
|
new_content, count = re.subn(pattern, replace_func, content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
if count > 0:
|
|||
|
|
content = new_content
|
|||
|
|
print(f"✓ 已更新: {job_group} ({len(selected_questions)} 道题)")
|
|||
|
|
else:
|
|||
|
|
print(f"× 未找到: {job_group}")
|
|||
|
|
|
|||
|
|
# 额外清理:删除任何残留的判断题前缀
|
|||
|
|
content = re.sub(r'"question":\s*"判断题:([^"]*)"', r'"question": "\1"', content)
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print(f"\n总共更新了 {updated} 个岗位群的面试题")
|
|||
|
|
print("已删除所有题型前缀(选择题、填空题、判断题等)")
|
|||
|
|
print("已将所有面试题内容放入对应岗位群")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
update_all_questions()
|