Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GeoPEAS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
esde
toar-data
GeoPEAS
Commits
b2e0f040
Commit
b2e0f040
authored
5 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
population density service uses now new View class
parent
2692b236
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
population-density/serializers.py
+21
-11
21 additions, 11 deletions
population-density/serializers.py
population-density/views.py
+8
-5
8 additions, 5 deletions
population-density/views.py
with
29 additions
and
16 deletions
population-density/serializers.py
+
21
−
11
View file @
b2e0f040
...
...
@@ -28,6 +28,7 @@ Center (SEDAC), Columbia University. """),
# serializer classes
class
AggSerializer
(
BaseSerializer
):
"""
see http://www.django-rest-framework.org/api-guide/serializers/#baseserializer
"""
...
...
@@ -45,23 +46,32 @@ class AggSerializer(BaseSerializer):
except
TypeError
:
vlength
=
1
if
vlength
>
1
:
properties
=
OrderedDict
([
(
'
agg_function
'
,
agg_function
),
(
'
many
'
,
True
),
(
agg_function
,
OrderedDict
([
(
d
,
v
)
for
d
,
v
in
zip
(
obj
[
'
direction
'
],
val
)
])),
(
'
units
'
,
'
km-2
'
),
(
'
radius
'
,
obj
[
'
radius
'
]),
])
if
obj
[
'
direction
'
]
is
None
:
properties
.
pop
(
'
direction
'
)
properties
=
OrderedDict
([
(
'
agg_function
'
,
agg_function
),
(
'
many
'
,
True
),
(
agg_function
,
OrderedDict
([
(
d
,
v
)
for
d
,
v
in
zip
(
range
(
vlength
),
val
)
])),
(
'
units
'
,
''
),
(
'
radius
'
,
obj
[
'
radius
'
]),
])
else
:
properties
=
OrderedDict
([
(
'
agg_function
'
,
agg_function
),
(
'
many
'
,
True
),
(
agg_function
,
OrderedDict
([
(
d
,
v
)
for
d
,
v
in
zip
(
obj
[
'
direction
'
],
val
)
])),
(
'
units
'
,
''
),
(
'
radius
'
,
obj
[
'
radius
'
]),
])
else
:
properties
=
OrderedDict
([
(
'
agg_function
'
,
agg_function
),
(
'
many
'
,
False
),
(
agg_function
,
val
),
(
'
units
'
,
'
km-2
'
),
(
'
units
'
,
''
),
(
'
radius
'
,
obj
[
'
radius
'
]),
(
'
direction
'
,
obj
[
'
direction
'
]),
])
...
...
This diff is collapsed.
Click to expand it.
population-density/views.py
+
8
−
5
View file @
b2e0f040
...
...
@@ -7,7 +7,7 @@ from rest_framework.response import Response
from
toar_location_services.settings
import
DEBUG
from
.population_file_extraction
import
read_proxydata
from
.serializers
import
AggSerializer
from
utils.views_commons
import
get_query_params
,
get_agg_function
from
utils.views_commons
import
CommonViews
from
utils.geoutils
import
Directions
from
utils.extraction_tools
import
extract_value
,
extract_value_stats
...
...
@@ -20,13 +20,17 @@ lonvec, latvec, data, datainfo = read_proxydata(FILENAME)
if
DEBUG
:
print
(
"
File %s successfully loaded
"
%
(
FILENAME
),
datainfo
)
class
PopulationView
(
APIView
):
class
PopulationView
(
APIView
,
CommonViews
):
def
__init__
(
self
):
CommonViews
.
__init__
(
self
)
def
_extract
(
self
,
lat
,
lon
,
radius
,
agg
,
direction
,
by_direction
):
"""
perform actual extraction of desired quantity
"""
print
(
'
**by_direction:
'
,
by_direction
,
'
** radius, agg =
'
,
radius
,
agg
)
if
agg
is
not
None
and
radius
is
not
None
and
radius
>
0.
:
agg_function
=
get_agg_function
(
agg
)
agg_function
=
self
.
get_agg_function
(
agg
)
min_angle
=
None
max_angle
=
None
if
by_direction
:
...
...
@@ -56,7 +60,6 @@ class PopulationView(APIView):
# return data, also return agg and direction as they may have been overwritten
return
result
,
agg
,
direction
def
get
(
self
,
request
,
format
=
None
):
"""
process GET requests for population-density app
...
...
@@ -79,7 +82,7 @@ class PopulationView(APIView):
by_direction: if True, data are returned as vector with one value aggregated
over each of 16 wind directions.
"""
lat
,
lon
,
radius
,
agg
,
direction
,
by_direction
=
get_query_params
(
request
.
query_params
,
lat
,
lon
,
radius
,
agg
,
direction
,
by_direction
=
self
.
get_query_params
(
request
.
query_params
,
[
'
lat
'
,
'
lon
'
,
'
radius
'
,
'
agg
'
,
'
direction
'
,
'
by_direction
'
])
result
,
agg
,
direction
=
self
.
_extract
(
lat
,
lon
,
radius
,
agg
,
direction
,
by_direction
)
...
...
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