Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2900
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sara Savanovic Djordjevic
PROG2900
Commits
ed5fc52f
Commit
ed5fc52f
authored
10 months ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: som error hadling in get_measurements.py
parent
b21b134f
No related branches found
Branches containing commit
No related tags found
1 merge request
!16
Clhp map into main
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/main.py
+1
-1
1 addition, 1 deletion
server/main.py
server/map_handler/get_measurements.py
+46
-40
46 additions, 40 deletions
server/map_handler/get_measurements.py
server/map_handler/lake_relations/mjøsa_lidar_data.json
+5
-5
5 additions, 5 deletions
server/map_handler/lake_relations/mjøsa_lidar_data.json
with
52 additions
and
46 deletions
server/main.py
+
1
−
1
View file @
ed5fc52f
...
...
@@ -81,7 +81,7 @@ class IceHTTP(BaseHTTPRequestHandler):
lake_name
=
unquote
(
lake_name_param
)
# Decode url param
if
lake_name_param
:
get_measurements
(
self
,
cursor
,
lake_name
)
get_measurements
(
self
,
lake_name
)
else
:
self
.
send_response
(
400
)
self
.
send_header
(
'
Content-type
'
,
'
application/json
'
)
...
...
This diff is collapsed.
Click to expand it.
server/map_handler/get_measurements.py
+
46
−
40
View file @
ed5fc52f
import
os
import
json
from
datetime
import
datetime
...
...
@@ -5,7 +6,7 @@ from server.consts import LAKE_RELATIONS_PATH
from
server.ModelFromNVE.icemodellingscripts.getIceThicknessLakes
import
get_raw_dates
,
ice_prognosis_raw_data
def
get_measurements
(
self
,
cursor
,
lake_name
):
def
get_measurements
(
self
,
lake_name
):
"""
Retrieves LiDar data for a given lake, and adds weather data to each subdivision.
...
...
@@ -15,42 +16,47 @@ def get_measurements(self, cursor, lake_name):
lake_name (str): The name of the requested file/lake
"""
try
:
# Read the newest lidar data from JSON file
with
open
(
LAKE_RELATIONS_PATH
+
lake_name
+
'
_lidar_data.json
'
,
'
r
'
)
as
file
:
lidar_data
=
json
.
load
(
file
)
file_path
=
os
.
path
.
join
(
LAKE_RELATIONS_PATH
,
lake_name
+
'
_measurements.json
'
)
sub_div_ids
=
[]
# Iterate over all fetched rows
for
measurement
in
lidar_data
:
for
sub_division
in
measurement
[
'
Subdivisions
'
]:
measurement_id
=
measurement
[
'
MeasurementID
'
]
subdiv_id
=
sub_division
[
'
SubdivID
'
]
center_lat
=
sub_division
[
'
CenLatitude
'
]
center_lng
=
sub_division
[
'
CenLongitude
'
]
# Create new subdivision object
sub_division
=
{
'
SubdivID
'
:
subdiv_id
,
'
GroupID
'
:
0
,
'
MinThickness
'
:
sub_division
[
'
MinThickness
'
],
'
AvgThickness
'
:
sub_division
[
'
AvgThickness
'
],
'
CenLatitude
'
:
center_lat
,
'
CenLongitude
'
:
center_lng
,
'
Accuracy
'
:
sub_division
[
'
Accuracy
'
],
'
Color
'
:
calculateColor
(
sub_division
[
'
MinThickness
'
],
),
# NB color calculated based on average thickness, should be minimum
# Fetch weather data from the NVE model
'
IceStats
'
:
get_raw_dates
(
ice_prognosis_raw_data
(
sub_div_id
=
subdiv_id
,
x
=
center_lat
,
y
=
center_lng
))
}
sub_div_ids
.
append
(
subdiv_id
)
lidar_data
[
measurement_id
][
'
Subdivisions
'
].
append
(
sub_division
)
measurements
=
[]
# Check if the file exists
if
os
.
path
.
exists
(
file_path
):
# Read the newest lidar data from JSON file
with
open
(
LAKE_RELATIONS_PATH
+
lake_name
+
'
_measurements.json
'
,
'
r
'
)
as
file
:
measurements
=
json
.
load
(
file
)
# Iterate over all fetched rows
for
measurement
in
measurements
:
for
sub_division
in
measurement
[
'
Subdivisions
'
]:
measurement_id
=
measurement
[
'
MeasurementID
'
]
subdiv_id
=
sub_division
[
'
SubdivID
'
]
center_lat
=
sub_division
[
'
CenLatitude
'
]
center_lng
=
sub_division
[
'
CenLongitude
'
]
# Create new subdivision object
sub_division
=
{
'
SubdivID
'
:
subdiv_id
,
'
GroupID
'
:
0
,
'
MinThickness
'
:
sub_division
[
'
MinThickness
'
],
'
AvgThickness
'
:
sub_division
[
'
AvgThickness
'
],
'
CenLatitude
'
:
center_lat
,
'
CenLongitude
'
:
center_lng
,
'
Accuracy
'
:
sub_division
[
'
Accuracy
'
],
'
Color
'
:
calculateColor
(
sub_division
[
'
MinThickness
'
],
),
# NB color calculated based on average thickness, should be minimum
# Fetch weather data from the NVE model
'
IceStats
'
:
get_raw_dates
(
ice_prognosis_raw_data
(
sub_div_id
=
subdiv_id
,
x
=
center_lat
,
y
=
center_lng
))
}
sub_div_ids
.
append
(
subdiv_id
)
measurements
[
measurement_id
][
'
Subdivisions
'
].
append
(
sub_division
)
# Populate remaining subdivisions and create "invalid" or "proxy" measurement to store them
remaining_sub_divs
=
fill_remaining_subdivisions
(
lake_name
,
sub_div_ids
)
lidar_data
[
-
1
]
=
{
measurements
[
-
1
]
=
{
'
MeasurementID
'
:
-
1
,
'
TimeMeasured
'
:
str
(
datetime
.
now
()),
'
CenterLat
'
:
None
,
...
...
@@ -60,21 +66,21 @@ def get_measurements(self, cursor, lake_name):
}
# Convert dictionary values to list of measurements
data
=
list
(
lidar_data
.
values
())
data
=
list
(
measurements
.
values
())
# Write the newest measurements to file
with
open
(
LAKE_RELATIONS_PATH
+
lake_name
.
lower
()
+
'
_
lidar_data
.json
'
,
'
w
'
)
as
f
:
with
open
(
LAKE_RELATIONS_PATH
+
lake_name
.
lower
()
+
'
_
measurements
.json
'
,
'
w
'
)
as
f
:
json
.
dump
(
data
,
f
)
if
len
(
data
)
==
0
:
marker
_data
=
json
.
dumps
([
'
no measurements
'
])
response
_data
=
json
.
dumps
([
'
no measurements
'
])
else
:
# Convert list of dictionaries to JSON
marker
_data
=
json
.
dumps
(
data
,
indent
=
4
)
response
_data
=
json
.
dumps
(
data
,
indent
=
4
)
except
Exception
as
e
:
print
(
f
"
Error in getting measurements:
{
e
}
"
)
marker
_data
=
'
[]
'
response
_data
=
'
[]
'
# Set headers
self
.
send_response
(
500
)
...
...
@@ -86,8 +92,8 @@ def get_measurements(self, cursor, lake_name):
self
.
send_header
(
"
Content-type
"
,
"
application/json
"
)
self
.
end_headers
()
# Write
marker
data to response object
self
.
wfile
.
write
(
marker
_data
.
encode
(
'
utf-8
'
))
# Write
processed
data to response object
self
.
wfile
.
write
(
response
_data
.
encode
(
'
utf-8
'
))
def
fill_remaining_subdivisions
(
lake_name
:
str
,
sub_div_ids
:
list
):
...
...
This diff is collapsed.
Click to expand it.
server/map_handler/lake_relations/mjøsa_lidar_data.json
+
5
−
5
View file @
ed5fc52f
...
...
@@ -4,7 +4,7 @@
"TimeMeasured"
:
"2024-04-15 16:23:28.620516"
,
"CenterLat"
:
60.841532
,
"CenterLon"
:
10.717878
,
"Sensor"
:
null
,
"Sensor"
:
2
,
"Subdivisions"
:
[
{
"SubdivID"
:
36
,
...
...
@@ -12,7 +12,7 @@
"AvgThickness"
:
1
,
"CenLatitude"
:
60.841532
,
"CenLongitude"
:
10.717878
,
"Accuracy"
:
null
,
"Accuracy"
:
2
,
"Heights"
:
[
1
]
},
{
...
...
@@ -21,7 +21,7 @@
"AvgThickness"
:
14
,
"CenLatitude"
:
60.828326
,
"CenLongitude"
:
10.982563
,
"Accuracy"
:
null
,
"Accuracy"
:
2
,
"Heights"
:
[
1
,
27
]
},
{
...
...
@@ -30,7 +30,7 @@
"AvgThickness"
:
1
,
"CenLatitude"
:
60.771059
,
"CenLongitude"
:
10.698341
,
"Accuracy"
:
null
,
"Accuracy"
:
2
,
"Heights"
:
[
1
]
},
{
...
...
@@ -39,7 +39,7 @@
"AvgThickness"
:
9
,
"CenLatitude"
:
60.396856
,
"CenLongitude"
:
11.220933
,
"Accuracy"
:
null
,
"Accuracy"
:
2
,
"Heights"
:
[
1
,
4
,
6
,
27
,
7
]
}
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment