marktask.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from typing import List, Any, Dict
  4. from bgtask.problem import bgtask_create_student_error_statistic
  5. from crud.marktask import crud_student_task
  6. from db.asyncsession import LocalAsyncSession
  7. # 创建学生阅卷任务
  8. async def bgtask_create_student_mark_task(task_id: int, task_type: str, students: List[Any],
  9. paper: Dict[str, Any], uid: int, username: str):
  10. print("[bgTask] Create Student MarkTask Starting!")
  11. db = LocalAsyncSession()
  12. student_errors = []
  13. for stu in students:
  14. task = dict(
  15. **{
  16. "student_id": stu.id,
  17. "student_sno": stu.sno,
  18. "student_name": stu.name,
  19. "task_id": task_id,
  20. "mtype": task_type,
  21. "pid": paper["id"],
  22. "pno": paper["pno"],
  23. "pname": paper["pname"],
  24. "pimgs": paper["imgs"],
  25. "question_amount": paper["question_amount"],
  26. "school_name": stu.school_name,
  27. "grade_name": stu.grade_name,
  28. "class_name": stu.class_name
  29. })
  30. task["creator_id"] = task["editor_id"] = uid
  31. task["creator_name"] = task["editor_name"] = username
  32. db_student_task = await crud_student_task.insert_one(db, task)
  33. error = {
  34. "school_id": stu.school_id,
  35. "school_name": stu.school_name,
  36. "grade_id": stu.grade_id,
  37. "grade_name": stu.grade_name,
  38. "class_id": stu.class_id,
  39. "class_name": stu.class_name,
  40. "student_id": stu.id,
  41. "student_sno": stu.sno,
  42. "student_name": stu.name,
  43. "total_questions": paper["question_amount"],
  44. "task_id": task_id,
  45. "student_task_id": db_student_task.id
  46. }
  47. student_errors.append(error)
  48. print(f"the student_errors: {len(student_errors)}")
  49. await bgtask_create_student_error_statistic(student_errors)
  50. print("[bgTask] Create Student MarkTask Successfully!")