From 3c2e89689f27c59251b19972adafeb035ddc3178 Mon Sep 17 00:00:00 2001 From: p6fxi93qh <1240380517@qq.com> Date: Sat, 12 Oct 2024 18:33:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=80=A7=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=90=8E=E7=9A=84=E5=87=BD=E6=95=B0=EF=BC=8C=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E6=8E=89=E8=80=97=E6=97=B6=E5=A4=A7=E7=9A=84=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- myproject/app01/models.py | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/myproject/app01/models.py b/myproject/app01/models.py index c0356e1..d534cd2 100644 --- a/myproject/app01/models.py +++ b/myproject/app01/models.py @@ -158,24 +158,24 @@ class Student(models.Model): sts.update(probability = (1 - (F('credit') - min_credit)/fm)) #耗时最大,性能改进前的代码 - def updateinfor (self,point,class_name,sid,style): #更新积分和概率 - if style == 1 : - point = point - if style == 2 : - point = point * 2 - #先改变该学生的积分值 - current_s = Student.objects.filter(class_name=class_name, sid=sid).first() - current_credit = current_s.credit - current_s.credit = current_credit + point - current_s.save() - #查找最新的最大或最小值,与原来写在表中的上次更新的最大值和最小值做对比 - max_credit = Student.objects.filter(class_name=class_name).aggregate(max_credit=Max('credit'))['max_credit'] - min_credit = Student.objects.filter(class_name=class_name).aggregate(min_credit=Min('credit'))['min_credit'] - fm = max_credit - min_credit #最新的分母 - sts = Student.objects.filter(class_name=class_name) - sts.update(min=min_credit, max=max_credit) - # 更新所有学生的概率 - if fm == 0: - sts.update(probability=1.0) - else: - sts.update(probability=(1 - (F('credit') - min_credit) / fm)) \ No newline at end of file +# def updateinfor (self,point,class_name,sid,style): #更新积分和概率 +# if style == 1 : +# point = point +# if style == 2 : +# point = point * 2 +# #先改变该学生的积分值 +# current_s = Student.objects.filter(class_name=class_name, sid=sid).first() +# current_credit = current_s.credit +# current_s.credit = current_credit + point +# current_s.save() +# #查找最新的最大或最小值,与原来写在表中的上次更新的最大值和最小值做对比 +# max_credit = Student.objects.filter(class_name=class_name).aggregate(max_credit=Max('credit'))['max_credit'] +# min_credit = Student.objects.filter(class_name=class_name).aggregate(min_credit=Min('credit'))['min_credit'] +# fm = max_credit - min_credit #最新的分母 +# sts = Student.objects.filter(class_name=class_name) +# sts.update(min=min_credit, max=max_credit) +# # 更新所有学生的概率 +# if fm == 0: +# sts.update(probability=1.0) +# else: +# sts.update(probability=(1 - (F('credit') - min_credit) / fm)) \ No newline at end of file