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

update: sql_query, non-functional

parent 9dd173b5
No related branches found
No related tags found
1 merge request!2App2
...@@ -37,11 +37,11 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -37,11 +37,11 @@ class IceHTTP(BaseHTTPRequestHandler):
self.wfile.write(b"Root path hit!") self.wfile.write(b"Root path hit!")
elif self.path == '/update_map': # NB: should be POST? elif self.path == '/update_map': # NB: should be POST?
get_all_markers(self, self.cursor, False) # Get all markers get_all_markers(self, self.cursor, False, 'Mjosa') # Get all markers
# NB: temporary hardcoded waterBodyName
elif self.path == '/get_valid_markers': # NB: should be POST? elif self.path == '/get_valid_markers': # NB: should be POST?
get_all_markers(self, self.cursor, True) # Get only valid markers get_all_markers(self, self.cursor, True, 'Mjosa') # Get only valid markers
# NB: temporary hardcoded waterBodyName
def do_POST(self): def do_POST(self):
if self.path == '/get_weather_data': if self.path == '/get_weather_data':
get_weather(self) get_weather(self)
......
No preview for this file type
...@@ -5,35 +5,24 @@ import json ...@@ -5,35 +5,24 @@ import json
# the data to the response object # the data to the response object
def get_all_markers(self, cursor, valid: bool, waterBodyName): def get_all_markers(self, cursor, valid: bool, waterBodyName):
try: try:
# NB: interval temporarily hard coded to 5 days sql_query = '''
if valid: SELECT m.MeasurementID, m.SensorID, m.TimeMeasured,
cursor.execute(''' s.SensorType, s.Active,
SELECT m.MeasurementID, m.SensorID, m.TimeMeasured, b.Name,
s.SensorType, s.Active, d.SubDivisionID, d.GroupID, d.MinimumThickness,
b.Name, d.AverageThickness, d.CenterLatitude, d.CenterLongitude,
d.SubDivisionID, d.GroupID, d.MinimumThickness, d.Accuracy
d.AverageThickness, d.CenterLatitude, d.CenterLongitude, FROM Measurement m
d.Accuracy INNER JOIN Sensor s ON m.SensorID = s.SensorID
FROM Measurement m INNER JOIN BodyOfWater b ON m.WaterBodyName = b.Name
INNER JOIN Sensor s ON m.SensorID = s.SensorID LEFT JOIN SubDivision d ON m.MeasurementID = d.MeasurementID
INNER JOIN BodyOfWater b ON m.WaterBodyName = b.Name WHERE b.Name = ?
LEFT JOIN SubDivision d ON m.MeasurementID = d.MeasurementID '''
WHERE m.TimeMeasured > DATE_SUB(NOW(), INTERVAL 5 DAY) & b.Name = ?
''', waterBodyName) if valid: # Append time restriction, NB temporarily hardcoded to 5 days
else: sql_query += ' AND m.TimeMeasured > DATE_SUB(NOW(), INTERVAL 5 DAY)'
cursor.execute('''
SELECT m.MeasurementID, m.SensorID, m.TimeMeasured, cursor.execute(sql_query, (waterBodyName,))
s.SensorType, s.Active,
b.Name,
d.SubDivisionID, d.GroupID, d.MinimumThickness,
d.AverageThickness, d.CenterLatitude, d.CenterLongitude,
d.Accuracy
FROM Measurement m
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 = ?
''', waterBodyName)
rows = cursor.fetchall() rows = cursor.fetchall()
...@@ -88,7 +77,7 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName): ...@@ -88,7 +77,7 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName):
marker_data = json.dumps(data, indent=4) marker_data = json.dumps(data, indent=4)
except Exception as e: except Exception as e:
print(f"An error occurred while querying the database: {e}") print(f"Error in querying database: {e}")
resp_code = 500 resp_code = 500
marker_data = '[]' marker_data = '[]'
......
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