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

change: response json instead of only 200 ok

parent 14f7a8a0
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,8 @@ def calculate_area_data(center, cell_size, body_of_water):
# filter data within sub-area zones
points_in_area = list(filter(lambda point_position: inArea(point_position, areazone), ice_points))
area_heights.append((current_zone_id,sub_area[0], sub_center, find_height(points_in_area)))
heights = find_height(points_in_area)
area_heights.append((current_zone_id, sub_area[0], sub_center, heights))
return area_heights
......
......@@ -30,7 +30,10 @@ def input_new_Lidar_data(self, cursor, bodyOfWater):
# calculate the area of to be calculated based on the coordinates given to the calculation model
areas_data = calculate_area_data((latitude, longitude), 0.04, bodyOfWater)
lidar_json_data = {}
if(areas_data):
# store lidar data in jason formate
# calculate data for each zone within the area
for area in areas_data:
# lng and lat relative to map
......@@ -51,6 +54,17 @@ def input_new_Lidar_data(self, cursor, bodyOfWater):
(?,?,?,?,?,?,?,?);
''',(measurement_id, area[0], area[1], float(minimum_thickness), float(average), float(map_lat), float(map_lng), float(1)))
# set up json formate
lidar_read = {
'MeasurementId': measurement_id,
'SubId': area[0],
'GroupId': area[1],
'SubCenter': (map_lat, map_lng),
'Heights': area[2]
}
lidar_json_data.append(lidar_read)
total_measurement_average = total_measurement_average / len(areas_data)
# input the newly generated measurement_id and whole average thickness
......@@ -59,6 +73,7 @@ def input_new_Lidar_data(self, cursor, bodyOfWater):
SET measurementID = ?, WholeAverageThickness = ?
WHERE MeasurementID IS NULL AND WholeAverageThickness = 0;
''', (int(measurement_id), total_measurement_average), )
else:
print('No data found')
......@@ -67,6 +82,20 @@ def input_new_Lidar_data(self, cursor, bodyOfWater):
# Send response
self.send_response(200)
self.send_header('Content-type', "application/json")
self.end_headers()
content = None
if len(lidar_json_data) > 0:
# convert list of lidar data to json
content = json.dumps(lidar_json_data)
else:
print('No data found')
content = []
# Write content data to response object
self.wfile.write(content.encode('utf-8'))
# error handling
except Exception as e:
......
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