Fixing average latlon function
This commit is contained in:
parent
8597e53599
commit
86c9de3213
@ -1,6 +1,6 @@
|
||||
import os
|
||||
import datetime
|
||||
from math import round, ceil
|
||||
from math import ceil
|
||||
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
@ -78,20 +78,20 @@ class Place(Submittable, Taggable, Mapable):
|
||||
# Get center position of LP-geocoordinates.
|
||||
def average_latlon(cls, place_list):
|
||||
amount = len(place_list)
|
||||
# Init fill values to prevent None
|
||||
# China Corner in Münster
|
||||
# Where I almost always eat lunch
|
||||
# (Does'nt help losing wheight, tho)
|
||||
longitude = 7.6295628132604385
|
||||
latitude = 51.961922091398904
|
||||
|
||||
if amount > 0:
|
||||
latitude = 0
|
||||
longitude = 0
|
||||
|
||||
for place in place_list:
|
||||
longitude += place.longitude
|
||||
latitude += place.latitude
|
||||
return {'latitude':latitude / amount, 'longitude': longitude / amount}
|
||||
|
||||
return {'latitude': latitude, 'longitude': longitude}
|
||||
return {'latitude': latitude / amount, 'longitude': longitude / amount}
|
||||
else:
|
||||
# Location of China Corner in Münster
|
||||
# Where I almost always eat lunch
|
||||
# (Does'nt help losing wheight, tho)
|
||||
return {'latitude': 51.961922091398904, 'longitude': 7.6295628132604385}
|
||||
|
||||
def calculate_place_level(self):
|
||||
if self.placevotings.count() == 0:
|
||||
@ -112,11 +112,14 @@ class Place(Submittable, Taggable, Mapable):
|
||||
accuaries = [];
|
||||
|
||||
for vote in self.placevotings.all():
|
||||
vote_age = timezone.now() - vote.created_when;
|
||||
vote_age = timezone.now() - vote.submitted_when;
|
||||
accuracy = 100 - (100 / (place_age / vote_age))
|
||||
accuaries.append(accuracy)
|
||||
|
||||
return ceil(sum(accuaries) / len(accuaries))
|
||||
if len(accuaries) > 0:
|
||||
return ceil(sum(accuaries) / len(accuaries))
|
||||
else:
|
||||
return 0
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@ -216,7 +219,7 @@ def auto_delete_file_on_change(sender, instance, **kwargs):
|
||||
old_file.delete(save=False)
|
||||
|
||||
|
||||
class PlaceVoting(PlaceAsset, Expireable):
|
||||
class PlaceVoting(PlaceAsset):
|
||||
vote = models.IntegerField(choices=PLACE_LEVELS)
|
||||
|
||||
def get_human_readable_level(self):
|
||||
|
Loading…
Reference in New Issue
Block a user