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

fix: sql_query

parent 38692c43
No related branches found
No related tags found
1 merge request!2App2
......@@ -42,6 +42,7 @@ class IceHTTP(BaseHTTPRequestHandler):
elif self.path == '/get_valid_markers': # NB: should be POST?
get_all_markers(self, self.cursor, True, 'Mjosa') # Get only valid markers
# NB: temporary hardcoded waterBodyName
def do_POST(self):
if self.path == '/get_weather_data':
get_weather(self)
......
No preview for this file type
......@@ -16,13 +16,13 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName):
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 = ?
WHERE b.Name = 'Mjosa'
'''
if valid: # Append time restriction, NB temporarily hardcoded to 5 days
if valid: # Append time restriction to WHERE statement, NB temporarily hardcoded to 5 days
sql_query += ' AND m.TimeMeasured > DATE_SUB(NOW(), INTERVAL 5 DAY)'
cursor.execute(sql_query, (waterBodyName,))
cursor.execute(sql_query)
rows = cursor.fetchall()
......@@ -35,13 +35,13 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName):
# Create subdivision object for current row
sub_division = {
'SubDivisionID': row[3],
'GroupID': row[4],
'MinimumThickness': row[5],
'AverageThickness': row[6],
'CenterLatitude': row[7],
'CenterlONGITUDE': row[8],
'Accuracy': row[9]
'SubDivisionID': row[6],
'GroupID': row[7],
'MinimumThickness': row[8],
'AverageThickness': row[9],
'CenterLatitude': row[10],
'CenterLongitude': row[11],
'Accuracy': row[12]
}
# Check if measurement ID already exists in measurement_data
......@@ -57,11 +57,10 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName):
'TimeMeasured': row[2],
'Sensor': { # Each measurement only has one related sensor
'SensorID': row[1],
'SensorType': row[9],
'Active': bool(row[10])
'SensorType': row[3],
'Active': bool(row[4])
},
'SubDivision': [sub_division], # Array of sub_division objects
'BodyOfWater': row[14]
}
# Convert dictionary values to list of measurements
......
No preview for this file type
......@@ -56,7 +56,11 @@ INSERT INTO SubDivision (MeasurementID, SubDivisionID, GroupID, MinimumThickness
(1, 1, 1, 3.2, 4.5, 60.765, 10.723, 1.2),
(1, 2, 1, 2.8, 4.3, 60.780, 10.776, 1.1),
(1, 3, 2, 4.1, 5.7, 60.768, 10.845, 1.3),
(1, 4, 2, 3.5, 5.0, 60.749, 10.783, 1.4);
(1, 4, 2, 3.5, 5.0, 60.749, 10.783, 1.4),
(2, 1, 1, 4.1, 5.7, 60.768, 10.845, 1.3),
(2, 2, 2, 3.5, 5.0, 60.749, 10.783, 1.4),
(3, 1, 1, 4.1, 5.7, 60.768, 10.845, 1.3),
(3, 2, 2, 3.5, 5.0, 60.749, 10.783, 1.4);
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