Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSWeb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSWeb
Commits
869b5402
Commit
869b5402
authored
7 years ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Handling changes in forecast result objects
parent
e29e3f66
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
VIPSWeb/views.py
+32
-29
32 additions, 29 deletions
VIPSWeb/views.py
common/util.py
+12
-2
12 additions, 2 deletions
common/util.py
forecasts/models.py
+4
-2
4 additions, 2 deletions
forecasts/models.py
forecasts/urls.py
+3
-3
3 additions, 3 deletions
forecasts/urls.py
with
51 additions
and
36 deletions
VIPSWeb/views.py
+
32
−
29
View file @
869b5402
...
@@ -28,36 +28,39 @@ from django.views.decorators.gzip import gzip_page
...
@@ -28,36 +28,39 @@ from django.views.decorators.gzip import gzip_page
from
django.views.decorators.cache
import
cache_page
from
django.views.decorators.cache
import
cache_page
def
index
(
request
):
def
index
(
request
):
# Check if user is on stock Android browser, which performs poorly with OpenLayers
try
:
user_is_stock_android
=
False
# Check if user is on stock Android browser, which performs poorly with OpenLayers
user_agent
=
request
.
META
[
'
HTTP_USER_AGENT
'
]
user_is_stock_android
=
False
#print user_agent
user_agent
=
request
.
META
[
'
HTTP_USER_AGENT
'
]
if
user_agent
.
find
(
"
Android
"
)
>=
0
and
user_agent
.
find
(
"
Windows
"
)
<
0
:
#print user_agent
chrome_index
=
user_agent
.
find
(
"
Chrome
"
)
if
user_agent
.
find
(
"
Android
"
)
>=
0
and
user_agent
.
find
(
"
Windows
"
)
<
0
:
if
chrome_index
<
0
:
chrome_index
=
user_agent
.
find
(
"
Chrome
"
)
user_is_stock_android
=
True
if
chrome_index
<
0
:
else
:
chrome_version
=
user_agent
[
chrome_index
+
7
:
chrome_index
+
9
]
if
int
(
chrome_version
)
<
40
:
user_is_stock_android
=
True
user_is_stock_android
=
True
else
:
user_uuid
=
request
.
GET
.
get
(
"
returnUUID
"
,
None
)
chrome_version
=
user_agent
[
chrome_index
+
7
:
chrome_index
+
9
]
if
user_uuid
==
None
:
if
int
(
chrome_version
)
<
40
:
user_uuid
=
request
.
session
.
get
(
"
user_uuid
"
,
""
)
user_is_stock_android
=
True
# Get front page categories. This is defined in local_settings.py
user_uuid
=
request
.
GET
.
get
(
"
returnUUID
"
,
None
)
#message_tags = MessageTag.get_message_tags(translation.get_language())
if
user_uuid
==
None
:
# Get advertisements, if any
user_uuid
=
request
.
session
.
get
(
"
user_uuid
"
,
""
)
#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
]
# Get front page categories. This is defined in local_settings.py
# Last 10 messages
#message_tags = MessageTag.get_message_tags(translation.get_language())
context
=
{
# Get advertisements, if any
'
user_uuid
'
:
user_uuid
,
#advertisements = Advertisement.objects.exclude(pub_date__gte=datetime.date.today()).exclude(exp_date__lte=datetime.date.today()).order_by('-pub_date')[:1]
'
advertisements
'
:
advertisements
,
advertisements
=
Advertisement
.
objects
.
exclude
(
pub_date__gt
=
datetime
.
date
.
today
()).
exclude
(
exp_date__lt
=
datetime
.
date
.
today
()).
order_by
(
'
-pub_date
'
)[:
1
]
'
crop_categories
'
:
CropCategory
.
get_crop_categories
(
translation
.
get_language
()),
# Last 10 messages
'
user_is_stock_android
'
:
user_is_stock_android
,
context
=
{
}
'
user_uuid
'
:
user_uuid
,
return
render
(
request
,
'
index.html
'
,
context
)
'
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
# Serving settings for JavaScript
def
settings_js
(
request
):
def
settings_js
(
request
):
...
...
This diff is collapsed.
Click to expand it.
common/util.py
+
12
−
2
View file @
869b5402
# coding: utf-8
# coding: utf-8
#
#
# Copyright (c) 201
4
NIBIO <http://www.nibio.no/>.
# Copyright (c) 201
8
NIBIO <http://www.nibio.no/>.
#
#
# This file is part of VIPSWeb.
# This file is part of VIPSWeb.
# VIPSWeb is free software: you can redistribute it and/or modify
# VIPSWeb is free software: you can redistribute it and/or modify
...
@@ -20,7 +20,17 @@
...
@@ -20,7 +20,17 @@
# Author: Tor-Einar Skog <tor-einar.skog@nibio.no>
# Author: Tor-Einar Skog <tor-einar.skog@nibio.no>
from
datetime
import
datetime
from
datetime
import
datetime
from
django.utils.dateparse
import
parse_datetime
def
get_unix_timestamp
(
datetime_object
):
def
get_unix_timestamp
(
datetime_object
):
"""
GET Unix timestamp (milliseconds since 1970-01-01 UTC) from datetime object
"""
"""
GET Unix timestamp (milliseconds since 1970-01-01 UTC) from datetime object
"""
return
(
datetime_object
-
datetime
(
1970
,
1
,
1
)).
total_seconds
()
*
1000
# The strftime("%s") is UNIX implementation dependent
\ No newline at end of file
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
This diff is collapsed.
Click to expand it.
forecasts/models.py
+
4
−
2
View file @
869b5402
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
# along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>.
# along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>.
#
#
from
datetime
import
datetime
import
math
import
math
import
requests
import
requests
import
json
import
json
...
@@ -27,6 +26,7 @@ from django.utils.translation import ugettext as _
...
@@ -27,6 +26,7 @@ from django.utils.translation import ugettext as _
from
django.conf
import
settings
from
django.conf
import
settings
from
django.db
import
models
from
django.db
import
models
from
django.utils
import
translation
from
django.utils
import
translation
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
organisms.models
import
Organism
from
organisms.models
import
Organism
...
@@ -40,7 +40,9 @@ Represents a single result from the running of a forecasting model
...
@@ -40,7 +40,9 @@ Represents a single result from the running of a forecasting model
class
ForecastResult
:
class
ForecastResult
:
def
__init__
(
self
,
forecast_result_id
,
valid_time_start
,
warning_status
,
all_values
):
def
__init__
(
self
,
forecast_result_id
,
valid_time_start
,
warning_status
,
all_values
):
self
.
forecast_result_id
=
forecast_result_id
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
.
warning_status
=
warning_status
self
.
all_values
=
all_values
self
.
all_values
=
all_values
...
...
This diff is collapsed.
Click to expand it.
forecasts/urls.py
+
3
−
3
View file @
869b5402
...
@@ -25,10 +25,10 @@ urlpatterns = patterns('forecasts.views',
...
@@ -25,10 +25,10 @@ urlpatterns = patterns('forecasts.views',
url
(
r
'
^$
'
,
views
.
index
,
name
=
'
index
'
),
url
(
r
'
^$
'
,
views
.
index
,
name
=
'
index
'
),
# ex: /forecasts/5/
# 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/$', 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+)/$', cache_page(60 * 15)(views.detail), name='detail'),
url
(
r
'
^(?P<forecast_id>\d+)/$
'
,
(
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+)/(?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/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/(?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
'
),
url
(
r
'
^models/js/modelLocalNames.js
'
,
cache_page
(
60
*
30
)(
views
.
model_local_names_js
),
name
=
'
model_local_names_js
'
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment