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

fix: update_data every 1 and 3 days

parent 7be7db5f
Branches
No related tags found
1 merge request!21Clhp map
This diff is collapsed.
This diff is collapsed.
...@@ -22,3 +22,5 @@ interval_from,interval_to,default_B0_min,default_B0_max,default_B0_mean,default_ ...@@ -22,3 +22,5 @@ interval_from,interval_to,default_B0_min,default_B0_max,default_B0_mean,default_
2024-04-16,2024-04-17,117.0,168.0,134.57,5.88,65536,0,Ice 2024-04-16,2024-04-17,117.0,168.0,134.57,5.88,65536,0,Ice
2024-04-21,2024-04-22,152.0,255.0,192.65,8.99,65536,0,No ice 2024-04-21,2024-04-22,152.0,255.0,192.65,8.99,65536,0,No ice
2024-05-04,2024-05-05,115.0,157.0,133.92,5.15,65536,0,Ice 2024-05-04,2024-05-05,115.0,157.0,133.92,5.15,65536,0,Ice
2024-05-14,2024-05-15,145.0,214.0,183.21,10.97,65536,0,No ice
2024-05-16,2024-05-17,126.0,174.0,148.16,6.77,65536,0,No ice
interval_from,interval_to,default_B0_min,default_B0_max,default_B0_mean,default_B0_stDev,default_B0_sampleCount,default_B0_noDataCount,ice_condition
2023-09-12,2023-09-13,52.0,192.0,115.82,17.09,65536,0,No ice
2023-09-17,2023-09-18,143.0,236.0,193.38,9.43,65536,0,No ice
2023-09-24,2023-09-25,155.0,223.0,186.53,8.26,65536,0,No ice
2023-10-02,2023-10-03,72.0,255.0,146.67,18.72,65536,0,No ice
2023-10-04,2023-10-05,132.0,184.0,156.12,5.82,65536,0,Ice
2023-10-12,2023-10-13,144.0,255.0,186.95,10.86,65536,0,No ice
2023-10-17,2023-10-18,157.0,235.0,193.67,8.66,65536,0,No ice
2023-10-19,2023-10-20,141.0,203.0,168.37,7.47,65536,0,No ice
2023-11-18,2023-11-19,163.0,253.0,202.24,11.41,65536,0,No ice
2023-12-03,2023-12-04,142.0,229.0,179.99,12.65,65536,0,No ice
2023-12-23,2023-12-24,103.0,122.0,111.55,2.58,65536,0,Ice
2023-12-26,2023-12-27,109.0,122.0,115.83,1.68,65536,0,Ice
2024-01-05,2024-01-06,107.0,117.0,111.94,1.32,65536,0,Ice
2024-01-25,2024-01-26,115.0,124.0,119.55,1.05,65536,0,Ice
2024-02-01,2024-02-02,114.0,128.0,118.01,1.26,65536,0,Ice
2024-02-09,2024-02-10,116.0,124.0,120.14,1.02,65536,0,Ice
2024-02-21,2024-02-22,120.0,126.0,122.65,0.75,65536,0,Ice
2024-02-26,2024-02-27,125.0,194.0,132.46,1.72,65536,0,Ice
2024-03-07,2024-03-08,128.0,236.0,166.79,20.65,65536,0,No ice
2024-03-12,2024-03-13,122.0,211.0,149.52,14.76,65536,0,No ice
2024-04-01,2024-04-02,122.0,238.0,154.82,14.9,65536,0,No ice
2024-04-16,2024-04-17,118.0,155.0,132.93,4.43,65536,0,Ice
2024-04-21,2024-04-22,82.0,216.0,179.98,22.89,65536,0,No ice
2024-05-04,2024-05-05,115.0,142.0,128.32,3.22,65536,0,Ice
2024-05-14,2024-05-15,136.0,199.0,169.73,10.25,65536,0,No ice
2024-05-16,2024-05-17,130.0,170.0,151.3,5.28,65536,0,Ice
interval_from,interval_to,default_B0_min,default_B0_max,default_B0_mean,default_B0_stDev,default_B0_sampleCount,default_B0_noDataCount,ice_condition
2023-09-12,2023-09-13,74.0,142.0,102.76,7.69,65536,0,No ice
2023-09-17,2023-09-18,155.0,255.0,202.76,10.26,65536,0,No ice
2023-09-24,2023-09-25,150.0,228.0,188.82,8.75,65536,0,No ice
2023-10-02,2023-10-03,128.0,185.0,156.82,6.72,65536,0,No ice
2023-10-04,2023-10-05,130.0,181.0,153.85,5.81,65536,0,Ice
2023-10-12,2023-10-13,148.0,242.0,188.78,11.45,65536,0,No ice
2023-10-17,2023-10-18,155.0,246.0,194.54,10.6,65536,0,No ice
2023-10-19,2023-10-20,137.0,209.0,168.83,7.8,65536,0,No ice
2023-11-18,2023-11-19,148.0,255.0,204.29,11.69,65536,0,No ice
2023-12-03,2023-12-04,100.0,246.0,180.18,13.13,65536,0,No ice
2023-12-23,2023-12-24,95.0,123.0,109.04,3.18,65536,0,Ice
2023-12-26,2023-12-27,127.0,240.0,176.32,13.55,65536,0,No ice
2024-01-05,2024-01-06,101.0,171.0,120.39,11.0,65536,0,No ice
2024-01-25,2024-01-26,115.0,123.0,119.01,1.07,65536,0,Ice
2024-02-01,2024-02-02,113.0,121.0,116.6,1.07,65536,0,Ice
2024-02-09,2024-02-10,116.0,124.0,119.9,0.88,65536,0,Ice
2024-02-21,2024-02-22,120.0,127.0,123.23,0.77,65536,0,Ice
2024-02-26,2024-02-27,125.0,135.0,131.35,1.21,65536,0,Ice
2024-03-07,2024-03-08,120.0,188.0,140.44,11.06,65536,0,No ice
2024-03-12,2024-03-13,118.0,175.0,136.15,9.75,65536,0,No ice
2024-04-01,2024-04-02,123.0,175.0,136.53,4.16,65536,0,Ice
2024-04-16,2024-04-17,114.0,145.0,124.9,2.56,65536,0,Ice
2024-04-21,2024-04-22,155.0,230.0,188.39,8.43,65536,0,No ice
2024-05-04,2024-05-05,116.0,148.0,131.24,3.88,65536,0,Ice
2024-05-14,2024-05-15,141.0,208.0,174.17,7.8,65536,0,No ice
2024-05-16,2024-05-17,121.0,178.0,151.29,7.98,65536,0,No ice
No preview for this file type
import ssl import ssl
import json import json
import sqlite3 import sqlite3
import threading
from flask import Flask from flask import Flask
from urllib.parse import urlparse, parse_qs, unquote from urllib.parse import urlparse, parse_qs, unquote
from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT from consts import SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT
...@@ -164,11 +165,14 @@ class IceHTTP(BaseHTTPRequestHandler): ...@@ -164,11 +165,14 @@ class IceHTTP(BaseHTTPRequestHandler):
self.send_header('Content-type', 'application/json') self.send_header('Content-type', 'application/json')
self.end_headers() self.end_headers()
#def do_POST(self):
# Start a server on port 8443 using self defined HTTP class # Start a server on port 8443 using self defined HTTP class
if __name__ == "__main__": if __name__ == "__main__":
try: try:
# Run the automatic updating of measurement data in a dedicated thread
scheduler_thread = threading.Thread(target=update_scheduler)
scheduler_thread.start()
# Initialize database connection # Initialize database connection
conn = sqlite3.connect('server/database/icedb') conn = sqlite3.connect('server/database/icedb')
cursor = conn.cursor() cursor = conn.cursor()
......
...@@ -14,6 +14,7 @@ def update_all_measurements(update_bbox: bool): ...@@ -14,6 +14,7 @@ def update_all_measurements(update_bbox: bool):
update_bbox (bool): Whether the bboxes should be updated or not. update_bbox (bool): Whether the bboxes should be updated or not.
""" """
try:
# Parse all lake names to a list. Set encoding to utf-8 to retain scandinavian characters # Parse all lake names to a list. Set encoding to utf-8 to retain scandinavian characters
with open(LAKE_RELATIONS_PATH + 'all_lake_names.json', 'r', encoding='utf-8') as file: with open(LAKE_RELATIONS_PATH + 'all_lake_names.json', 'r', encoding='utf-8') as file:
lake_names = json.load(file) lake_names = json.load(file)
...@@ -23,14 +24,21 @@ def update_all_measurements(update_bbox: bool): ...@@ -23,14 +24,21 @@ def update_all_measurements(update_bbox: bool):
from_date = "2024-01-10" from_date = "2024-01-10"
to_date = "2024-01-20" to_date = "2024-01-20"
update_data(from_date, to_date, lake_name=lake_names, # Updates the data from the NVE model
sub_divs_folder=LAKE_RELATIONS_PATH + lake_names + '_centers.txt', update_all_bboxes=update_bbox) update_data(from_date, to_date, lake_name=lake,
sub_divs_folder=LAKE_RELATIONS_PATH + lake + '_centers.txt', update_all_bboxes=update_bbox)
# Updates all the measurements for the current lake
update_measurements_handler(None, lake) update_measurements_handler(None, lake)
print("\t", lake, " updated")
except Exception as e:
print(f"Failed in update_all_measurements(...): {e}")
def update_scheduler(): def update_scheduler():
"""Schedules the updating of all maps every three days""" """Schedules the updating of all maps every three days"""
try:
print("Updating all lake data. This may take some time...") print("Updating all lake data. This may take some time...")
# Run update_all_measurements on startup # Run update_all_measurements on startup
...@@ -45,3 +53,6 @@ def update_scheduler(): ...@@ -45,3 +53,6 @@ def update_scheduler():
while True: while True:
schedule.run_pending() schedule.run_pending()
time.sleep(1) time.sleep(1)
except Exception as e:
print(f"Failed to schedule updates: {e}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment