Add settings field to fetch timetable thresholds

This commit is contained in:
Jan Tuomi
2017-01-25 17:37:02 +02:00
parent 4a3da98e4e
commit a063337f0a
4 changed files with 21 additions and 4 deletions
+10 -4
View File
@@ -75,7 +75,12 @@ app.controller('timetableCtrl',
$scope.arr=[];
parse(data);
});
};
$http.get('/infoscreen/hsl_data/settings')
.then(function(data, status, headers, config) {
$scope.departureThreshold = data.data['departure_threshold'];
$scope.hurryThreshold = data.data['hurry_threshold'];
});
}
$scope.$on('$destroy', function() {
$interval.cancel(inter1);
$interval.cancel(inter2);
@@ -138,8 +143,8 @@ app.controller('timetableCtrl',
delOld();
}
function delOld(){
var toSoon=5;
var hurry=10;
tooSoon = typeof($scope.departureThreshold) != 'undefined' ? $scope.departureThreshold: 0;
hurry = typeof($scope.hurryThreshold) != 'undefined' ? $scope.hurryThreshold : 0;
f= new Date();
for(var a=$scope.arr.length-1; a>=0; a--){
var time=$scope.arr[a]['time'].split(":");
@@ -149,13 +154,14 @@ app.controller('timetableCtrl',
d.setHours(time[0]);
d.setMinutes(time[1]);
var diff=(d.getTime()-f.getTime());
if(diff < toSoon*60000)
if(diff < tooSoon*60000)
$scope.arr.splice(a,1);
else if(diff < hurry*60000)
$scope.arr[a]['hurry']=true;
}
}
load();
var inter1=$interval(delOld,2000);
var inter2=$interval(load,10000);
+7
View File
@@ -10,6 +10,7 @@ from infoscreen.models import ABBInfoItem, ExternalImageInfoItem, ImageInfoItem,
from infoscreen.models import ImageUploadForm
from infoscreen.models import HSLDataModel
from infoscreen.hsl_fetcher import HSLFetcher
import sikweb.settings as settings
import json
import logging
import threading
@@ -183,6 +184,12 @@ def delete_rotation(request, *args, **kwargs):
return resp
@require_http_methods(["GET"])
def hsl_timetable_settings(request, *args, **kwargs):
d = {"departure_threshold": settings.HSL_DEPARTURE_THRESHOLD,
"hurry_threshold": settings.HSL_HURRY_THRESHOLD}
resp = json.dumps(d)
return HttpResponse(resp, status=200)
@require_http_methods(["GET"])
def CurrentHSLView(request, *args, **kwargs):
+2
View File
@@ -152,3 +152,5 @@ STATICFILES_FINDERS = ['django.contrib.staticfiles.finders.AppDirectoriesFinder'
STATIC_URL = '/static/'
HSL_USERHASH = 'YOUR HSL USERHASH HERE'
HSL_DEPARTURE_THRESHOLD = 8
HSL_HURRY_THRESHOLD = 13
+2
View File
@@ -50,6 +50,7 @@ from infoscreen.views import create_rotation
from infoscreen.views import delete_rotation
from infoscreen.views import CurrentHSLView
from infoscreen.views import admin as infoscreen_admin
from infoscreen.views import hsl_timetable_settings
#application
from members.views import application_index
from members.views import application_success_index
@@ -93,6 +94,7 @@ urlpatterns = [
url(r'^infoscreen/create_rotation$', create_rotation),
url(r'^infoscreen/delete_rotation/(?P<id>\d+)$', delete_rotation),
url(r'^infoscreen/hsl_data$', CurrentHSLView),
url(r'^infoscreen/hsl_data/settings$', hsl_timetable_settings),
#application
url(r'^application/$', application_index),
url(r'^application/success$', application_success_index),