Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
visualizer-embed
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
Container 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
Owen Graham
visualizer-embed
Commits
2130f4fb
Verified
Commit
2130f4fb
authored
3 years ago
by
Owen Graham
Browse files
Options
Downloads
Patches
Plain Diff
Document more Python functions
parent
99d29731
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
visualizer.py
+11
-5
11 additions, 5 deletions
visualizer.py
with
11 additions
and
5 deletions
visualizer.py
+
11
−
5
View file @
2130f4fb
...
...
@@ -114,7 +114,7 @@ def read_stations():
@app.route
(
'
/record/years
'
)
def
record_years
():
"""
Return a
JSON
list of years for the selected station.
"""
"""
Return a list of years for the selected station.
"""
station
=
get_station
(
get_param
(
'
station
'
))
years
=
[
i
[
'
year
'
]
for
i
in
station
[
'
records
'
]]
return
jsonify
(
years
)
...
...
@@ -122,6 +122,7 @@ def record_years():
@app.route
(
'
/plot/boxplot
'
)
def
plot_boxplot
():
"""
Boxplot one station/measurement @ multiple years.
"""
station_id
=
get_param
(
'
station
'
)
year1
=
get_param
(
'
year1
'
,
to
=
year_type
)
year2
=
get_param
(
'
year2
'
,
to
=
year_type
)
...
...
@@ -171,6 +172,7 @@ def plot_boxplot():
@app.route
(
'
/plot
'
)
def
plot
():
"""
Plot one station/year/measurement.
"""
station_id
=
get_param
(
'
station
'
)
year
=
get_param
(
'
year
'
,
to
=
year_type
)
meas
=
get_param
(
'
measurement
'
,
to
=
meas_type
)
...
...
@@ -203,6 +205,7 @@ def plot():
@app.route
(
'
/plot/overlay
'
)
def
plot_overlay
():
"""
Plot two station/years @ one measurement.
"""
num_datasets
=
2
datasets
=
tuple
(
SimpleNamespace
()
for
_
in
range
(
num_datasets
))
stations
=
read_stations
()
...
...
@@ -266,7 +269,7 @@ def savefig_response(fig):
def
get_param
(
key
,
to
=
str
):
"""
Get a
value
from the query string.
"""
Get a
parameter
from the query string.
Calls `abort(400)` if the value is the wrong type or missing.
"""
...
...
@@ -299,7 +302,7 @@ def year_type(s):
def
get_link
(
station
,
year
):
"""
Get the link to a dataset.
Calls `abort(404)` if
ther
e is
no link/record for the given year
.
Calls `abort(404)` if
non
e is
found
.
"""
for
record
in
station
[
'
records
'
]:
if
record
[
'
year
'
]
==
year
:
...
...
@@ -309,15 +312,16 @@ def get_link(station, year):
@app.route
(
'
/record/link
'
)
def
record_link
():
"""
Return the source link for the selected dataset.
"""
station
=
get_station
(
get_param
(
'
station
'
))
year
=
get_param
(
'
year
'
,
to
=
year_type
)
return
jsonify
(
get_link
(
station
,
year
))
def
get_station
(
station_id
,
stations
=
None
):
"""
Get
the
station record
corresponding to the station
ID.
"""
Get
a
station record
by
ID.
Calls `abort(404)` if
ther
e is
none
.
"""
Calls `abort(404)` if
non
e is
found
.
"""
if
stations
is
None
:
stations
=
read_stations
()
for
station
in
stations
:
...
...
@@ -327,6 +331,7 @@ def get_station(station_id, stations=None):
def
get_resources
(
link
):
"""
Fetch the download links for a dataset.
"""
doc
=
jsonld
.
flatten
(
link
+
'
.jsonld
'
)
for
i
in
doc
:
types
=
i
.
get
(
'
@type
'
,
[])
...
...
@@ -345,6 +350,7 @@ def get_resources(link):
def
read_data
(
station
,
year
):
"""
Fetch data and convert it to a NumPy array.
"""
data
=
[]
resource_list
=
get_resources
(
get_link
(
station
,
year
))
for
url
in
resource_list
:
...
...
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