From 0cd1b4988a98951cd0ad4e8b337eb12be7ca6aff Mon Sep 17 00:00:00 2001
From: Hoa Ben The Nguyen <hbnguye@stud.ntnu.no>
Date: Fri, 22 Mar 2024 15:32:41 +0100
Subject: [PATCH] change: add new lidar data to actual file

---
 server/data_processing/process_lidar_data.py | 7 ++++---
 server/map/input_new_data.py                 | 9 ++++++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/server/data_processing/process_lidar_data.py b/server/data_processing/process_lidar_data.py
index 540691d4..3cbba725 100644
--- a/server/data_processing/process_lidar_data.py
+++ b/server/data_processing/process_lidar_data.py
@@ -124,7 +124,7 @@ def calculate_area_data(center, body_of_water):
     min_point = min(ice_points)
 
     # define all the sub-areas within the area, local coordinates
-    grid_area_heights = define_gridareas(60,10, (cell_x, cell_y),4)
+    grid_area_heights = define_gridareas(60, 10, (cell_x, cell_y),4)
 
     # find the heights of each sub-area => area-heights
     for sub_area in grid_area_heights:
@@ -145,7 +145,8 @@ def calculate_area_data(center, body_of_water):
         sub_center = ((xs + xe)/2, (ys + ye)/2)
         if len(map_data) > 0:
             current_map_zone = closest_points(sub_center, map_data, taken_coords)
-            taken_coords.append((current_map_zone['properties']['sub_div_center'][0][0], current_map_zone['properties']['sub_div_center'][0][1]))
+            sub_center = current_map_zone['properties']['sub_div_center'][0]
+            taken_coords.append(sub_center)
         else:
             return [0]
 
@@ -158,5 +159,5 @@ def calculate_area_data(center, body_of_water):
 
     return area_heights
 
-print(calculate_area_data((61,11), 0.04,'mjosa'))
+print(calculate_area_data((61, 11), 0.04, 'mjosa'))
 
diff --git a/server/map/input_new_data.py b/server/map/input_new_data.py
index 849a75b2..a7b326b0 100644
--- a/server/map/input_new_data.py
+++ b/server/map/input_new_data.py
@@ -1,4 +1,5 @@
 import json
+import os.path
 from datetime import datetime
 from server.data_processing.process_lidar_data import calculate_area_data, about_laz_file
 
@@ -85,10 +86,17 @@ def input_new_Lidar_data(self, cursor, bodyOfWater):
         self.send_header('Content-type', "application/json")
         self.end_headers()
 
+        file_path = "../lake_relation/newest_lidar_data.json"
         content = None
+
         if len(lidar_json_data) > 0:
+            if os.path.exists(file_path):
+                os.remove(file_path)
+
             # convert list of lidar data to json
             content = json.dumps(lidar_json_data)
+            with open(file_path, "w") as file:
+                file.write(content)
         else:
             print('No data found')
             content = json.dumps([])
@@ -96,7 +104,6 @@ def input_new_Lidar_data(self, cursor, bodyOfWater):
         # Write content data to response object
         self.wfile.write(content.encode('utf-8'))
 
-
     # error handling
     except Exception as e:
         print("An error occurred", e)
-- 
GitLab