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
1492965c
Verified
Commit
1492965c
authored
3 years ago
by
Owen Graham
Browse files
Options
Downloads
Patches
Plain Diff
Read `amrdcrecords.json` only once per invocation
parent
30479fa1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
visualizer/plotting.py
+2
-3
2 additions, 3 deletions
visualizer/plotting.py
visualizer/records.py
+4
-4
4 additions, 4 deletions
visualizer/records.py
with
6 additions
and
7 deletions
visualizer/plotting.py
+
2
−
3
View file @
1492965c
...
...
@@ -10,7 +10,7 @@ import numpy as np
from
.data
import
read_data
from
.parameters
import
get_param
,
meas_type
,
year_type
from
.records
import
get_station
,
read_stations
from
.records
import
get_station
plt
.
style
.
use
(
'
ggplot
'
)
plt
.
rcParams
[
'
axes.xmargin
'
]
=
0
...
...
@@ -129,11 +129,10 @@ class Overlay(Plotter):
def
plot
(
cls
):
num_datasets
=
2
datasets
=
tuple
(
SimpleNamespace
()
for
_
in
range
(
num_datasets
))
stations
=
read_stations
()
for
n
,
dset
in
enumerate
(
datasets
,
start
=
1
):
dset
.
station_id
=
get_param
(
f
'
station
{
n
}
'
)
dset
.
year
=
get_param
(
f
'
year
{
n
}
'
,
to
=
year_type
)
dset
.
station
=
get_station
(
dset
.
station_id
,
stations
=
stations
)
dset
.
station
=
get_station
(
dset
.
station_id
)
dset
.
name
=
dset
.
station
[
'
name
'
]
meas
=
get_param
(
'
measurement
'
,
to
=
meas_type
)
...
...
This diff is collapsed.
Click to expand it.
visualizer/records.py
+
4
−
4
View file @
1492965c
"""
Read and parse records of station data.
"""
from
functools
import
lru_cache
import
json
from
flask
import
abort
@lru_cache
(
maxsize
=
None
)
def
read_stations
():
"""
Read amrdcrecords.json.
"""
with
open
(
'
amrdcrecords.json
'
)
as
f
:
return
json
.
load
(
f
)
def
get_station
(
station_id
,
stations
=
None
):
def
get_station
(
station_id
):
"""
Get a station record by ID.
Calls `abort(404)` if none is found.
"""
if
stations
is
None
:
stations
=
read_stations
()
for
station
in
stations
:
for
station
in
read_stations
():
if
station
[
'
id
'
]
==
station_id
:
return
station
abort
(
404
)
...
...
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