diffi_label.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import json
  2. import time
  3. import re
  4. import requests
  5. topic_type_dict = {"单选": 1, "多选":2, "单空":5, "多空":6, "简答":7}
  6. # 1=>单选题 2=>多选题 5=>单空题 6=>多空题 7=>解答题
  7. def get_item_diff(item_dict):
  8. """
  9. 获取一个题目的难度 1-6:超易到超难;得分率:越高越易
  10. :param item_dict: dict zyk中的试题
  11. :return:
  12. """
  13. if "checkType" in item_dict and item_dict["checkType"]:
  14. item_type_id = item_dict["checkType"]["id"]
  15. else:
  16. item_type = item_dict["type"]
  17. if item_type == "选择题":
  18. if len(re.findall("[A-E]", item_dict["key"]))>1:
  19. item_type = "多选"
  20. else:
  21. item_type = "单选"
  22. elif item_type == "填空题":
  23. if len(re.findall("_{2,}", item_dict["stem"]))>1:
  24. item_type = "多空"
  25. else:
  26. item_type = "单空"
  27. else:
  28. item_type = "简答"
  29. item_type_id = topic_type_dict[item_type]
  30. # print(item_type)
  31. if "stem" not in item_dict or not item_dict["stem"].strip():
  32. item_dict["difficulty"] = "中"
  33. return item_dict, 3
  34. url = 'http://49.232.72.198:8868/api/math/degree_of_difficulty/v1.0/level_method'
  35. headers = {'Content-Type': 'application/json', "Connection": "close"}
  36. text_dict = {'content': item_dict["stem"],
  37. 'options': item_dict["options"] if "options" in item_dict else [],
  38. 'parse': item_dict["parse"],
  39. 'topic_type_id': item_type_id,
  40. 'point_id': []} # 没有就填空列表
  41. # print(item_dict)
  42. input_data = json.dumps(text_dict)
  43. scoring_rate = -1
  44. try:
  45. response = requests.post(url, headers=headers, data=input_data, timeout=5)
  46. dif_res = json.loads(response.text)
  47. scoring_rate = float(dif_res['scoring_rate'])
  48. except:
  49. time.sleep(4)
  50. try:
  51. response = requests.post(url, headers=headers, data=input_data, timeout=5)
  52. dif_res = json.loads(response.text)
  53. scoring_rate = float(dif_res['scoring_rate'])
  54. except:
  55. pass
  56. if scoring_rate == -1:
  57. item_dict["difficulty"] = "中"
  58. return item_dict, 3
  59. # print("scoring_rate:", scoring_rate)
  60. diffi_xbk = 3
  61. item_dict["difficulty"] = "中"
  62. if scoring_rate < 3/6:
  63. diffi_xbk = 4
  64. if scoring_rate < 1 / 6:
  65. diffi_xbk = 6
  66. item_dict["difficulty"] = "难"
  67. elif scoring_rate < 2 / 6:
  68. diffi_xbk = 5
  69. item_dict["difficulty"] = "难"
  70. elif scoring_rate < 4/6:
  71. diffi_xbk = 3
  72. elif scoring_rate < 5 / 6:
  73. item_dict["difficulty"] = "易"
  74. diffi_xbk = 2
  75. else:
  76. diffi_xbk = 1
  77. item_dict["difficulty"] = "易"
  78. # item_dict['scoring_rate'] = scoring_rate
  79. return item_dict, diffi_xbk