gen_data.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import ujson
  2. import time
  3. from typing import Dict, List, Any
  4. from random import sample,random
  5. def encapsulate(op_type: int, data: Dict[str, Any]) -> str:
  6. e_log = {
  7. "target": 1, # 暂时只有smart这一个target
  8. "source": 0, # 暂时只有eval这一个source
  9. "op_type": op_type,
  10. "created_time": "2021-12-29 17:15:00",
  11. "data": ujson.dumps(data),
  12. "message": ""
  13. }
  14. return ujson.dumps(e_log)
  15. def get_question_list() -> List[str]:
  16. return ['d8009eb4-5833-424d-91c3-7dbc160a2a0a', 'b58e18a6-18f5-42b6-ab45-3ecbcb4c97ca', '290dc9de58cd4a37b9a7a52847ccd1ce',
  17. '742fa61f-8c6f-4f62-a997-e5900263f77b', '724eddaa-9414-4803-8920-579416eccccc', '27019', '21016', '3026', '19037', '19035', '19033', '19031',
  18. '19030', 'JL-56nwBGvo2WgFx-3pf', 'I7-56nwBGvo2WgFx-3pf', 'Ir-56nwBGvo2WgFx-3pf', 'Ib-56nwBGvo2WgFx-3pf', 'Hb-u5nwBGvo2WgFxV3ps', 'Hr-u5nwBGvo2WgFxV3pt']
  19. class Exam(object):
  20. def __init__(self, exam_id, exam_score, questions):
  21. self.exam_id = exam_id
  22. self.exam_score = exam_score
  23. self.questions = questions
  24. self.difficulty = 1
  25. self.update_time = "2021-09-29 17:15:00"
  26. self.start_time = "2021-09-29 17:15:00"
  27. self.end_time = "2021-09-29 19:15:00"
  28. class Question(object):
  29. def __init__(self, question_id, question_score):
  30. self.question_id = question_id
  31. self.question_score = question_score
  32. class Answer(object):
  33. def __init__(self, exam_id, student_id, score, error_ques):
  34. self.exam_id = exam_id
  35. self.student_id = student_id
  36. self.submit_time = "2021-11-03 00:58:03"
  37. self.score = score
  38. self.error_ques = error_ques
  39. class ErrorQuestion(object):
  40. def __init__(self, question_id, actual_score):
  41. self.question_id = question_id
  42. self.question_score = actual_score
  43. def mock():
  44. # 教师提交试题A
  45. j0 = '{"exam_id":1,"exam_score":100,"questions":[{"question_id":"d8009eb4-5833-424d-91c3-7dbc160a2a0a","question_score":12.5},{"question_id":"b58e18a6-18f5-42b6-ab45-3ecbcb4c97ca","question_score":12.5},{"question_id":"290dc9de58cd4a37b9a7a52847ccd1ce","question_score":12.5},{"question_id":"742fa61f-8c6f-4f62-a997-e5900263f77b","question_score":12.5},{"question_id":"724eddaa-9414-4803-8920-579416eccccc","question_score":12.5},{"question_id":"27019","question_score":12.5},{"question_id":"21016","question_score":12.5},{"question_id":"3026","question_score":12.5}],"difficulty":0,"update_time":"2021-09-29 17:15:00","start_time":"2021-09-29 17:15:00","end_time":"2021-09-29 19:15:00"}'
  46. # 教师提交试题A的修改
  47. j1 = '{"exam_id":1,"exam_score":100,"questions":[{"question_id":"d8009eb4-5833-424d-91c3-7dbc160a2a0a","question_score":12.5},{"question_id":"b58e18a6-18f5-42b6-ab45-3ecbcb4c97ca","question_score":12.5},{"question_id":"290dc9de58cd4a37b9a7a52847ccd1ce","question_score":12.5},{"question_id":"742fa61f-8c6f-4f62-a997-e5900263f77b","question_score":12.5},{"question_id":"724eddaa-9414-4803-8920-579416eccccc","question_score":12.5},{"question_id":"27019","question_score":12.5},{"question_id":"21016","question_score":12.5},{"question_id":"3026","question_score":12.5}],"difficulty":0,"update_time":"2021-09-29 18:15:00","start_time":"2021-11-03 0:15:00","end_time":"2021-11-03 19:15:00"}'
  48. # 学生1提交试题A的解答
  49. j2 = '{"exam_id":1,"student_id":1032,"submit_time":"2021-11-03 10:25:38","score":62.5,"error_ques":[{"question_id":"290dc9de58cd4a37b9a7a52847ccd1ce","actual_score":0.0},{"question_id":"21016","actual_score":0.0},{"question_id":"3026","actual_score":0.0}]}'
  50. # 学生2提交试题A的解答
  51. j3 = '{"exam_id":1,"student_id":1458,"submit_time":"2021-11-03 00:58:03","score":62.5,"error_ques":[{"question_id":"27019","actual_score":0.0},{"question_id":"21016","actual_score":0.0}]}'
  52. j_strs = [j0, j1, j2, j3]
  53. op_types = [0,1,2,2]
  54. for i in range(4):
  55. with open("mock{}.log".format(i), "w") as f:
  56. f.write(encapsulate(op_types[i], ujson.loads(j_strs[i])))
  57. def main():
  58. question_list = get_question_list()
  59. total_count = 0
  60. for i in range(2, 20): # randomly generate exams
  61. ques = sample(question_list, int(8*random())+4)
  62. e = Exam(i, len(ques), [Question(q, 1).__dict__ for q in ques])
  63. with open("gen{}.log".format(total_count), "w") as f:
  64. f.write(encapsulate(0, e.__dict__))
  65. total_count += 1
  66. for j in ["1032", "1458"]:
  67. error_ques = sample(ques, int(len(ques)*random()))
  68. a = Answer(i, j, e.exam_score - len(error_ques), [ErrorQuestion(e, 0).__dict__ for e in error_ques])
  69. with open("gen{}.log".format(total_count), "w") as f:
  70. f.write(encapsulate(2, a.__dict__))
  71. total_count += 1
  72. if __name__ == '__main__':
  73. # mock()
  74. main()