diff --git a/server/map/__pycache__/add_lake.cpython-311.pyc b/server/map/__pycache__/add_lake.cpython-311.pyc index 5791d4e3b431d3b5e9e3a8bfa6f60c3045aaf4dc..7409ca6202d63e1e08f7263c9d2268868485bda9 100644 Binary files a/server/map/__pycache__/add_lake.cpython-311.pyc and b/server/map/__pycache__/add_lake.cpython-311.pyc differ diff --git a/server/map/get_measurements.py b/server/map/get_measurements.py index e3f02a6278d383dda372a5ae3850279299d53d40..4199b487bf0b4067e72085c358c23f0957b57766 100644 --- a/server/map/get_measurements.py +++ b/server/map/get_measurements.py @@ -1,7 +1,8 @@ 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'))