From d66effcd461ec87c944eefb09bda26333b1ad2d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Mon, 13 Feb 2023 22:46:54 +0100 Subject: [PATCH] =?UTF-8?q?move:=20p=C5=99esunuty=20vzore=C4=8Dky=20na=20p?= =?UTF-8?q?=C5=99epo=C4=8Det=20bod=C5=AF=20do=20seminar.utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/models/odevzdavatko.py | 23 +++++++---------------- seminar/utils.py | 9 +++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/seminar/models/odevzdavatko.py b/seminar/models/odevzdavatko.py index 0fad97f8..744fe38c 100644 --- a/seminar/models/odevzdavatko.py +++ b/seminar/models/odevzdavatko.py @@ -1,4 +1,3 @@ -import decimal import os import reversion @@ -15,6 +14,8 @@ from seminar.models import personalni as pm from seminar.models import treenode as tm from seminar.models import base as bm +from seminar.utils import vzorecek_na_prepocet, inverze_vzorecku_na_prepocet + @reversion.register(ignore_duplicates=True) class Reseni(bm.SeminarModelBase): @@ -116,16 +117,6 @@ class Hodnoceni(bm.SeminarModelBase): feedback = models.TextField('zpětná vazba', blank=True, default='', help_text='Zpětná vazba řešiteli (plain text)') - # TODO najít správné místo - @staticmethod - def vzorecek_na_prepocet(body, resitelu): - return body * 3 / (resitelu + 2) - - # TODO najít správné místo - @staticmethod - def inverze_vzorecku_na_prepocet(body: decimal.Decimal, resitelu) -> decimal.Decimal: - return round(body * (resitelu + 2) / 3, 1) - @property def body_celkem(self): # FIXME řeším jen prvního řešitele. @@ -147,33 +138,33 @@ class Hodnoceni(bm.SeminarModelBase): def body_neprepocitane(self): if self.body is None: return None - return self.inverze_vzorecku_na_prepocet(self.body, self.reseni.resitele.count()) + return inverze_vzorecku_na_prepocet(self.body, self.reseni.resitele.count()) @body_neprepocitane.setter def body_neprepocitane(self, value): if value is None: self.body = None else: - self.body = self.vzorecek_na_prepocet(value, self.reseni.resitele.count()) + self.body = vzorecek_na_prepocet(value, self.reseni.resitele.count()) @property def body_neprepocitane_celkem(self): if self.body_celkem is None: return None - return self.inverze_vzorecku_na_prepocet(self.body_celkem, self.reseni.resitele.count()) + return inverze_vzorecku_na_prepocet(self.body_celkem, self.reseni.resitele.count()) @body_neprepocitane_celkem.setter def body_neprepocitane_celkem(self, value): if value is None: self.body = None else: - self.body_celkem = self.vzorecek_na_prepocet(value, self.reseni.resitele.count()) + self.body_celkem = vzorecek_na_prepocet(value, self.reseni.resitele.count()) @property def body_max(self): if self.body_neprepocitane_max is None: return None - return self.vzorecek_na_prepocet(self.body_neprepocitane_max, self.reseni.resitele.count()) + return vzorecek_na_prepocet(self.body_neprepocitane_max, self.reseni.resitele.count()) @property def body_neprepocitane_max(self): diff --git a/seminar/utils.py b/seminar/utils.py index e7d52529..4ab547ab 100644 --- a/seminar/utils.py +++ b/seminar/utils.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import datetime +import decimal from django.contrib.auth import get_user_model from django.contrib.auth.decorators import permission_required, \ @@ -44,6 +45,14 @@ AnonymousUser.je_org = False AnonymousUser.je_resitel = False +def vzorecek_na_prepocet(body, resitelu): + return body * 3 / (resitelu + 2) + + +def inverze_vzorecku_na_prepocet(body: decimal.Decimal, resitelu) -> decimal.Decimal: + return round(body * (resitelu + 2) / 3, 1) + + class FirstTagParser(HTMLParser): def __init__(self, *args, **kwargs): self.firstTag = None