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

fix: random temp color generation

parent ae25702b
No related branches found
No related tags found
1 merge request!16Clhp map into main
...@@ -252,6 +252,11 @@ class _MapContainerWidgetState extends State<MapContainerWidget> { ...@@ -252,6 +252,11 @@ class _MapContainerWidgetState extends State<MapContainerWidget> {
), ),
const Divider(), const Divider(),
const SizedBox(height: 10), // Reduced padding const SizedBox(height: 10), // Reduced padding
Text(
'Tile ID: ${selectedSubDiv?.sub_div_id}',
style: regTextStyle,
),
const SizedBox(height: 20),
Text( Text(
'Measured at ', 'Measured at ',
style: subHeadingStyle, style: subHeadingStyle,
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
No preview for this file type
import os import os
import json import json
import random
from datetime import datetime from datetime import datetime
from server.consts import LAKE_RELATIONS_PATH from server.consts import LAKE_RELATIONS_PATH
...@@ -15,14 +16,14 @@ def get_measurements(self, lake_name): ...@@ -15,14 +16,14 @@ def get_measurements(self, lake_name):
lake_name (str): The name of the requested file/lake lake_name (str): The name of the requested file/lake
""" """
try: try:
print("Getting measurements...") # Define file path to lidar data file
file_path = os.path.join(LAKE_RELATIONS_PATH, lake_name + '_lidar_data.json') file_path = os.path.join(LAKE_RELATIONS_PATH, lake_name + '_lidar_data.json')
# Lists to store processed data # Lists to store processed data
sub_div_ids = [] sub_div_ids = []
measurements = [] measurements = []
# Check if the file exists # Some lakes may not have any recent lidar data, so must check if the file exists
if os.path.exists(file_path): if os.path.exists(file_path):
# Read the newest lidar data from JSON file # Read the newest lidar data from JSON file
with open(file_path, 'r') as file: with open(file_path, 'r') as file:
...@@ -31,13 +32,20 @@ def get_measurements(self, lake_name): ...@@ -31,13 +32,20 @@ def get_measurements(self, lake_name):
# Iterate over all fetched rows # Iterate over all fetched rows
for measurement in lidar_data: for measurement in lidar_data:
processed_subdivs = [] processed_subdivs = []
print("Processing measurement ", measurement['MeasurementID']) # Create new measurement object
new_measurement = {
'MeasurementID': measurement['MeasurementID'],
'TimeMeasured': str(datetime.now()),
'CenterLat': measurement['CenterLat'],
'CenterLon': measurement['CenterLon'],
'Sensor': measurement['Sensor'],
'Subdivisions': [],
}
for sub_division in measurement['Subdivisions']: for sub_division in measurement['Subdivisions']:
subdiv_id = sub_division['SubdivID'] subdiv_id = sub_division['SubdivID']
center_lat = sub_division['CenLatitude'] center_lat = sub_division['CenLatitude']
center_lng = sub_division['CenLongitude'] center_lng = sub_division['CenLongitude']
thicknesses = sub_division['Heights']
print("Processing subdivision ", subdiv_id)
# Create new subdivision object # Create new subdivision object
sub_division = { sub_division = {
...@@ -60,11 +68,15 @@ def get_measurements(self, lake_name): ...@@ -60,11 +68,15 @@ def get_measurements(self, lake_name):
processed_subdivs.append(sub_division) processed_subdivs.append(sub_division)
# Append processed measurement and subdivisions # Append processed measurement and subdivisions
measurement['Subdivisions'].append(processed_subdivs) new_measurement['Subdivisions'].append(processed_subdivs)
measurements.append(measurement) measurements.append(new_measurement)
# Populate remaining subdivisions and create "invalid" or "proxy" measurement to store them # Populate remaining non-processed subdivisions and create "invalid" or "proxy" measurement to store them
remaining_sub_divs = fill_remaining_subdivisions(lake_name, sub_div_ids) remaining_sub_divs = fill_remaining_subdivisions(lake_name, sub_div_ids)
print("Len remaining_sub_divs: ", len(remaining_sub_divs))
print("Sub_div_ids: ", sub_div_ids)
print("Len measurements: ", len(measurements))
measurements[-1] = { measurements[-1] = {
'MeasurementID': -1, 'MeasurementID': -1,
'TimeMeasured': str(datetime.now()), 'TimeMeasured': str(datetime.now()),
...@@ -131,17 +143,19 @@ def fill_remaining_subdivisions(lake_name: str, sub_div_ids: list): ...@@ -131,17 +143,19 @@ def fill_remaining_subdivisions(lake_name: str, sub_div_ids: list):
# Fetch weather data for each subdivision from the NVE model # Fetch weather data for each subdivision from the NVE model
ice_stats = get_raw_dates(ice_prognosis_raw_data(sub_div_id=sub_div_id, x=center_lat, y=center_lng)) ice_stats = get_raw_dates(ice_prognosis_raw_data(sub_div_id=sub_div_id, x=center_lat, y=center_lng))
total_ice_thickness = ice_stats[0]['Total ice (m)']
# Create new subdivision object # Create new subdivision object
sub_division = { sub_division = {
'SubdivID': sub_div_id, 'SubdivID': sub_div_id,
'GroupID': None, 'GroupID': None,
'MinThickness': -1.0, # NB placeholders 'MinThickness': total_ice_thickness,
'AvgThickness': ice_stats[0]['Total ice (m)'], 'AvgThickness': total_ice_thickness,
'CenLatitude': center_lat, 'CenLatitude': center_lat,
'CenLongitude': center_lng, 'CenLongitude': center_lng,
'Accuracy': None, 'Accuracy': None,
# Calculate ice thickness based on total ice, temporary # Calculate ice thickness based on total ice, temporary
'Color': calculateColor(ice_stats[0]['Total ice (m)']), # 'Color': calculateColor(ice_stats[0]['Total ice (m)']),
'Color': calculateColor(random.randint(0, 20)), # NB placeholder
'IceStats': ice_stats, 'IceStats': ice_stats,
} }
sub_divisions.append(sub_division) sub_divisions.append(sub_division)
......
[ [
"Mjøsa", "Mjøsa",
"Skumsjøen", "Skumsjøen"
"Mjsa",
"Skumsjen"
] ]
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
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