Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Sara Savanovic Djordjevic
PROG2900
Commits
f233ed60
Commit
f233ed60
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: merger relation and measurement response, server-side
parent
3fca7139
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/map/__pycache__/add_lake.cpython-311.pyc
+0
-0
0 additions, 0 deletions
server/map/__pycache__/add_lake.cpython-311.pyc
server/map/get_measurements.py
+31
-3
31 additions, 3 deletions
server/map/get_measurements.py
with
31 additions
and
3 deletions
server/map/__pycache__/add_lake.cpython-311.pyc
+
0
−
0
View file @
f233ed60
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_measurements.py
+
31
−
3
View file @
f233ed60
import
json
from
datetime
import
datetime
import
random
from
random
import
randint
import
geopandas
as
gpd
# get_markers requests all marker data or valid markers, converts the data to json, and writes
# the data to the response object
...
...
@@ -108,8 +109,35 @@ def get_all_markers(self, cursor, waterBodyName):
########################### TEST DATA ###########################################
# Convert dictionary values to list of measurements
data
=
list
(
measurement_data
.
values
())
+
test_measurements
measurements_list
=
list
(
measurement_data
.
values
())
+
test_measurements
######################### ADD GROUP_IDS TO RELATION DATA ##################################
# Read lake relation from json file
geo_data
=
gpd
.
read_file
(
"
server/lake_relations/mjosa_div.json
"
)
relation_data
=
geo_data
[
geo_data
[
'
geometry
'
].
geom_type
==
'
Polygon
'
]
# Add group IDs to lake relation
for
measurement
in
measurements_list
:
measurement_id
=
measurement
[
'
MeasurementID
'
]
# Extract measurement ID
for
subdivision
in
measurement
[
'
Subdivisions
'
]:
group_id
=
subdivision
[
'
GroupID
'
]
# Extract group ID
new_group_id
=
str
(
measurement_id
)
+
"
-
"
+
str
(
subdivision
[
'
GroupID
'
])
# Create concatenated group ID
# Find the matching subdivision in relation_data
for
idx
,
feature
in
relation_data
.
iterrows
():
# Add the new group ID to the correct subdivision
if
feature
[
'
properties
'
][
'
sub_div_id
'
]
==
subdivision
[
'
sub_div_id
'
]:
relation_data
.
at
[
idx
,
'
GroupID
'
]
=
new_group_id
####################################################################################
# Convert GeoDataFrame to JSON
relation_data_json
=
json
.
loads
(
relation_data
.
to_json
())
# Combine measurements_list and relation_data
data
=
[
measurements_list
,
relation_data_json
]
if
len
(
rows
)
==
0
or
len
(
data
)
==
0
:
# Return 500 and empty list if no data is found
print
(
f
"
No data which meets the condition found
"
)
marker_data
=
'
[]
'
...
...
@@ -126,7 +154,7 @@ def get_all_markers(self, cursor, waterBodyName):
self
.
send_header
(
"
Content-type
"
,
"
application/json
"
)
self
.
end_headers
()
# Write
marker
data to response object
# Write
both measurement data and relation
data to
the
response object
self
.
wfile
.
write
(
marker_data
.
encode
(
'
utf-8
'
))
...
...
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