diff --git a/app/lib/server_requests/fetch_markers.dart b/app/lib/server_requests/fetch_markers.dart index 7cd1b5c4e1d437a7cfa8d39948d570a055b94c35..818bec9712ce4be34cfa0cc9f12fe17409151391 100644 --- a/app/lib/server_requests/fetch_markers.dart +++ b/app/lib/server_requests/fetch_markers.dart @@ -23,9 +23,9 @@ Future<FetchResult> fetchMeasurements() async { (X509Certificate cert, String host, int port) => true; // Request markers from server - var parameterValue = 'Mjosa'; // NB temp hardcoded, should use selectedLake directly in url param var request = await client.getUrl(Uri.parse('$serverURI$mapEndpoint?lake=' - '${Uri.encodeComponent(parameterValue)}')); + '${Uri.encodeFull(selectedLake)}')); + var response = await request.close(); // Close response body at end of function // Parse body to JSON if request is ok diff --git a/app/lib/server_requests/fetch_relation.dart b/app/lib/server_requests/fetch_relation.dart index 875f3a31c7a03e430fdf45a31579b809d269114d..876fa9006c4358278eecc0be258a96e5ee7765ba 100644 --- a/app/lib/server_requests/fetch_relation.dart +++ b/app/lib/server_requests/fetch_relation.dart @@ -15,10 +15,8 @@ Future<Uint8List> fetchRelation() async { (X509Certificate cert, String host, int port) => true; // Execute request to to get_relation endpoint - var parameterValue = 'Mjøsa'; // NB temp hardcoded, should use selectedLake directly in url param - //var request = await client.getUrl(Uri.parse('${serverURI}get_relation')); var request = await client.getUrl(Uri.parse('${serverURI}get_relation?lake=' - '${Uri.encodeFull(parameterValue)}')); + '${Uri.encodeFull(selectedLake)}')); var response = await request.close(); // Close response body at end of function diff --git a/server/database/icedb b/server/database/icedb index f72af9b3586a8d3546eeb065f92c8eba1b20ed47..21581f431073869d4d23a0682bd4fe2bfd994a8f 100644 Binary files a/server/database/icedb and b/server/database/icedb differ diff --git a/server/main.py b/server/main.py index 092cb6432e0291dbb4f631b97aefae67e0f15ddb..3db590fd55f9b88defa2c15f8164681f99e71a49 100644 --- a/server/main.py +++ b/server/main.py @@ -57,7 +57,11 @@ class IceHTTP(BaseHTTPRequestHandler): elif self.path.startswith('/update_map'): # NB: should be POST? parsed_path = urlparse(self.path) query_params = parse_qs(parsed_path.query) - get_all_markers(self, self.cursor, 'mjosa') # Get all markers + + lake_name_param = query_params.get('lake', [''])[0] + lake_name = unquote(lake_name_param) # Decode url param + + get_all_markers(self, self.cursor, lake_name) # Get all markers # NB: temporary hardcoded waterBodyName elif self.path.startswith('/get_relation'): parsed_path = urlparse(self.path) @@ -73,7 +77,7 @@ class IceHTTP(BaseHTTPRequestHandler): lake_name = query_params.get('lake', [None])[0] if lake_name is not None: - cut_map(self, lake_name) + cut_map(self, cursor, lake_name) else: self.send_response(400) self.send_header('Content-type', 'application/json') diff --git a/server/map_handler/__pycache__/add_lake.cpython-311.pyc b/server/map_handler/__pycache__/add_lake.cpython-311.pyc index d2fb1f4ad0db1e44f8e56d7f591fd08ea4cc7e0c..3337d8de7c10d6e98b86ea0835797f3599d8cd47 100644 Binary files a/server/map_handler/__pycache__/add_lake.cpython-311.pyc and b/server/map_handler/__pycache__/add_lake.cpython-311.pyc differ diff --git a/server/map_handler/__pycache__/get_measurements.cpython-311.pyc b/server/map_handler/__pycache__/get_measurements.cpython-311.pyc index b375f54cdcedc8721cc48f56cd6d406bab183dd4..04e435195bb84b483975508c3e1f2e1f7c2ac5ab 100644 Binary files a/server/map_handler/__pycache__/get_measurements.cpython-311.pyc and b/server/map_handler/__pycache__/get_measurements.cpython-311.pyc differ diff --git a/server/map_handler/add_lake.py b/server/map_handler/add_lake.py index 71ce38b75d7c10d79f47fd6cf2e6246eb071f6b2..6c22ed5bd575349fc6b120eab337ce986d4fadd4 100644 --- a/server/map_handler/add_lake.py +++ b/server/map_handler/add_lake.py @@ -10,8 +10,7 @@ from server.consts import LAKE_RELATIONS_PATH # Read a json file with relation data and send to response object -def cut_map(self, lake_name: str): - +def cut_map(self, cursor, lake_name: str): try: # Read relation from GeoJson file and extract all polygons geo_data = gpd.read_file(LAKE_RELATIONS_PATH + lake_name + ".geojson") @@ -80,6 +79,12 @@ def cut_map(self, lake_name: str): for sub_div_id, x, y in sub_div_center_list: file.write(f"{sub_div_id}, {x}, {y}\n") # Write each list entry on a new line + # Add lake name to database + cursor.execute(''' + INSERT INTO BodyOfWater(Name) VALUES + (?); + ''', (lake_name,)) + write_json_to_file(lake_name, feature_collection) self.send_response(200) @@ -96,7 +101,6 @@ def cut_map(self, lake_name: str): self.end_headers() - def create_grid(poly: Polygon, cell_width, cell_height): # Retrieve bounds of the entire polygon bounds = poly.bounds @@ -169,4 +173,3 @@ def plot_map(divided_map): gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none') plt.show() - diff --git a/server/map_handler/get_measurements.py b/server/map_handler/get_measurements.py index 87fda774a65eb25e870ccac8abc8280a2cefa575..c7a88f816017270a60e53f9a2240427f91615d54 100644 --- a/server/map_handler/get_measurements.py +++ b/server/map_handler/get_measurements.py @@ -18,10 +18,10 @@ def get_all_markers(self, cursor, lake_name): INNER JOIN Sensor s ON m.SensorID = s.SensorID INNER JOIN BodyOfWater b ON m.WaterBodyName = b.Name LEFT JOIN SubDivision d ON m.MeasurementID = d.MeasurementID - WHERE b.Name = 'Mjosa' + WHERE b.Name = ? ''' - cursor.execute(sql_query) + cursor.execute(sql_query, (lake_name,)) rows = cursor.fetchall() diff --git a/server/map_handler/lake_relations/all_lake_names.json b/server/map_handler/lake_relations/all_lake_names.json index 2b2c82afde20516e0f2370f0ead9aacfdf2a82c5..468b1fe7c028067f627bc2aef8c6b1e14e88ca74 100644 --- a/server/map_handler/lake_relations/all_lake_names.json +++ b/server/map_handler/lake_relations/all_lake_names.json @@ -7,5 +7,6 @@ "Fjellsj\u00c3\u00b8en", "Gjende", "Gjersj\u00c3\u00b8en", + "skumsj\u00f8en", "skumsj\u00f8en" ] \ No newline at end of file