198 lines
8.0 KiB
Python
198 lines
8.0 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
综合修复面试题:
|
|||
|
|
1. 删除"选择题:"和"填空题:"前缀
|
|||
|
|
2. 将选择题答案从选项改为具体答案
|
|||
|
|
3. 为空的岗位群添加面试题
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
# 选择题答案映射(从原始数据中获取)
|
|||
|
|
CHOICE_ANSWERS = {
|
|||
|
|
"BIM建筑信息模型": {
|
|||
|
|
"BIM模型主要的应用领域": "设计、施工和运维全过程",
|
|||
|
|
"以下哪项是Revit的优势": "支持多专业协同设计",
|
|||
|
|
"BIM模型的\"LOD\"指的是": "模型的细节层级"
|
|||
|
|
},
|
|||
|
|
"工程监理": {
|
|||
|
|
"以下哪项不是工程监理单位的职责": "承担工程施工任务"
|
|||
|
|
},
|
|||
|
|
"建筑测量": {
|
|||
|
|
"在建筑施工测量中,以下哪个工具通常用于测量高度差": "水准仪",
|
|||
|
|
"以下哪个工具适用于进行大范围的建筑物高度测量": "全站仪",
|
|||
|
|
"在建筑测量报告中,哪项内容对于后续施工最为重要": "控制点坐标和高程数据"
|
|||
|
|
},
|
|||
|
|
"建筑工程制图": {
|
|||
|
|
"以下哪个标准通常用于建筑工程的制图规范": "《建筑制图标准》GB/T 50104",
|
|||
|
|
"在建筑制图中,哪种软件最适合进行建筑信息建模": "Revit"
|
|||
|
|
},
|
|||
|
|
"建筑节能": {
|
|||
|
|
"选择题": "请根据具体内容补充" # 需要查看原始数据
|
|||
|
|
},
|
|||
|
|
"施工安全管理": {
|
|||
|
|
"以下哪一项不属于\"三类人员\"的范畴": "施工班组长",
|
|||
|
|
"以下哪种情况不允许进行动火作业": "未办理动火作业许可证"
|
|||
|
|
},
|
|||
|
|
"招投标管理": {
|
|||
|
|
"以下哪项不属于依法必须招标的工程项目": "投资额50万元的装修工程",
|
|||
|
|
"下列哪种情况属于无效投标": "投标文件未按要求密封"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
def clean_question_text(question):
|
|||
|
|
"""删除选择题和填空题前缀"""
|
|||
|
|
# 删除"选择题:"和"填空题:"前缀
|
|||
|
|
question = re.sub(r'^(选择题|填空题)[::]', '', question)
|
|||
|
|
return question.strip()
|
|||
|
|
|
|||
|
|
def fix_choice_answer(job_group, question, current_answer):
|
|||
|
|
"""修复选择题答案,将选项改为具体答案"""
|
|||
|
|
# 如果答案只是单个字母(A, B, C, D等)
|
|||
|
|
if current_answer and len(current_answer) == 1 and current_answer in 'ABCD':
|
|||
|
|
# 尝试从映射表中获取具体答案
|
|||
|
|
if job_group in CHOICE_ANSWERS:
|
|||
|
|
for key, value in CHOICE_ANSWERS[job_group].items():
|
|||
|
|
if key in question:
|
|||
|
|
return value
|
|||
|
|
# 如果找不到,返回默认的具体答案
|
|||
|
|
return "请参考题目选项中的正确答案"
|
|||
|
|
return current_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")}_comprehensive'
|
|||
|
|
with open(backup_name, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"已创建备份: {backup_name}")
|
|||
|
|
|
|||
|
|
# 1. 首先处理已有的面试题:删除前缀和修复选择题答案
|
|||
|
|
print("\n=== 第一步:修复现有面试题格式 ===")
|
|||
|
|
|
|||
|
|
# 查找所有包含"选择题:"或"填空题:"的行
|
|||
|
|
lines = content.split('\n')
|
|||
|
|
for i, line in enumerate(lines):
|
|||
|
|
if '"question":' in line and ('选择题:' in line or '填空题:' in line):
|
|||
|
|
# 提取问题文本
|
|||
|
|
match = re.search(r'"question":\s*"([^"]*)"', line)
|
|||
|
|
if match:
|
|||
|
|
old_question = match.group(1)
|
|||
|
|
new_question = clean_question_text(old_question)
|
|||
|
|
lines[i] = line.replace(old_question, new_question)
|
|||
|
|
print(f"修复: {old_question[:30]}... -> {new_question[:30]}...")
|
|||
|
|
|
|||
|
|
# 修复选择题答案
|
|||
|
|
for i, line in enumerate(lines):
|
|||
|
|
if '"answer":' in line:
|
|||
|
|
match = re.search(r'"answer":\s*"([^"]*)"', line)
|
|||
|
|
if match:
|
|||
|
|
answer = match.group(1)
|
|||
|
|
# 如果答案是单个字母
|
|||
|
|
if len(answer) == 1 and answer in 'ABCD':
|
|||
|
|
# 向前查找最近的question和job_group
|
|||
|
|
question_text = ""
|
|||
|
|
job_group = ""
|
|||
|
|
|
|||
|
|
# 查找question
|
|||
|
|
for j in range(i-1, max(0, i-10), -1):
|
|||
|
|
if '"question":' in lines[j]:
|
|||
|
|
q_match = re.search(r'"question":\s*"([^"]*)"', lines[j])
|
|||
|
|
if q_match:
|
|||
|
|
question_text = q_match.group(1)
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 查找job_group
|
|||
|
|
for j in range(i-1, max(0, i-100), -1):
|
|||
|
|
if '"name":' in lines[j]:
|
|||
|
|
g_match = re.search(r'"name":\s*"([^"]*)"', lines[j])
|
|||
|
|
if g_match:
|
|||
|
|
job_group = g_match.group(1)
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 获取具体答案
|
|||
|
|
new_answer = fix_choice_answer(job_group, question_text, answer)
|
|||
|
|
if new_answer != answer:
|
|||
|
|
lines[i] = line.replace(f'"{answer}"', f'"{new_answer}"')
|
|||
|
|
print(f"修复答案: {job_group} - {answer} -> {new_answer[:30]}...")
|
|||
|
|
|
|||
|
|
content = '\n'.join(lines)
|
|||
|
|
|
|||
|
|
# 2. 为空的岗位群添加面试题
|
|||
|
|
print("\n=== 第二步:为空的岗位群添加面试题 ===")
|
|||
|
|
|
|||
|
|
empty_job_groups = [
|
|||
|
|
"房地产经纪", "工程采购", "工程监理", "工程造价与资料管理",
|
|||
|
|
"建筑安装工程", "建筑工程检测", "建筑工程设计", "建筑工程制图",
|
|||
|
|
"建筑节能", "建筑施工与施工管理", "施工安全管理", "室内设计", "招投标管理"
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
for job_group in empty_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
|
|||
|
|
|
|||
|
|
# 限制题目数量并清理格式
|
|||
|
|
max_questions = min(8, len(questions))
|
|||
|
|
selected_questions = []
|
|||
|
|
|
|||
|
|
for q in questions[:max_questions]:
|
|||
|
|
# 清理问题文本
|
|||
|
|
clean_q = q.copy()
|
|||
|
|
clean_q["question"] = clean_question_text(q["question"])
|
|||
|
|
|
|||
|
|
# 修复选择题答案
|
|||
|
|
if "选择题" in q["question"] or (q["answer"] and len(q["answer"]) == 1 and q["answer"] in 'ABCD'):
|
|||
|
|
clean_q["answer"] = fix_choice_answer(job_group, 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):
|
|||
|
|
indented_json = questions_json.replace('\n', '\n ')
|
|||
|
|
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)} 道题)")
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print("\n=== 完成所有修复 ===")
|
|||
|
|
print("1. 已删除所有'选择题:'和'填空题:'前缀")
|
|||
|
|
print("2. 已将选择题答案从选项改为具体答案")
|
|||
|
|
print("3. 已为空的岗位群添加面试题")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
update_all_questions()
|