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

update: get valid markers or all markers

parent f489dd9c
No related branches found
No related tags found
No related merge requests found
......@@ -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');
}
}
......@@ -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):
......
......@@ -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()
......
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