From fd01ac43281c6f1e62c83fcc8ea9a76e2e41c931 Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Wed, 14 Feb 2024 14:07:30 +0100 Subject: [PATCH] update: get valid markers or all markers --- app/lib/pages/marker_handler/get_markers.dart | 4 +-- server/main.py | 6 ++-- server/map/get_markers.py | 35 +++++++++++++------ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/lib/pages/marker_handler/get_markers.dart b/app/lib/pages/marker_handler/get_markers.dart index 14d3da49..9e0e1e3b 100644 --- a/app/lib/pages/marker_handler/get_markers.dart +++ b/app/lib/pages/marker_handler/get_markers.dart @@ -22,12 +22,10 @@ Future<List<Measurement>> fetchMarkerData() async { } else { print('Request failed with status: ${response.statusCode}'); - // Throw an exception or return null if the request fails - throw Exception('Failed to fetch marker template'); + throw Exception('Failed to parse marker data'); } } catch (e) { print('Error: $e'); - // Throw an exception or return null if there's an error throw Exception('Failed to connect to the server. Please check your network connection'); } } diff --git a/server/main.py b/server/main.py index 9e51bc42..1f465496 100644 --- a/server/main.py +++ b/server/main.py @@ -48,9 +48,11 @@ class IceHTTP(BaseHTTPRequestHandler): self.wfile.write(b"Root path hit!") - # Update_map endpoint elif self.path == '/update_map': # NB: should be POST? - get_all_markers(self, self.cursor) # Accessing cursor from self + get_all_markers(self, self.cursor, False) # Get all markers + + elif self.path == '/get_valid_markers': # NB: should be POST? + get_all_markers(self, self.cursor, True) # Get only valid markers # Listen for pressing of q key to terminate server def on_key_press(server, event, cursor, conn): diff --git a/server/map/get_markers.py b/server/map/get_markers.py index 3b3ba48e..608b4009 100644 --- a/server/map/get_markers.py +++ b/server/map/get_markers.py @@ -2,18 +2,31 @@ import json # get_markers requests all marker data from mongoDB -def get_all_markers(self, cursor): +def get_all_markers(self, cursor, valid : bool): try: - # Fetch all data - cursor.execute(''' - SELECT m.MeasurementID, m.SensorID, m.TimeMeasured, d.Latitude, d.Longitude, - d.IceTop, d.IceBottom, d.CalculatedThickness, d.Accuracy, s.SensorType, s.Active, - c.CornerID, c.CornerLatitude, c.CornerLongitude - FROM Measurement m - INNER JOIN Sensor s ON m.SensorID = s.SensorID - INNER JOIN Data d ON m.MeasurementID = d.MeasurementID - INNER JOIN Corner c ON m.MeasurementID = c.MeasurementID - ''') + + # NB: interval temporarily hard coded to 5 days + if valid == True: # Fetch only valid markers (taken within last 5 days) + cursor.execute(''' + SELECT m.MeasurementID, m.SensorID, m.TimeMeasured, d.Latitude, d.Longitude, + d.IceTop, d.IceBottom, d.CalculatedThickness, d.Accuracy, s.SensorType, s.Active, + c.CornerID, c.CornerLatitude, c.CornerLongitude + FROM Measurement m + INNER JOIN Sensor s ON m.SensorID = s.SensorID + INNER JOIN Data d ON m.MeasurementID = d.MeasurementID + INNER JOIN Corner c ON m.MeasurementID = c.MeasurementID + WHERE m.TimeMeasured > DATE_SUB(NOW(), INTERVAL 5 DAY); + ''') + else: # Fetch all markers + cursor.execute(''' + SELECT m.MeasurementID, m.SensorID, m.TimeMeasured, d.Latitude, d.Longitude, + d.IceTop, d.IceBottom, d.CalculatedThickness, d.Accuracy, s.SensorType, s.Active, + c.CornerID, c.CornerLatitude, c.CornerLongitude + FROM Measurement m + INNER JOIN Sensor s ON m.SensorID = s.SensorID + INNER JOIN Data d ON m.MeasurementID = d.MeasurementID + INNER JOIN Corner c ON m.MeasurementID = c.MeasurementID + ''') rows = cursor.fetchall() -- GitLab