You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB

from models import Database
from utils import ProbabilityCalculator, ScoreCalculator, ExcelService
class RollCallService:
def __init__(self):
self.db = Database()
self.probability_calculator = ProbabilityCalculator()
def random_roll_call(self, class_name):
"""随机点名"""
students = self.db.get_students_by_class(class_name)
if not students:
return None
selected_student = self.probability_calculator.weighted_random_selection(students)
# 记录点名
self.db.add_roll_call_record(
selected_student.student_id,
selected_student.name
)
return selected_student
def update_student_score(self, student_id, answer_type, performance):
"""更新学生积分"""
score_delta = ScoreCalculator.calculate_score(answer_type, performance)
success = self.db.update_student_score(student_id, score_delta)
if success and score_delta != 0:
student = next((s for s in self.db.get_all_students()
if s.student_id == student_id), None)
if student:
self.db.add_roll_call_record(
student_id,
student.name,
score_delta
)
return success, score_delta
class ScoreService:
def __init__(self):
self.db = Database()
self.excel_service = ExcelService()
def get_class_ranking(self, class_name):
"""获取班级积分排名"""
students = self.db.get_students_by_class(class_name)
return sorted(students, key=lambda x: x.total_score, reverse=True)
def export_scores_excel(self, class_name):
"""导出积分Excel"""
students = self.db.get_students_by_class(class_name)
return self.excel_service.export_scores(students)