diff --git a/server/data_processing/__pycache__/area_processing.cpython-39.pyc b/server/data_processing/__pycache__/area_processing.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..36bd3436993a5dbf223824d0c9b30cbeb8de4ca5 Binary files /dev/null and b/server/data_processing/__pycache__/area_processing.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 index 47edf95b89a3f2a16363fcc7430b1e02bc70d60d..9a3706cc4096a71462648ad5967fbd3abd35f8e1 100644 Binary files a/server/data_processing/__pycache__/process_lidar_data.cpython-39.pyc and b/server/data_processing/__pycache__/process_lidar_data.cpython-39.pyc differ diff --git a/server/data_processing/area_processing.py b/server/data_processing/area_processing.py index 6239487d90d2189885d8466e5296b86d90349221..43e289ee01d5794c6af26982fcee4c20a1308448 100644 --- a/server/data_processing/area_processing.py +++ b/server/data_processing/area_processing.py @@ -41,7 +41,7 @@ def define_gridareas(lat, lng, area_offset, grid_size): area_size = (main_area[2][0] - main_area[0][0], main_area[0][1] - main_area[2][1]) # find each subareas vector to it's center dist_to_subcenter = (area_size[0]/(grid_size*2), area_size[1]/(grid_size*2)) - print(dist_to_subcenter) + # find subareas size relative to main area subarea_offset = area_offset/grid_size @@ -71,4 +71,5 @@ def define_gridareas(lat, lng, area_offset, grid_size): return grided_area -print(define_gridareas(60,10,1500,4)) \ No newline at end of file +#print(define_gridareas(-60,10,1500,4)) +print(define_gridareas(3435693.5,6299200.0, 20000000000,4)) \ No newline at end of file diff --git a/server/data_processing/process_lidar_data.py b/server/data_processing/process_lidar_data.py index a0282be55a54d6a50c0a3b3c6aeaf2d8710924a7..6345fe111402ee8e51229e16630a5d819f5912d7 100644 --- a/server/data_processing/process_lidar_data.py +++ b/server/data_processing/process_lidar_data.py @@ -1,7 +1,9 @@ import numpy as np import laspy +import utm # src: https://github.com/Turbo87/utm from itertools import groupby -from process_lidar_data import calculate_corners, define_gridareas +from server.data_processing.area_processing import calculate_corners, define_gridareas + # hard coded files for test data lazData_path = ["server/example_lidar_data/ot_N_000005_1.laz", "server/example_lidar_data/ot_N_000033_1.laz"] @@ -27,7 +29,9 @@ with laspy.open(lazData_path[0]) as fh: # check if lidar points is within range of the area selected def inArea(position, areaRange): x, y, _ = position - if (areaRange[0][0] < x < areaRange[1][0]) and (areaRange[0][1] > y > areaRange[1][1]): + print(areaRange[0][0], " > ", x, " > ", areaRange[1][0], ") and (", areaRange[0][1], " < ", y, " < ", areaRange[1][1]) + if (areaRange[0][0] > x > areaRange[1][0]) and (areaRange[0][1] < y < areaRange[1][1]): + print("inside area") return True else: return False @@ -60,7 +64,7 @@ def find_height(points): # find the height of an area based on the coordinates of it's center # and it's affiliations (subId and groupId) (soon to be implemented -def height_in_area(center): +def calculate_area_data(center): # container for all the heights in area area_heights = [] @@ -73,11 +77,39 @@ def height_in_area(center): # ] # specified the area and it's range - area = calculate_corners(center, 1500) - area = (area[0], area[2]) - # NB: is only for the test data (soon to be removed) - areazone = [(((area[0]) * ((-3671212/60.815356) - (-3200175/60.774878))) - 3200175, (area[1] * ((7898422/10.768867) - (4699978/10.672022))) + 4699978), - (((area[0] - 100) * ((-3671212/60.815356) - (-3200175/60.774878))) - 3200175, ((area[1] - 1) * ((7898422/10.768867) - (4699978/10.672022))) + 4699978)] + #area = (area[0], area[2]) + #print("area size") + # NB: is only for the test data (soon to be removed and switched with center) + #areazone = ((((7898422) - (4699978)))/2.0 + 4699978), (((-3671212) - (-3200175)))/2.0 - 3200175 + #areazone = ((-3671212 - (-3200175))/center[0] - 3200175, (7898422 - 4699978)/center[1] + 4699978) + + #print(areazone) + + + # max and min initial (-9.790000, -615.719971) - (696.619995, 96.660004) + # max and min g(idk) (-36709.790000, 78284.280029) - (-36003.380005,78996.660004) + # should be within (-3200175, 4699978) - (-3671212, 7898422) + #print(utm.to_latlon(4699978, -3200175,18,'S')) + + + #areazone = ((((-3200175 + 3671212) / ( area[0][0] - area[2][0]))), + # ((7898422 - 4699978) / (area[0][1] - area[2][1]))) + #areazone = ((((-3200175 / area[0][0]) - ( - 3671212 / area[2][0]))), + # ((7898422 / area[0][1]) - (area[2][1] / 4699978))) + + #area = calculate_corners(center[0],center[1], 1500) + + areazone = calculate_corners(3435693.5,7550000.0, 20000000000) + #print(area[0]," area ", area[2]) + + #start_point = areazone[0] + #areazone = (areazone[2][0] - areazone[0][0], areazone[2][1] - areazone[0][1]) + #print("az",areazone) + + # areazone = [(((center[0]) * ((-3671212 / 60.815356) - (-3200175 / 60.774878))) - 3200175, + # (center[1] * ((7898422 / 10.768867) - (4699978 / 10.672022))) + 4699978), + # (((center[0] - 100) * ((-3671212 / 60.815356) - (-3200175 / 60.774878))) - 3200175, + # ((center[1] - 1) * ((7898422 / 10.768867) - (4699978 / 10.672022))) + 4699978)] # Refactor lidar data to a readable format iceOver = laspy.read(lazData_path[0]) @@ -85,13 +117,48 @@ def height_in_area(center): # add two files together temporary test data(soon to be removed) ice_points = list(zip(iceOver.X,iceOver.Y,iceOver.Z)) + list(zip(iceUnder.X,iceUnder.Y,iceUnder.Z)) - # area height in all the subsections - grid_area_heights = define_gridareas(areazone, 1500, 20) + #grid_area_heights = define_gridareas(-3435693.5,6299200.0, 20000000000,4) + grid_area_heights = define_gridareas(3435693.5,7550000.0, 20000000000,4) + + print("",grid_area_heights) # find the heights of each sub-area => area-heights for sub_area in grid_area_heights: - ice_points = list(filter(lambda point_position: inArea(point_position, (sub_area[0],sub_area[2])), ice_points)) - area_heights.append(find_height(ice_points)) + + #main_vector = tuple(x - y for x, y in zip(area[2], area[0])) + #sub_vector = tuple(x - y for x, y in zip(sub_area[2][2], sub_area[2][0])) + #relative_to_laz = (tuple(x - y for x, y in zip(sub_area[2][0], area[0])), + # tuple(x + y for x, y in zip(sub_vector, sub_area[2][0]))) + #relative_to_laz = (tuple(x / y for x, y in zip(relative_to_laz[0], main_vector)), + # tuple(x / y for x, y in zip(relative_to_laz[1], sub_area[2][0]))) + #relative_to_laz = (tuple(x * y for x, y in zip(relative_to_laz[0], areazone)), + # tuple(x * y for x, y in zip(relative_to_laz[1], areazone))) + #relative_to_laz = (tuple(x + y for x, y in zip(relative_to_laz[0], start_point)), + # tuple(x + y for x, y in zip(relative_to_laz[1], start_point))) + + #print("areaZone",areazone) + #print("sub area",sub_area) + #print("relativer",relative_to_laz) + + #zone_limit = (tuple(x * y for x, y in zip(relative_to_laz, areazone)), + # tuple(x * y for x, y in zip(sub_area[2][2], areazone))) + #print("zone_limit",zone_limit) + #zone_limit = (tuple(x + y for x, y in zip(zone_limit[0], start_point)), + # tuple(x + y for x, y in zip(zone_limit[1], start_point))) + + #print("zone_limit",zone_limit) + print(type(ice_points[0])) + ice_points = list(filter(lambda point_position: inArea(point_position, ((int(-sub_area[2][0][0]),int(sub_area[2][0][1])),(int(-sub_area[2][2][0]),int(sub_area[2][2][1])))), ice_points)) + #ice_points = list(filter(lambda point_position: inArea(point_position, (((-areazone[0][0]),areazone[0][1]),(-areazone[2][0],areazone[2][1]))), ice_points)) + #ice_points = list(filter(lambda point_position: inArea(point_position, (((-3200000,7400000),(-3671212,7898422)))), ice_points)) + print("ice",ice_points) + area_heights.append((sub_area[0],sub_area[1],find_height(ice_points))) return area_heights + +print(-3>-4) +print(calculate_area_data((60.0,10.0))) + + + diff --git a/server/main.py b/server/main.py index 021581b66bad5d2d02f87f82d89824754cd1358a..5aa9dd5b75e7cac6214a3bb4de3fc6b41757595b 100644 --- a/server/main.py +++ b/server/main.py @@ -43,15 +43,15 @@ 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 - elif self.path == '/get_relation': - get_relation(self, 'Mjosa') # NB temp hardcoded value + #elif self.path == '/get_relation': + # get_relation(self, 'Mjosa') # NB temp hardcoded value def do_POST(self): if self.path == '/get_weather_data': get_weather(self) elif self.path == '/new_lidar_data': - input_new_Lidar_data(self,self.cursor, 1, 'Mjosa') # hardcoded body of water must change later + input_new_Lidar_data(self,self.cursor, 1, 'Mjosa') # 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 c1b95c053be539be6996efc2239388bcdada2a33..153eff491a414be4d1f89f774ec15cc0bcc92577 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 index 0bd02d71bf69b6ab2b4ebf9ed26a4e027128f49a..4881eedf5ef43ca958dd3f3bc08a3990387c89ae 100644 Binary files a/server/map/__pycache__/input_new_data.cpython-39.pyc and b/server/map/__pycache__/input_new_data.cpython-39.pyc differ diff --git a/server/map/input_new_data.py b/server/map/input_new_data.py index c5e2e25cb2f0c9e0c8cf00c13825b055b35a08fd..d52d93bac86442ecd7831831b234a271f7782a7f 100644 --- a/server/map/input_new_data.py +++ b/server/map/input_new_data.py @@ -1,51 +1,65 @@ import json from datetime import datetime -from server.data_processing.process_lidar_data import height_in_area +from server.data_processing.process_lidar_data import calculate_area_data # input_new_Lidar_data send new data gathered from the lidar and send it to the database (from the drone, most likely) def input_new_Lidar_data(self, cursor, sensorId, bodyOfWater): try: + # hard coded coordinates + latitude = 60.0 + longitude = 10.0 + + total_measurement_average = 0 # the total average of a measurement + # create a new measurement with the time the data is sent, sensor type, where # and an estimate of average thickness of ice on water body cursor.execute(''' - INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName, WholeAverageThickness) VALUES - (?,?,?,?); - ''', ( sensorId, datetime.utcnow().replace(microsecond=0), bodyOfWater, 0)) + INSERT INTO Measurement( SensorID, TimeMeasured, WaterBodyName, + WholeAverageThickness, CenterLat, CenterLon) VALUES + (?,?,?,?,?,?); + ''', (sensorId, datetime.utcnow().replace(microsecond=0), bodyOfWater, 0, latitude, longitude)) # auto generate new measurement id measurement_id = cursor.lastrowid - # input the newly generated measurement_id and ... average thickness (soon to be implemented) - cursor.execute(''' - UPDATE Measurement - SET measurementID = ? - WHERE MeasurementID IS NULL; - ''', (int(measurement_id),)) - # soon to be removed - cursor.execute(''' - SELECT CenterLatitude, CenterLongitude, SubDivisionID, GroupID - FROM SubDivision - GROUP BY CenterLatitude, CenterLongitude - ''') - position_data = cursor.fetchall() + # supposed get all the hardcode the coordinates of the areas we want + # cursor.execute(''' + # SELECT CenterLatitude, CenterLongitude, SubDivisionID, GroupID + # FROM SubDivision + # GROUP BY CenterLatitude, CenterLongitude + # ''') + # position_data = cursor.fetchall() + # soon to be removed - if(position_data): - for row in position_data: - latitude, longitude, subID, groupID = row - heights = height_in_area((latitude,longitude)) - if(len(heights) > 0): - print(heights) - else: - print("No height found") - average = sum(heights)/len(heights) + print("uwu") + areas_data = calculate_area_data((latitude, longitude)) + print("area") + print(areas_data) + if(areas_data): + for area in areas_data: + #if(len(area[2]) != 0): + average = sum(area[2])/len(area[2]) + #else: + #average = 0 + + total_measurement_average += average cursor.execute(''' INSERT INTO SubDivision(MeasurementID, SubDivisionID, GroupID, MinimumThickness, AverageThickness, CenterLatitude, CenterLongitude, Accuracy) VALUES (?,?,?,?,?,?,?,?); - ''',(measurement_id, subID, groupID, float(min(heights)), float(average), float(latitude), float(longitude), float(1))) + ''',(measurement_id, area[0], area[1], float(min(area[2])), float(average), float(latitude), float(longitude), float(1))) + + total_measurement_average = total_measurement_average / len(areas_data) + # input the newly generated measurement_id and whole average thickness (soon to be implemented) + cursor.execute(''' + UPDATE Measurement + SET measurementID = ? AND WholeAverageThickness = ? + WHERE MeasurementID IS NULL AND WholeAverageThickness = 0; + ''', (int(measurement_id), total_measurement_average),) else: - print('No data') + print('No data found') + print("uwu3") # send the changes to the database cursor.connection.commit()