update 问题模块bug

This commit is contained in:
P3ngSaM 2022-08-15 15:30:47 +08:00
parent fee9404567
commit c45e9e7262
1 changed files with 35 additions and 24 deletions

View File

@ -31,6 +31,11 @@ class QuestionImpl(object):
question_type = data['question_type'] question_type = data['question_type']
if question_type == '单选题-多解' or question_type == '多选题-多解': if question_type == '单选题-多解' or question_type == '多选题-多解':
if question_type == '多选题-多解':
total = [item['percentage'] for item in data['options']]
if sum(total) > 100:
return '多选多解类型得分比合计不应超过100%'
quest.options = list() quest.options = list()
for option in data['options']: for option in data['options']:
options = quest.Options() options = quest.Options()
@ -132,7 +137,7 @@ class QuestionImpl(object):
else: else:
score = 0 score = 0
desc = [des['描述'] for des in quest_data['题目选项']] desc = [des['描述'] for des in quest_data['题目选项']]
if set(answer) < set(desc): if set(answer) < set(desc) or set(answer) == set(desc):
for option_ in quest_data['题目选项']: for option_ in quest_data['题目选项']:
if option_['描述'] in answer: if option_['描述'] in answer:
if option_['得分比'] == 0: if option_['得分比'] == 0:
@ -164,7 +169,7 @@ class QuestionImpl(object):
else: else:
desc = [des['描述'] for des in quest_data['题目选项']] desc = [des['描述'] for des in quest_data['题目选项']]
right = [des['描述'] for des in quest_data['题目选项'] if des['正确'] == 1] right = [des['描述'] for des in quest_data['题目选项'] if des['正确'] == 1]
if set(answer) < set(desc): if set(answer) < set(desc) or set(answer) == set(desc):
if right == answer: if right == answer:
score = 1 score = 1
else: else:
@ -202,31 +207,37 @@ class QuestionImpl(object):
return score return score
elif question_type == '填空题-档位多解': elif question_type == '填空题-档位多解':
# 校验数据格式 # 校验数据格式
decision = data['decision_setting'] if isinstance(answer, (int, float)):
setting = quest.DecisionSetting() decision = data['decision_setting']
setting.interval = decision['interval'] setting = quest.DecisionSetting()
setting.score = decision['score'] setting.interval = decision['interval']
quest.decision_setting = setting setting.score = decision['score']
# 校验答案 quest.decision_setting = setting
quest_data = quest.fields_toggle() # 校验答案
score = 0 quest_data = quest.fields_toggle()
for index in range(len(quest_data['判定设置']['区间'])): score = 0
if eval(quest_data['判定设置']['区间'][index].replace('x', str(answer))): for index in range(len(quest_data['判定设置']['区间'])):
score = quest_data['判定设置']['得分比'][index] * 0.01 if eval(quest_data['判定设置']['区间'][index].replace('x', str(answer))):
return score score = quest_data['判定设置']['得分比'][index] * 0.01
return score
else:
return 'answer类型不能为string'
elif question_type == '填空题-指定处理': elif question_type == '填空题-指定处理':
# 校验数据格式 # 校验数据格式
decision = data['decision_setting'] if isinstance(answer, (int, float)):
setting = quest.DecisionSetting() decision = data['decision_setting']
setting.assigned = decision['assigned'] setting = quest.DecisionSetting()
quest.decision_setting = setting setting.assigned = decision['assigned']
# 校验答案 quest.decision_setting = setting
quest_data = quest.fields_toggle() # 校验答案
if eval(quest_data['判定设置']['指定处理'].replace('x', str(answer))): quest_data = quest.fields_toggle()
score = 1 if eval(quest_data['判定设置']['指定处理'].replace('x', str(answer))):
score = 1
else:
score = 0
return score
else: else:
score = 0 return 'answer类型不能为string'
return score
elif question_type == '自定义问题': elif question_type == '自定义问题':
# 校验数据格式 # 校验数据格式
input_setting = data['input_setting'] input_setting = data['input_setting']