125 lines
4.5 KiB
Python
125 lines
4.5 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
移除所有选择题(答案为"请参考题目选项中的正确答案"或类似内容的题目)
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
def remove_choice_questions():
|
|||
|
|
# 读取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")}_before_remove_choice'
|
|||
|
|
with open(backup_name, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"已创建备份: {backup_name}")
|
|||
|
|
|
|||
|
|
# 读取面试题数据,重新生成不包含选择题的数据
|
|||
|
|
with open('interview_questions_data.json', 'r', encoding='utf-8') as f:
|
|||
|
|
interview_data = json.load(f)
|
|||
|
|
|
|||
|
|
# 所有岗位群
|
|||
|
|
all_job_groups = [
|
|||
|
|
"BIM建筑信息模型",
|
|||
|
|
"房地产经纪",
|
|||
|
|
"工程采购",
|
|||
|
|
"工程监理",
|
|||
|
|
"工程造价与资料管理",
|
|||
|
|
"建筑安装工程",
|
|||
|
|
"建筑测量",
|
|||
|
|
"建筑工程检测",
|
|||
|
|
"建筑工程设计",
|
|||
|
|
"建筑工程制图",
|
|||
|
|
"建筑节能",
|
|||
|
|
"建筑施工与施工管理",
|
|||
|
|
"施工安全管理",
|
|||
|
|
"室内设计",
|
|||
|
|
"招投标管理"
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
lines = content.split('\n')
|
|||
|
|
|
|||
|
|
for job_group in all_job_groups:
|
|||
|
|
if job_group not in interview_data:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
questions = interview_data[job_group]
|
|||
|
|
if not questions:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 过滤掉选择题(答案是单字母或包含"选择题"关键词的)
|
|||
|
|
filtered_questions = []
|
|||
|
|
for q in questions:
|
|||
|
|
# 跳过选择题
|
|||
|
|
if (q.get("answer") and len(q["answer"]) == 1 and q["answer"] in 'ABCD'):
|
|||
|
|
continue
|
|||
|
|
if "选择题" in q.get("question", ""):
|
|||
|
|
continue
|
|||
|
|
if "以下哪" in q.get("question", ""):
|
|||
|
|
continue
|
|||
|
|
if "下列哪" in q.get("question", ""):
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 清理题目文本
|
|||
|
|
clean_q = {
|
|||
|
|
"id": q["id"],
|
|||
|
|
"question": re.sub(r'^(选择题|填空题|判断题|问答题|情景题|案例|模拟)[::]', '', q["question"]).strip(),
|
|||
|
|
"answer": q["answer"]
|
|||
|
|
}
|
|||
|
|
filtered_questions.append(clean_q)
|
|||
|
|
|
|||
|
|
if not filtered_questions:
|
|||
|
|
print(f"警告: {job_group} 移除选择题后没有剩余题目")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 构建新的questions对象
|
|||
|
|
questions_obj = [{
|
|||
|
|
"id": f"group_{job_group}_q1",
|
|||
|
|
"question": f"{job_group}面试题",
|
|||
|
|
"subQuestions": filtered_questions
|
|||
|
|
}]
|
|||
|
|
|
|||
|
|
# 查找并替换
|
|||
|
|
for i, line in enumerate(lines):
|
|||
|
|
if f'"name": "{job_group}"' in line:
|
|||
|
|
# 找到岗位群,查找questions字段
|
|||
|
|
for j in range(i, min(i + 300, len(lines))):
|
|||
|
|
if '"questions":' in lines[j]:
|
|||
|
|
# 找到questions开始位置
|
|||
|
|
if '[' in lines[j]:
|
|||
|
|
# 找到对应的结束位置
|
|||
|
|
bracket_count = 1
|
|||
|
|
end_line = j + 1
|
|||
|
|
while end_line < len(lines) and bracket_count > 0:
|
|||
|
|
if '[' in lines[end_line]:
|
|||
|
|
bracket_count += lines[end_line].count('[')
|
|||
|
|
if ']' in lines[end_line]:
|
|||
|
|
bracket_count -= lines[end_line].count(']')
|
|||
|
|
if bracket_count == 0:
|
|||
|
|
break
|
|||
|
|
end_line += 1
|
|||
|
|
|
|||
|
|
# 生成新的JSON
|
|||
|
|
questions_json = json.dumps(questions_obj, ensure_ascii=False, indent=4)
|
|||
|
|
indented_json = questions_json.replace('\n', '\n ')
|
|||
|
|
|
|||
|
|
# 替换
|
|||
|
|
del lines[j:end_line+1]
|
|||
|
|
lines.insert(j, ' "questions": ' + indented_json)
|
|||
|
|
print(f"✓ 已更新: {job_group} (剩余 {len(filtered_questions)} 道非选择题)")
|
|||
|
|
break
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write('\n'.join(lines))
|
|||
|
|
|
|||
|
|
print("\n完成!已移除所有选择题")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
remove_choice_questions()
|