Skip to content
Snippets Groups Projects
Commit 33af0684 authored by Hoa Ben The Nguyen's avatar Hoa Ben The Nguyen
Browse files

add: file structure, moved update feature to nrew file

parent ab034eb1
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
......@@ -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])
......
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):
......
No preview for this file type
File added
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
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
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