diff --git a/django_lostplaces/lostplaces/models/place.py b/django_lostplaces/lostplaces/models/place.py index 140fb9f..191d849 100644 --- a/django_lostplaces/lostplaces/models/place.py +++ b/django_lostplaces/lostplaces/models/place.py @@ -1,11 +1,13 @@ import os -from math import floor +import datetime +from math import round, ceil from django.db import models from django.urls import reverse from django.dispatch import receiver from django.db.models.signals import post_delete, pre_save from django.utils.translation import gettext as _ +from django.utils import timezone from django.conf import settings from lostplaces.models.abstract_models import Submittable, Taggable, Mapable, Expireable @@ -92,8 +94,6 @@ class Place(Submittable, Taggable, Mapable): return {'latitude': latitude, 'longitude': longitude} def calculate_place_level(self): - self.remove_expired_votes() - if self.placevotings.count() == 0: self.level = 5 self.save() @@ -104,13 +104,19 @@ class Place(Submittable, Taggable, Mapable): for vote in self.placevotings.all(): level += vote.vote - self.level = floor(level / self.placevotings.count()) + self.level = round(level / self.placevotings.count()) self.save() - def remove_expired_votes(self): + def calculate_voting_accuracy(self): + place_age = timezone.now() - self.submitted_when; + accuaries = []; + for vote in self.placevotings.all(): - if vote.is_expired: - vote.delete() + vote_age = timezone.now() - vote.created_when; + accuracy = 100 - (100 / (place_age / vote_age)) + accuaries.append(accuracy) + + return ceil(sum(accuaries) / len(accuaries)) def __str__(self): return self.name diff --git a/django_lostplaces/lostplaces/templates/partials/voting.html b/django_lostplaces/lostplaces/templates/partials/voting.html index 169b8ca..f112756 100644 --- a/django_lostplaces/lostplaces/templates/partials/voting.html +++ b/django_lostplaces/lostplaces/templates/partials/voting.html @@ -28,12 +28,7 @@