diff --git a/server/ModelFromNVE/icemodellingscripts/__pycache__/getIceThicknessLakes.cpython-311.pyc b/server/ModelFromNVE/icemodellingscripts/__pycache__/getIceThicknessLakes.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dbdeee0ef194c9bd40333ba43d750871ae4b282c Binary files /dev/null and b/server/ModelFromNVE/icemodellingscripts/__pycache__/getIceThicknessLakes.cpython-311.pyc differ diff --git a/server/consts.py b/server/consts.py index da41c583663051f30bcd6929ba92f389dd06084a..a667ac84a59424ea4130bb890349b34e7a37ff3d 100644 --- a/server/consts.py +++ b/server/consts.py @@ -12,5 +12,3 @@ SSL_CERT_PATH = CERT_DIR + "testCert.crt" # File paths MAP_HANDLER_PATH = "server/map_handler/" LAKE_RELATIONS_PATH = MAP_HANDLER_PATH + "lake_relations/" -PLOT_PATH = "server/ModelFromNVE/output/plots/" - diff --git a/server/map_handler/__pycache__/get_measurements.cpython-311.pyc b/server/map_handler/__pycache__/get_measurements.cpython-311.pyc index 314075cb96602386e95eef9e467a519de7802523..f8e3968878f7c56a0b929781e777cc9c39aa4023 100644 Binary files a/server/map_handler/__pycache__/get_measurements.cpython-311.pyc and b/server/map_handler/__pycache__/get_measurements.cpython-311.pyc differ diff --git a/server/map_handler/__pycache__/input_new_data.cpython-311.pyc b/server/map_handler/__pycache__/input_new_data.cpython-311.pyc index 7f959582f8d78d8341fb2f14b0c7bfc033a99259..6b7334b408e14cb1b5f4a0e804b3394cae03dbc6 100644 Binary files a/server/map_handler/__pycache__/input_new_data.cpython-311.pyc and b/server/map_handler/__pycache__/input_new_data.cpython-311.pyc differ diff --git a/server/map_handler/get_measurements.py b/server/map_handler/get_measurements.py index 61c48dcdac0d8426ad195c4515e9725855abd006..e19b099a14cccd24f3ff200832e297d18437e9e5 100644 --- a/server/map_handler/get_measurements.py +++ b/server/map_handler/get_measurements.py @@ -1,124 +1,9 @@ import json -import random -from datetime import datetime -from server.consts import PLOT_PATH +from server.ModelFromNVE.icemodellingscripts.getIceThicknessLakes import get_raw_dates, ice_prognosis_raw_data -# get_markers requests all marker data or valid markers, converts the data to json, and writes -# the data to the response object def get_measurements(self, cursor, lake_name): try: - print("Lake name in get_measurements: ", lake_name) - sql_query = ''' - SELECT m.MeasurementID, m.SensorID, m.TimeMeasured, m.CenterLat, m.CenterLon, - s.SensorType, s.Active, - b.Name, - d.SubDivisionID, d.GroupID, d.MinimumThickness, - d.AverageThickness, d.CenterLatitude, d.CenterLongitude, - d.Accuracy - FROM Measurement m - INNER JOIN Sensor s ON m.SensorID = s.SensorID - INNER JOIN BodyOfWater b ON m.WaterBodyName = b.Name - LEFT JOIN SubDivision d ON m.MeasurementID = d.MeasurementID - WHERE b.Name = ? - ''' - - cursor.execute(sql_query, (lake_name,)) - - rows = cursor.fetchall() - - # List of all fetched measurement objects - measurement_data = {} - - ''' - f = open('server/?') - data = json.load(f) - - ''' - # Iterate over all fetched rows - for row in rows: - measurement_id = row[0] - sub_div_id = row[8] - center_lat = row[12] - center_lng = row[13] - - ''' - curr_stat = [] - - # Find matching ice stat - for stat in data['stats'] - if ice_stats.sub_div_id == sub_div_id - curr_stat = stat - break - ''' - - # Create subdivision new object - sub_division = { - 'SubdivID': sub_div_id, - 'GroupID': row[9], - 'MinThickness': row[10], - 'AvgThickness': row[11], - 'CenLatitude': center_lat, - 'CenLongitude': center_lng, - 'Accuracy': row[14], - 'Color': calculateColor(row[11]), # NB color calculated based on average thickness, should be minimum - 'IceStats': () # NB temp empty, add ice stats later - } - - # Check if measurement ID already exists in measurement_data - if measurement_id in measurement_data: - # Create new subdivision within measurement if it does not already exist - if sub_division not in measurement_data[measurement_id]['Subdivisions']: - measurement_data[measurement_id]['Subdivisions'].append(sub_division) - - else: - # Create a new entry for measurement_id if it does not already exist in the list - measurement_data[measurement_id] = { - 'MeasurementID': measurement_id, - 'TimeMeasured': row[2], - 'CenterLat': row[3], - 'CenterLon': row[4], - 'Sensor': { # Each measurement only has one related sensor - 'SensorID': row[1], - 'SensorType': row[5], - 'Active': bool(row[6]) - }, - 'Subdivisions': [sub_division], # Array of sub_division objects - } - - # NB remember to clos file after implementation - # f.close() - - # Convert dictionary values to list of measurements - data = list(measurement_data.values()) - - if len(data) == 0: - marker_data = json.dumps(['no measurements']) - else: - # Convert list of dictionaries to JSON - marker_data = json.dumps(data, indent=4) - - except Exception as e: - print(f"Error in querying database: {e}") - marker_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 marker data to response object - self.wfile.write(marker_data.encode('utf-8')) - - -def get_measurements(self, cursor, lake_name): - try: - print("Lake name in get_measurements: ", lake_name) sql_query = ''' SELECT m.MeasurementID, m.SensorID, m.TimeMeasured, m.CenterLat, m.CenterLon, s.SensorType, s.Active, @@ -161,6 +46,10 @@ def get_measurements(self, cursor, lake_name): curr_stat = stat break ''' + # NB test + print("sub_div_id before call: ", sub_div_id, " center lat and lng: ", center_lng, " ", center_lng) + ice_stats = get_raw_dates(ice_prognosis_raw_data(sub_div_id, center_lat, center_lng)) + print("ice stats:", ice_stats[0]) # Create subdivision new object sub_division = { @@ -172,7 +61,7 @@ def get_measurements(self, cursor, lake_name): 'CenLongitude': center_lng, 'Accuracy': row[14], 'Color': calculateColor(row[11]), # NB color calculated based on average thickness, should be minimum - 'IceStats': () # NB temp empty, add ice stats later + 'IceStats': get_raw_dates(ice_prognosis_raw_data(sub_div_id, center_lat, center_lng)) } # Check if measurement ID already exists in measurement_data @@ -196,8 +85,6 @@ def get_measurements(self, cursor, lake_name): 'Subdivisions': [sub_division], # Array of sub_division objects } - # Add ice stats - # NB remember to clos file after implementation # f.close() @@ -211,7 +98,7 @@ def get_measurements(self, cursor, lake_name): marker_data = json.dumps(data, indent=4) except Exception as e: - print(f"Error in querying database: {e}") + print(f"Error in getting measurements: {e}") marker_data = '[]' # Set headers @@ -239,5 +126,3 @@ def calculateColor(thickness: float): # NB neither final colors nor ranges return 0xFF00d6ff # Blue else: return 0xFF939393 # Gray - -#def addIceStats(lake: str, measurements: list):