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

update: implement lake_name in relation and measurement fetch

parent ba15a0e2
No related branches found
No related tags found
1 merge request!12Clhp map
...@@ -23,9 +23,9 @@ Future<FetchResult> fetchMeasurements() async { ...@@ -23,9 +23,9 @@ Future<FetchResult> fetchMeasurements() async {
(X509Certificate cert, String host, int port) => true; (X509Certificate cert, String host, int port) => true;
// Request markers from server // 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=' 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 var response = await request.close(); // Close response body at end of function
// Parse body to JSON if request is ok // Parse body to JSON if request is ok
......
...@@ -15,10 +15,8 @@ Future<Uint8List> fetchRelation() async { ...@@ -15,10 +15,8 @@ Future<Uint8List> fetchRelation() async {
(X509Certificate cert, String host, int port) => true; (X509Certificate cert, String host, int port) => true;
// Execute request to to get_relation endpoint // 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=' 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 var response = await request.close(); // Close response body at end of function
......
No preview for this file type
...@@ -57,7 +57,11 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -57,7 +57,11 @@ class IceHTTP(BaseHTTPRequestHandler):
elif self.path.startswith('/update_map'): # NB: should be POST? elif self.path.startswith('/update_map'): # NB: should be POST?
parsed_path = urlparse(self.path) parsed_path = urlparse(self.path)
query_params = parse_qs(parsed_path.query) 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 # NB: temporary hardcoded waterBodyName
elif self.path.startswith('/get_relation'): elif self.path.startswith('/get_relation'):
parsed_path = urlparse(self.path) parsed_path = urlparse(self.path)
...@@ -73,7 +77,7 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -73,7 +77,7 @@ class IceHTTP(BaseHTTPRequestHandler):
lake_name = query_params.get('lake', [None])[0] lake_name = query_params.get('lake', [None])[0]
if lake_name is not None: if lake_name is not None:
cut_map(self, lake_name) cut_map(self, cursor, lake_name)
else: else:
self.send_response(400) self.send_response(400)
self.send_header('Content-type', 'application/json') self.send_header('Content-type', 'application/json')
......
No preview for this file type
No preview for this file type
...@@ -10,8 +10,7 @@ from server.consts import LAKE_RELATIONS_PATH ...@@ -10,8 +10,7 @@ from server.consts import LAKE_RELATIONS_PATH
# Read a json file with relation data and send to response object # 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: try:
# Read relation from GeoJson file and extract all polygons # Read relation from GeoJson file and extract all polygons
geo_data = gpd.read_file(LAKE_RELATIONS_PATH + lake_name + ".geojson") geo_data = gpd.read_file(LAKE_RELATIONS_PATH + lake_name + ".geojson")
...@@ -80,6 +79,12 @@ def cut_map(self, lake_name: str): ...@@ -80,6 +79,12 @@ def cut_map(self, lake_name: str):
for sub_div_id, x, y in sub_div_center_list: 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 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) write_json_to_file(lake_name, feature_collection)
self.send_response(200) self.send_response(200)
...@@ -96,7 +101,6 @@ def cut_map(self, lake_name: str): ...@@ -96,7 +101,6 @@ def cut_map(self, lake_name: str):
self.end_headers() self.end_headers()
def create_grid(poly: Polygon, cell_width, cell_height): def create_grid(poly: Polygon, cell_width, cell_height):
# Retrieve bounds of the entire polygon # Retrieve bounds of the entire polygon
bounds = poly.bounds bounds = poly.bounds
...@@ -169,4 +173,3 @@ def plot_map(divided_map): ...@@ -169,4 +173,3 @@ def plot_map(divided_map):
gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none') gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none')
plt.show() plt.show()
...@@ -18,10 +18,10 @@ def get_all_markers(self, cursor, lake_name): ...@@ -18,10 +18,10 @@ def get_all_markers(self, cursor, lake_name):
INNER JOIN Sensor s ON m.SensorID = s.SensorID INNER JOIN Sensor s ON m.SensorID = s.SensorID
INNER JOIN BodyOfWater b ON m.WaterBodyName = b.Name INNER JOIN BodyOfWater b ON m.WaterBodyName = b.Name
LEFT JOIN SubDivision d ON m.MeasurementID = d.MeasurementID 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() rows = cursor.fetchall()
......
...@@ -7,5 +7,6 @@ ...@@ -7,5 +7,6 @@
"Fjellsj\u00c3\u00b8en", "Fjellsj\u00c3\u00b8en",
"Gjende", "Gjende",
"Gjersj\u00c3\u00b8en", "Gjersj\u00c3\u00b8en",
"skumsj\u00f8en",
"skumsj\u00f8en" "skumsj\u00f8en"
] ]
\ No newline at end of file
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