1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import json
- import time
- import re
- import requests
- topic_type_dict = {"单选": 1, "多选":2, "单空":5, "多空":6, "简答":7}
- # 1=>单选题 2=>多选题 5=>单空题 6=>多空题 7=>解答题
- def get_item_diff(item_dict):
- """
- 获取一个题目的难度 1-6:超易到超难;得分率:越高越易
- :param item_dict: dict zyk中的试题
- :return:
- """
- if "checkType" in item_dict and item_dict["checkType"]:
- item_type_id = item_dict["checkType"]["id"]
- else:
- item_type = item_dict["type"]
- if item_type == "选择题":
- if len(re.findall("[A-E]", item_dict["key"]))>1:
- item_type = "多选"
- else:
- item_type = "单选"
- elif item_type == "填空题":
- if len(re.findall("_{2,}", item_dict["stem"]))>1:
- item_type = "多空"
- else:
- item_type = "单空"
- else:
- item_type = "简答"
- item_type_id = topic_type_dict[item_type]
- # print(item_type)
- if "stem" not in item_dict or not item_dict["stem"].strip():
- item_dict["difficulty"] = "中"
- return item_dict, 3
- url = 'http://49.232.72.198:8868/api/math/degree_of_difficulty/v1.0/level_method'
- headers = {'Content-Type': 'application/json', "Connection": "close"}
- text_dict = {'content': item_dict["stem"],
- 'options': item_dict["options"] if "options" in item_dict else [],
- 'parse': item_dict["parse"],
- 'topic_type_id': item_type_id,
- 'point_id': []} # 没有就填空列表
- # print(item_dict)
- input_data = json.dumps(text_dict)
- scoring_rate = -1
- try:
- response = requests.post(url, headers=headers, data=input_data, timeout=5)
- dif_res = json.loads(response.text)
- scoring_rate = float(dif_res['scoring_rate'])
- except:
- time.sleep(4)
- try:
- response = requests.post(url, headers=headers, data=input_data, timeout=5)
- dif_res = json.loads(response.text)
- scoring_rate = float(dif_res['scoring_rate'])
- except:
- pass
- if scoring_rate == -1:
- item_dict["difficulty"] = "中"
- return item_dict, 3
- # print("scoring_rate:", scoring_rate)
- diffi_xbk = 3
- item_dict["difficulty"] = "中"
- if scoring_rate < 3/6:
- diffi_xbk = 4
- if scoring_rate < 1 / 6:
- diffi_xbk = 6
- item_dict["difficulty"] = "难"
- elif scoring_rate < 2 / 6:
- diffi_xbk = 5
- item_dict["difficulty"] = "难"
- elif scoring_rate < 4/6:
- diffi_xbk = 3
- elif scoring_rate < 5 / 6:
- item_dict["difficulty"] = "易"
- diffi_xbk = 2
- else:
- diffi_xbk = 1
- item_dict["difficulty"] = "易"
- # item_dict['scoring_rate'] = scoring_rate
- return item_dict, diffi_xbk
|