diff --git a/server/APIs/__pycache__/get_weather.cpython-39.pyc b/server/APIs/__pycache__/get_weather.cpython-39.pyc index 2c0c82d7bea273f0a93159170f91de5e995623bb..f8858872de717cd7d93b420283a1654752615aec 100644 Binary files a/server/APIs/__pycache__/get_weather.cpython-39.pyc and b/server/APIs/__pycache__/get_weather.cpython-39.pyc differ diff --git a/server/data_processing/__pycache__/process_lidar_data.cpython-39.pyc b/server/data_processing/__pycache__/process_lidar_data.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4b9c5e0857452a784de0ace8ed0f1d69d5075580 Binary files /dev/null and b/server/data_processing/__pycache__/process_lidar_data.cpython-39.pyc differ diff --git a/server/data_processing/process_lidar_data.py b/server/data_processing/process_lidar_data.py index a0fdea41051e072ac9a6b4ce9c055fd054693a62..4db12e3d7d6f1a87dd04ce29a4292c0090a02e47 100644 --- a/server/data_processing/process_lidar_data.py +++ b/server/data_processing/process_lidar_data.py @@ -22,14 +22,6 @@ with laspy.open(lazData_path[0]) as fh: for r, c in zip(bins, counts): print(' {}:{}'.format(r, c)) -# Limit the data to specific areas -# should be within this range (10.616913,60.742712) - (10.825653,60.940206) -# this is only temporary data for coordinates in arctic -areas = [ - [(-3671212, 7898422), (-3200175, 4699978)], - [(-3671212, 7898422), (-3200175, 4699978)] -] - def inArea(position, areaRange): x, y, _ = position if (areaRange[0][0] < x < areaRange[1][0]) and (areaRange[0][1] > y > areaRange[1][1]): @@ -61,6 +53,17 @@ def find_height(points): # areas def height_in_area(area): + # Limit the data to specific areas + + # this is only temporary data for coordinates in arctic + # areas = [ + # [(-3671212, 7898422), (-3200175, 4699978)], + # [(60.815356, 10.672022), (60.774878, 10.768867)], + # ] + + # NB: is only for the test data should be removed after + area = (area[0] * ((-3671212/60.815356) - (-3200175/60.774878)), area[1] * ((7898422/10.672022) - (4699978/10.768867))) + # Refactor data format iceOver = laspy.read(lazData_path[0]) iceUnder = laspy.read(lazData_path[1]) diff --git a/server/main.py b/server/main.py index eac3faf1ebd6bc5a0fa5526c5b07c79424821ce1..7e79ca5eeb5ebb69fdcf8a55de3609f052b7f9d1 100644 --- a/server/main.py +++ b/server/main.py @@ -1,7 +1,8 @@ from flask import Flask from http.server import HTTPServer, BaseHTTPRequestHandler from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT -from map.get_markers import get_all_markers, input_new_Lidar_data +from map.get_markers import get_all_markers +from map.input_new_data import input_new_Lidar_data from APIs.get_weather import get_weather import ssl import keyboard @@ -45,8 +46,8 @@ class IceHTTP(BaseHTTPRequestHandler): if self.path == '/get_weather_data': get_weather(self) - elif self.path == '/get_new_lidar_data': - input_new_Lidar_data(self,self.cursor, 1, 'Mjøsa') + elif self.path == '/new_lidar_data': + input_new_Lidar_data(self,self.cursor, 1, 'Mjøsa') # hardcoded body of water must change later # Terminate server on key press q def on_key_press(server, event, cursor, conn): diff --git a/server/map/__pycache__/get_markers.cpython-39.pyc b/server/map/__pycache__/get_markers.cpython-39.pyc index 0ed1ba09ccad9e2350e9200179cbb2e084247f85..9e45cfc2c9ce435036ce31556ab2be3352754967 100644 Binary files a/server/map/__pycache__/get_markers.cpython-39.pyc and b/server/map/__pycache__/get_markers.cpython-39.pyc differ diff --git a/server/map/__pycache__/input_new_data.cpython-39.pyc b/server/map/__pycache__/input_new_data.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..02a1dd5649b14c230e1c373aece6024d454c0a50 Binary files /dev/null and b/server/map/__pycache__/input_new_data.cpython-39.pyc differ diff --git a/server/map/get_markers.py b/server/map/get_markers.py index 9fa5dd1a8e07b8911e80db1ca9d4eb5b924d720e..e1e8231202baba42464b13e16332283e8abb2499 100644 --- a/server/map/get_markers.py +++ b/server/map/get_markers.py @@ -1,6 +1,4 @@ import json -from datetime import datetime -from server.data_processing.process_lidar_data import height_in_area # get_markers requests all marker data or valid markers, converts the data to json, and writes # the data to the response object @@ -103,39 +101,3 @@ def get_all_markers(self, cursor, valid: bool): # Write marker data to response object self.wfile.write(marker_data.encode('utf-8')) -def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): - try: - - cursor.execute(''' - INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName) VALUES - (?,?,?); - ''',( sensorId, datetime.utcnow(), bodyOfWater)) - - # auto generate new measurement id - measurement_id = cursor.lastrowid - - cursor.execute(''' - SELECT DISTINCT CenterLatitude, CenterLongitude - FROM SubDivision - where MeasurementID = ?; - ''') - position_data = cursor.fetchall() - - if(position_data): - for row in position_data: - latitude, longitude = row - heights = height_in_area((latitude,longitude)) - average = sum(heights)/len(heights) - cursor.execute(''' - INSERT INTO SubDivision(MeasurementID, SubDivisionID, GroupID, MinimumThickness, AverageThickness, CenterLatitude, CenterLongitude, Accuracy) VALUES - (?,?,?,?,?,?,?,?); - ''',(measurement_id, 1, 1, min(heights), average, latitude, longitude, 1)) - - cursor.connection.commit() - - print("suc_ceed") - - except Exception as e: - print("An error occurred", e) - # rollback in case of error - cursor.connection.rollback() \ No newline at end of file diff --git a/server/map/input_new_data.py b/server/map/input_new_data.py new file mode 100644 index 0000000000000000000000000000000000000000..87276f9285e37885b91329b549171882fdd9f5a1 --- /dev/null +++ b/server/map/input_new_data.py @@ -0,0 +1,42 @@ +import json +from datetime import datetime +from server.data_processing.process_lidar_data import height_in_area + +def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): + try: + + cursor.execute(''' + INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName) VALUES + (?,?,?); + ''',( sensorId, datetime.utcnow(), bodyOfWater)) + + # auto generate new measurement id + measurement_id = cursor.lastrowid + + cursor.execute(''' + SELECT CenterLatitude, CenterLongitude, SubDivision, GroupID + FROM SubDivision + where MeasurementID = ? AND (CenterLatitude, CenterLongitude) + IN (SELECT DISTINCT CenterLongitude, CenterLatitiude + FROM SubDivision); + ''') + position_data = cursor.fetchall() + + if(position_data): + for row in position_data: + latitude, longitude, subID, groupID = row + heights = height_in_area((latitude,longitude)) + average = sum(heights)/len(heights) + cursor.execute(''' + INSERT INTO SubDivision(MeasurementID, SubDivisionID, GroupID, MinimumThickness, AverageThickness, CenterLatitude, CenterLongitude, Accuracy) VALUES + (?,?,?,?,?,?,?,?); + ''',(measurement_id, subID, groupID, min(heights), average, latitude, longitude, 1)) + + cursor.connection.commit() + + print("suc_ceed") + + except Exception as e: + print("An error occurred", e) + # rollback in case of error + cursor.connection.rollback() \ No newline at end of file