|
|
|
|
import pandas as pd
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
# 加载学生名单,从Excel文件导入
|
|
|
|
|
def load_students(file_path):
|
|
|
|
|
df = pd.read_excel(file_path)
|
|
|
|
|
# Excel文件有两列:'姓名' 和 '学号'
|
|
|
|
|
students = df.to_dict('records')
|
|
|
|
|
for student in students:
|
|
|
|
|
student['积分'] = 0 # 初始化每位学生的积分为0
|
|
|
|
|
return students
|
|
|
|
|
|
|
|
|
|
# 保存学生名单,更新积分后导出到Excel
|
|
|
|
|
def save_students(students, file_path):
|
|
|
|
|
df = pd.DataFrame(students)
|
|
|
|
|
df.to_excel(file_path, index=False)
|
|
|
|
|
|
|
|
|
|
# 根据积分设置每个学生的被选概率,积分越高,权重越低
|
|
|
|
|
def get_student_weights(students):
|
|
|
|
|
max_score = max([s['积分'] for s in students])
|
|
|
|
|
weights = [(max_score - s['积分'] + 1) for s in students] # 权重为 max_score - 当前积分 + 1
|
|
|
|
|
return weights
|
|
|
|
|
|
|
|
|
|
# 随机点名
|
|
|
|
|
def pick_student(students):
|
|
|
|
|
weights = get_student_weights(students)
|
|
|
|
|
picked_student = random.choices(students, weights=weights, k=1)[0]
|
|
|
|
|
print(f"点到学生: {picked_student['姓名']} (学号: {picked_student['学号']})")
|
|
|
|
|
return picked_student
|
|
|
|
|
|
|
|
|
|
# 增加到达课堂的积分
|
|
|
|
|
def update_attendance_score(student):
|
|
|
|
|
student['积分'] += 1
|
|
|
|
|
print(f"{student['姓名']} 到达课堂,积分 +1,总积分: {student['积分']}")
|
|
|
|
|
|
|
|
|
|
# 处理回答问题的积分
|
|
|
|
|
def update_answer_score(student, repeated_question_correctly, answer_score):
|
|
|
|
|
if repeated_question_correctly:
|
|
|
|
|
student['积分'] += 0.5
|
|
|
|
|
print(f"{student['姓名']} 正确重复问题,积分 +0.5")
|
|
|
|
|
else:
|
|
|
|
|
student['积分'] -= 1
|
|
|
|
|
print(f"{student['姓名']} 未能正确重复问题,积分 -1")
|
|
|
|
|
|
|
|
|
|
student['积分'] += answer_score
|
|
|
|
|
print(f"{student['姓名']} 回答问题,加 {answer_score} 分,总积分: {student['积分']}")
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
# Excel 文件路径
|
|
|
|
|
file_path = 'students.xlsx'
|
|
|
|
|
|
|
|
|
|
# 加载学生数据
|
|
|
|
|
students = load_students(file_path)
|
|
|
|
|
|
|
|
|
|
# 随机点名
|
|
|
|
|
picked_student = pick_student(students)
|
|
|
|
|
|
|
|
|
|
# 假设学生到达课堂 客户端反馈是否调用函数
|
|
|
|
|
update_attendance_score(picked_student)
|
|
|
|
|
|
|
|
|
|
# 假设学生回答问题 客户端反馈具体答题情况再调用函数
|
|
|
|
|
repeated_correctly = True # 假设学生正确重复了问题
|
|
|
|
|
answer_score = 2.0 # 假设学生回答问题的得分是2分
|
|
|
|
|
update_answer_score(picked_student, repeated_correctly, answer_score)
|
|
|
|
|
|
|
|
|
|
# 保存更新后的数据回到 Excel 文件
|
|
|
|
|
save_students(students, file_path)
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|