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
38692c43
Commit
38692c43
authored
1 year ago
by
Sara Savanovic Djordjevic
Browse files
Options
Downloads
Patches
Plain Diff
update: sql_query, non-functional
parent
9dd173b5
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
App2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/main.py
+4
-4
4 additions, 4 deletions
server/main.py
server/map/__pycache__/get_markers.cpython-311.pyc
+0
-0
0 additions, 0 deletions
server/map/__pycache__/get_markers.cpython-311.pyc
server/map/get_markers.py
+19
-30
19 additions, 30 deletions
server/map/get_markers.py
with
23 additions
and
34 deletions
server/main.py
+
4
−
4
View file @
38692c43
...
...
@@ -37,11 +37,11 @@ class IceHTTP(BaseHTTPRequestHandler):
self
.
wfile
.
write
(
b
"
Root path hit!
"
)
elif
self
.
path
==
'
/update_map
'
:
# NB: should be POST?
get_all_markers
(
self
,
self
.
cursor
,
False
)
# Get all markers
get_all_markers
(
self
,
self
.
cursor
,
False
,
'
Mjosa
'
)
# Get all markers
# NB: temporary hardcoded waterBodyName
elif
self
.
path
==
'
/get_valid_markers
'
:
# NB: should be POST?
get_all_markers
(
self
,
self
.
cursor
,
True
)
# Get only valid markers
get_all_markers
(
self
,
self
.
cursor
,
True
,
'
Mjosa
'
)
# Get only valid markers
# NB: temporary hardcoded waterBodyName
def
do_POST
(
self
):
if
self
.
path
==
'
/get_weather_data
'
:
get_weather
(
self
)
...
...
This diff is collapsed.
Click to expand it.
server/map/__pycache__/get_markers.cpython-311.pyc
+
0
−
0
View file @
38692c43
No preview for this file type
This diff is collapsed.
Click to expand it.
server/map/get_markers.py
+
19
−
30
View file @
38692c43
...
...
@@ -5,35 +5,24 @@ import json
# the data to the response object
def
get_all_markers
(
self
,
cursor
,
valid
:
bool
,
waterBodyName
):
try
:
# NB: interval temporarily hard coded to 5 days
if
valid
:
cursor
.
execute
(
'''
SELECT m.MeasurementID, m.SensorID, m.TimeMeasured,
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 m.TimeMeasured > DATE_SUB(NOW(), INTERVAL 5 DAY) & b.Name = ?
'''
,
waterBodyName
)
else
:
cursor
.
execute
(
'''
SELECT m.MeasurementID, m.SensorID, m.TimeMeasured,
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 = ?
'''
,
waterBodyName
)
sql_query
=
'''
SELECT m.MeasurementID, m.SensorID, m.TimeMeasured,
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 = ?
'''
if
valid
:
# Append time restriction, NB temporarily hardcoded to 5 days
sql_query
+=
'
AND m.TimeMeasured > DATE_SUB(NOW(), INTERVAL 5 DAY)
'
cursor
.
execute
(
sql_query
,
(
waterBodyName
,))
rows
=
cursor
.
fetchall
()
...
...
@@ -88,7 +77,7 @@ def get_all_markers(self, cursor, valid: bool, waterBodyName):
marker_data
=
json
.
dumps
(
data
,
indent
=
4
)
except
Exception
as
e
:
print
(
f
"
An e
rror
occurred while
querying
the
database:
{
e
}
"
)
print
(
f
"
E
rror
in
querying database:
{
e
}
"
)
resp_code
=
500
marker_data
=
'
[]
'
...
...
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