Skip to content
Snippets Groups Projects
Commit 5cdd206c authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

add: update scheduler

parent 936abf7b
No related branches found
No related tags found
1 merge request!16Clhp map into main
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -7,6 +7,7 @@ from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT
from http.server import HTTPServer, BaseHTTPRequestHandler
from map_handler.add_new_lake import cut_map
from server.scheduler import update_scheduler
from server.consts import LAKE_RELATIONS_PATH
from map_handler.get_lake_relation import get_map_data
from map_handler.get_measurements import get_measurements
......@@ -148,6 +149,9 @@ if __name__ == "__main__":
print("Server running on port ", PORT)
# Initialise the scheduler for updating lakes
update_scheduler()
# Run server indefinitely
server.serve_forever()
......
......@@ -7,12 +7,11 @@ from server.consts import LAKE_RELATIONS_PATH
from server.ModelFromNVE.icemodellingscripts.getIceThicknessLakes import get_raw_dates, ice_prognosis_raw_data
def get_measurements(self, lake_name):
def get_measurements(lake_name):
"""
Retrieves LiDar data for a given lake, and adds weather data to each subdivision.
Parameters:
self (BaseHTTPRequestHandler): A instance of a BaseHTTPRequestHandler
lake_name (str): The name of the requested file/lake
"""
try:
......@@ -92,28 +91,8 @@ def get_measurements(self, lake_name):
with open(LAKE_RELATIONS_PATH + lake_name.lower() + '_measurements.json', 'w') as f:
json.dump(measurements, f)
if len(measurements) == 0:
response_data = json.dumps(['no measurements'])
else:
# Convert list of dictionaries to JSON
response_data = json.dumps(measurements, indent=4)
except Exception as e:
print(f"Error in getting measurements: {e}")
response_data = '[]'
# Set headers
self.send_response(500)
self.send_header("Content-type", "application/json")
self.end_headers()
# Set headers
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
# Write processed data to response object
self.wfile.write(response_data.encode('utf-8'))
print(f"Error in updating measurements: {e}")
def fill_remaining_subdivisions(lake_name: str, sub_div_ids: list):
......
......@@ -12,7 +12,7 @@
"Subdivisions": [
{
"SubdivID": 36,
"MinThickness": -1.0,
"MinThickness": 0.4,
"AvgThickness": 1.0,
"CenLatitude": 60.841532,
"CenLongitude": 10.717878,
......@@ -20,7 +20,7 @@
},
{
"SubdivID": 83,
"MinThickness": -1.0,
"MinThickness": 5.5,
"AvgThickness": 14.0,
"CenLatitude": 60.828326,
"CenLongitude": 10.982563,
......@@ -28,7 +28,7 @@
},
{
"SubdivID": 33,
"MinThickness": -1.0,
"MinThickness": 0.0,
"AvgThickness": 1.0,
"CenLatitude": 60.771059,
"CenLongitude": 10.698341,
......@@ -36,11 +36,67 @@
},
{
"SubdivID": 136,
"MinThickness": -1.0,
"MinThickness": 5.5,
"AvgThickness": 9.0,
"CenLatitude": 60.396856,
"CenLongitude": 11.220933,
"Accuracy": 2
},
{
"SubdivID": 0,
"MinThickness": 7.0,
"AvgThickness": 8.2,
"CenLatitude": 60.396856,
"CenLongitude": 11.220933,
"Accuracy": 2
},
{
"SubdivID": 1,
"MinThickness": 0.4,
"AvgThickness": 5.0,
"CenLatitude": 60.396856,
"CenLongitude": 11.220933,
"Accuracy": 2
},
{
"SubdivID": 3,
"MinThickness": 1.0,
"AvgThickness": 4.0,
"CenLatitude": 60.345355,
"CenLongitude": 11.220933,
"Accuracy": 2
},
{
"SubdivID": 4,
"MinThickness": 2.0,
"AvgThickness": 4.0,
"CenLatitude": 60.202034,
"CenLongitude": 11.890890,
"Accuracy": 2
},
{
"SubdivID": 5,
"MinThickness": 2.3,
"AvgThickness": 7.3,
"CenLatitude": 60.45367,
"CenLongitude": 11.43533,
"Accuracy": 2
},
{
"SubdivID": 6,
"MinThickness": 1.0,
"AvgThickness": 2.2,
"CenLatitude": 60.45367,
"CenLongitude": 11.43533,
"Accuracy": 2
},
{
"SubdivID": 7,
"MinThickness": 4.0,
"AvgThickness": 8.2,
"CenLatitude": 60.45367,
"CenLongitude": 11.43533,
"Accuracy": 2
}
]
}
......
import json
import time
import schedule
from map_handler.get_measurements import get_measurements
from server.consts import LAKE_RELATIONS_PATH
def update_all_measurements(lake_names: list):
"""Loops through all lake names and calls get_measurements() on each lake"""
for lake in lake_names:
get_measurements(lake)
def update_scheduler():
"""Schedules the updating of all maps every three days"""
print("Updating all lake data. This may take some time...")
# Parse all lake names to a list
with open(LAKE_RELATIONS_PATH + 'all_lake_names.json', 'r') as file:
lake_names = json.load(file)
# Run update_all_measurements on startup
update_all_measurements(lake_names)
# Schedule the updating of all maps every three days
schedule.every(3).days.do(update_all_measurements(lake_names))
# Keep scheduler running indefinitely
while True:
schedule.run_pending()
time.sleep(1)
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