Skip to content
Snippets Groups Projects
Commit 869b5402 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Handling changes in forecast result objects

parent e29e3f66
Branches
No related tags found
No related merge requests found
......@@ -28,36 +28,39 @@ from django.views.decorators.gzip import gzip_page
from django.views.decorators.cache import cache_page
def index(request):
# Check if user is on stock Android browser, which performs poorly with OpenLayers
user_is_stock_android = False
user_agent = request.META['HTTP_USER_AGENT']
#print user_agent
if user_agent.find("Android") >= 0 and user_agent.find("Windows") < 0:
chrome_index = user_agent.find("Chrome")
if chrome_index < 0:
user_is_stock_android = True
else:
chrome_version = user_agent[chrome_index+7:chrome_index+9]
if int(chrome_version) < 40:
try:
# Check if user is on stock Android browser, which performs poorly with OpenLayers
user_is_stock_android = False
user_agent = request.META['HTTP_USER_AGENT']
#print user_agent
if user_agent.find("Android") >= 0 and user_agent.find("Windows") < 0:
chrome_index = user_agent.find("Chrome")
if chrome_index < 0:
user_is_stock_android = True
user_uuid = request.GET.get("returnUUID",None)
if user_uuid == None:
user_uuid = request.session.get("user_uuid","")
# Get front page categories. This is defined in local_settings.py
#message_tags = MessageTag.get_message_tags(translation.get_language())
# Get advertisements, if any
#advertisements = Advertisement.objects.exclude(pub_date__gte=datetime.date.today()).exclude(exp_date__lte=datetime.date.today()).order_by('-pub_date')[:1]
advertisements = Advertisement.objects.exclude(pub_date__gt=datetime.date.today()).exclude(exp_date__lt=datetime.date.today()).order_by('-pub_date')[:1]
# Last 10 messages
context = {
'user_uuid': user_uuid,
'advertisements': advertisements,
'crop_categories': CropCategory.get_crop_categories(translation.get_language()),
'user_is_stock_android': user_is_stock_android,
}
return render(request, 'index.html', context)
else:
chrome_version = user_agent[chrome_index+7:chrome_index+9]
if int(chrome_version) < 40:
user_is_stock_android = True
user_uuid = request.GET.get("returnUUID",None)
if user_uuid == None:
user_uuid = request.session.get("user_uuid","")
# Get front page categories. This is defined in local_settings.py
#message_tags = MessageTag.get_message_tags(translation.get_language())
# Get advertisements, if any
#advertisements = Advertisement.objects.exclude(pub_date__gte=datetime.date.today()).exclude(exp_date__lte=datetime.date.today()).order_by('-pub_date')[:1]
advertisements = Advertisement.objects.exclude(pub_date__gt=datetime.date.today()).exclude(exp_date__lt=datetime.date.today()).order_by('-pub_date')[:1]
# Last 10 messages
context = {
'user_uuid': user_uuid,
'advertisements': advertisements,
'crop_categories': CropCategory.get_crop_categories(translation.get_language()),
'user_is_stock_android': user_is_stock_android,
}
return render(request, 'index.html', context)
except ValueError:
return render(request, '503.html')
# Serving settings for JavaScript
def settings_js(request):
......
# coding: utf-8
#
# Copyright (c) 2014 NIBIO <http://www.nibio.no/>.
# Copyright (c) 2018 NIBIO <http://www.nibio.no/>.
#
# This file is part of VIPSWeb.
# VIPSWeb is free software: you can redistribute it and/or modify
......@@ -20,7 +20,17 @@
# Author: Tor-Einar Skog <tor-einar.skog@nibio.no>
from datetime import datetime
from django.utils.dateparse import parse_datetime
def get_unix_timestamp(datetime_object):
"""GET Unix timestamp (milliseconds since 1970-01-01 UTC) from datetime object"""
return (datetime_object - datetime(1970,1,1)).total_seconds() * 1000
\ No newline at end of file
# The strftime("%s") is UNIX implementation dependent
return int(datetime_object.strftime("%s")) * 1000
#return (datetime_object - datetime(1970,1,1)).total_seconds() * 1000
def parse_json_timestamp(timestamp_str):
""" Either it's a UNIX timestamp or an ISO datetime string """
try:
return datetime.fromtimestamp(timestamp_str/1000)
except TypeError:
return parse_datetime(timestamp_str)
\ No newline at end of file
......@@ -17,7 +17,6 @@
# along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>.
#
from datetime import datetime
import math
import requests
import json
......@@ -27,6 +26,7 @@ from django.utils.translation import ugettext as _
from django.conf import settings
from django.db import models
from django.utils import translation
from django.core.exceptions import ValidationError
from organisms.models import Organism
......@@ -40,7 +40,9 @@ Represents a single result from the running of a forecasting model
class ForecastResult:
def __init__(self,forecast_result_id,valid_time_start,warning_status,all_values):
self.forecast_result_id = forecast_result_id
self.valid_time_start = datetime.fromtimestamp(valid_time_start/1000)
#self.valid_time_start = datetime.fromtimestamp(valid_time_start/1000)
self.valid_time_start = util.parse_json_timestamp(valid_time_start)
print self.valid_time_start
self.warning_status = warning_status
self.all_values = all_values
......
......@@ -25,10 +25,10 @@ urlpatterns = patterns('forecasts.views',
url(r'^$', views.index, name='index'),
# ex: /forecasts/5/
#url(r'^(?P<forecast_id>\d+)/detail_highcharts_json/$', cache_page(60 * 15)(views.detail_highcharts_json), name='detail_highcharts_json'),
url(r'^(?P<forecast_id>\d+)/detail_highcharts_json/$', views.detail_highcharts_json, name='detail_highcharts_json'),
url(r'^(?P<forecast_id>-?\d+)/detail_highcharts_json/$', views.detail_highcharts_json, name='detail_highcharts_json'),
#url(r'^(?P<forecast_id>\d+)/$', cache_page(60 * 15)(views.detail), name='detail'),
url(r'^(?P<forecast_id>\d+)/$', (views.detail), name='detail'),
url(r'^(?P<forecast_id>\d+)/(?P<latest_days>\d+)/$', (views.detail_latest_days), name='detail_latest_days'),
url(r'^(?P<forecast_id>-?\d+)/$', (views.detail), name='detail'),
url(r'^(?P<forecast_id>-?\d+)/(?P<latest_days>\d+)/$', (views.detail_latest_days), name='detail_latest_days'),
url(r'^models/test/$', views.models_detail_test, name='models_detail_test'),
url(r'^models/(?P<model_id>\w+)/$', views.models_detail, name='models_detail'),
url(r'^models/js/modelLocalNames.js', cache_page(60 * 30)(views.model_local_names_js), name='model_local_names_js'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment