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