Skip to content
Snippets Groups Projects
Commit f233ed60 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: merger relation and measurement response, server-side

parent 3fca7139
No related branches found
No related tags found
No related merge requests found
No preview for this file type
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'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment