...
 
Commits (12)
......@@ -8,7 +8,7 @@ How to run this Django Server ?
- Django 1.11 (really needed)
--> CMD : pip install django
- Django Rest Framework (really needed too)
--> CMD : pip install django-rest-framework
--> CMD : pip install djangorestframework
- Django Cors Headers (really needed too)
--> CMD : pip install django-cors-headers
......
import datetime
from django.utils import timezone
from saclaze_back.models import ObservedWaitingTime, Location
......@@ -6,6 +7,7 @@ class WaitingTimeFactory():
# Parameters
anomalous_value_threshold = 10.0 # Observations within this factor of the median are retained
decay_rate = 0.9 # Older data gets less and less relevant
def time_distance(self, time1, time2):
"""
......@@ -30,7 +32,7 @@ class WaitingTimeFactory():
:param estimated_time:
:return:
"""
# print("test")
now = timezone.now()
observed_times = ObservedWaitingTime.objects.filter(
day_of_the_week=estimated_time.day_of_the_week,
location=estimated_time.location
......@@ -47,9 +49,10 @@ class WaitingTimeFactory():
observed_times = [o for o in observed_times if
median_time / self.anomalous_value_threshold <= o.waiting_time <= median_time * self.anomalous_value_threshold]
if len(observed_times) > 0:
average_waiting_time=sum([o.waiting_time.seconds for o in observed_times])
relevant_waiting_times=len(observed_times)
average_waiting_time=sum([o.waiting_time.seconds*(self.decay_rate**((now-o.timestamp).days//7)) for o in observed_times])
relevant_waiting_times=sum([self.decay_rate**((now-o.timestamp).days//7) for o in observed_times])
average_waiting_time //= relevant_waiting_times
average_waiting_time = ((average_waiting_time+5)//10)*10 # Rounding
estimated_time.waiting_time = datetime.timedelta(0, average_waiting_time)
estimated_time.save()
......