Skip to content
Snippets Groups Projects
Verified Commit 011ce859 authored by Owen Graham's avatar Owen Graham
Browse files

Make "measurement" the first parameter everywhere

parent 6e8b43d3
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ class Selector: ...@@ -14,7 +14,7 @@ class Selector:
"""Information about a `<select>`.""" """Information about a `<select>`."""
def __init__(self, **kwargs): def __init__(self, **kwargs):
if kwargs['type'] not in ('station', 'year', 'measurement'): if kwargs['type'] not in ('measurement', 'station', 'year'):
raise ValueError('unknown type') raise ValueError('unknown type')
self.type = kwargs['type'] self.type = kwargs['type']
self.name = kwargs['name'] self.name = kwargs['name']
...@@ -23,10 +23,10 @@ class Selector: ...@@ -23,10 +23,10 @@ class Selector:
self.onchange = kwargs.get('onchange') self.onchange = kwargs.get('onchange')
def get_param(self): def get_param(self):
if self.type == 'year': if self.type == 'measurement':
to = year_type
elif self.type == 'measurement':
to = meas_type to = meas_type
elif self.type == 'year':
to = year_type
else: else:
to = str to = str
return get_param(self.name, to=to, call_abort=False) return get_param(self.name, to=to, call_abort=False)
...@@ -43,18 +43,18 @@ class Plotter: ...@@ -43,18 +43,18 @@ class Plotter:
class TimeSeries(Plotter): class TimeSeries(Plotter):
"""Plot one station/year/measurement.""" """Plot one measurement/station/year."""
name = 'time-series' name = 'time-series'
nav_title = 'Time Series' nav_title = 'Time Series'
page_title = 'Plot Data' page_title = 'Plot Data'
onsubmit_fn = 'timeSeriesVisualize' onsubmit_fn = 'timeSeriesVisualize'
selectors = ( selectors = (
Selector(type='measurement', name='measurement', id='measurement',
label='Measurement'),
Selector(type='station', name='station', id='station', label='Station', Selector(type='station', name='station', id='station', label='Station',
onchange='getYears()'), onchange='getYears()'),
Selector(type='year', name='year', id='year', label='Year'), Selector(type='year', name='year', id='year', label='Year'),
Selector(type='measurement', name='measurement', id='measurement',
label='Measurement'),
) )
source_param_maps = ( source_param_maps = (
{'station': 'station', 'year': 'year'}, {'station': 'station', 'year': 'year'},
...@@ -70,9 +70,9 @@ class TimeSeries(Plotter): ...@@ -70,9 +70,9 @@ class TimeSeries(Plotter):
plt.rcParams['axes.xmargin'] = 0 plt.rcParams['axes.xmargin'] = 0
matplotlib.use('Agg') matplotlib.use('Agg')
meas = get_param('measurement', to=meas_type)
station_id = get_param('station') station_id = get_param('station')
year = get_param('year', to=year_type) year = get_param('year', to=year_type)
meas = get_param('measurement', to=meas_type)
station = get_station(station_id) station = get_station(station_id)
data = read_data(station, year) data = read_data(station, year)
fig, axes = plt.subplots() fig, axes = plt.subplots()
...@@ -96,26 +96,26 @@ class TimeSeries(Plotter): ...@@ -96,26 +96,26 @@ class TimeSeries(Plotter):
plt.suptitle(f'{meas.title.capitalize()} measurements, ' plt.suptitle(f'{meas.title.capitalize()} measurements, '
f'{name} Station, {data[0, 0].year}') f'{name} Station, {data[0, 0].year}')
return savefig_response(fig, filename=( return savefig_response(fig, filename=(
f'{cls.name}.{station_id}.{year}.{meas.slug}.png' f'{cls.name}.{meas.slug}.{station_id}.{year}.png'
)) ))
class Overlay(Plotter): class Overlay(Plotter):
"""Plot two station/years @ one measurement.""" """Plot one measurement @ two station/years."""
name = 'overlay' name = 'overlay'
nav_title = 'Overlay' nav_title = 'Overlay'
page_title = 'Overlay Stations' page_title = 'Overlay Stations'
onsubmit_fn = 'overlayVisualize' onsubmit_fn = 'overlayVisualize'
selectors = ( selectors = (
Selector(type='measurement', name='measurement', id='measurement',
label='Measurement'),
Selector(type='station', name='station1', id='station-1', Selector(type='station', name='station1', id='station-1',
label='Station #1', onchange='getYears(1)'), label='Station #1', onchange='getYears(1)'),
Selector(type='year', name='year1', id='year-1', label='Year #1'), Selector(type='year', name='year1', id='year-1', label='Year #1'),
Selector(type='station', name='station2', id='station-2', Selector(type='station', name='station2', id='station-2',
label='Station #2', onchange='getYears(2)'), label='Station #2', onchange='getYears(2)'),
Selector(type='year', name='year2', id='year-2', label='Year #2'), Selector(type='year', name='year2', id='year-2', label='Year #2'),
Selector(type='measurement', name='measurement', id='measurement',
label='Measurement'),
) )
source_param_maps = ( source_param_maps = (
{'station': 'station1', 'year': 'year1'}, {'station': 'station1', 'year': 'year1'},
...@@ -132,6 +132,7 @@ class Overlay(Plotter): ...@@ -132,6 +132,7 @@ class Overlay(Plotter):
plt.rcParams['axes.xmargin'] = 0 plt.rcParams['axes.xmargin'] = 0
matplotlib.use('Agg') matplotlib.use('Agg')
meas = get_param('measurement', to=meas_type)
num_datasets = 2 num_datasets = 2
datasets = tuple(SimpleNamespace() for _ in range(num_datasets)) datasets = tuple(SimpleNamespace() for _ in range(num_datasets))
for n, dset in enumerate(datasets, start=1): for n, dset in enumerate(datasets, start=1):
...@@ -139,7 +140,6 @@ class Overlay(Plotter): ...@@ -139,7 +140,6 @@ class Overlay(Plotter):
dset.year = get_param(f'year{n}', to=year_type) dset.year = get_param(f'year{n}', to=year_type)
dset.station = get_station(dset.station_id) dset.station = get_station(dset.station_id)
dset.name = dset.station['name'] dset.name = dset.station['name']
meas = get_param('measurement', to=meas_type)
def ignore_feb_29(rows): def ignore_feb_29(rows):
return [row for row in rows return [row for row in rows
...@@ -189,24 +189,24 @@ class Overlay(Plotter): ...@@ -189,24 +189,24 @@ class Overlay(Plotter):
filename_dsets = '.'.join(f'{dset.station_id}.{dset.year}' filename_dsets = '.'.join(f'{dset.station_id}.{dset.year}'
for dset in datasets) for dset in datasets)
return savefig_response(fig, filename=( return savefig_response(fig, filename=(
f'{cls.name}.{filename_dsets}.{meas.slug}.png' f'{cls.name}.{meas.slug}.{filename_dsets}.png'
)) ))
class Boxplot(Plotter): class Boxplot(Plotter):
"""Boxplot one station/measurement @ multiple years.""" """Boxplot one measurement/station @ multiple years."""
name = 'boxplot' name = 'boxplot'
nav_title = 'Boxplot' nav_title = 'Boxplot'
page_title = 'Boxplot Years' page_title = 'Boxplot Years'
onsubmit_fn = 'boxplotVisualize' onsubmit_fn = 'boxplotVisualize'
selectors = ( selectors = (
Selector(type='measurement', name='measurement', id='measurement',
label='Measurement'),
Selector(type='station', name='station', id='station', label='Station', Selector(type='station', name='station', id='station', label='Station',
onchange='boxplotGetYears()'), onchange='boxplotGetYears()'),
Selector(type='year', name='year1', id='year-1', label='Year #1'), Selector(type='year', name='year1', id='year-1', label='Year #1'),
Selector(type='year', name='year2', id='year-2', label='Year #2'), Selector(type='year', name='year2', id='year-2', label='Year #2'),
Selector(type='measurement', name='measurement', id='measurement',
label='Measurement'),
) )
source_param_maps = ( source_param_maps = (
{'station': 'station', 'year': 'year1'}, {'station': 'station', 'year': 'year1'},
...@@ -221,10 +221,10 @@ class Boxplot(Plotter): ...@@ -221,10 +221,10 @@ class Boxplot(Plotter):
plt.rcParams['axes.xmargin'] = 0 plt.rcParams['axes.xmargin'] = 0
matplotlib.use('Agg') matplotlib.use('Agg')
meas = get_param('measurement', to=meas_type)
station_id = get_param('station') station_id = get_param('station')
year1 = get_param('year1', to=year_type) year1 = get_param('year1', to=year_type)
year2 = get_param('year2', to=year_type) year2 = get_param('year2', to=year_type)
meas = get_param('measurement', to=meas_type)
station = get_station(station_id) station = get_station(station_id)
plot_data = [] plot_data = []
...@@ -267,7 +267,7 @@ class Boxplot(Plotter): ...@@ -267,7 +267,7 @@ class Boxplot(Plotter):
plt.suptitle(f'{meas.title.capitalize()} measurements, ' plt.suptitle(f'{meas.title.capitalize()} measurements, '
f'{name} Station, {start_year} - {end_year}.') f'{name} Station, {start_year} - {end_year}.')
return savefig_response(fig, filename=( return savefig_response(fig, filename=(
f'{cls.name}.{station_id}.{year1}.{year2}.{meas.slug}.png' f'{cls.name}.{meas.slug}.{station_id}.{year1}.{year2}.png'
)) ))
......
...@@ -3,6 +3,15 @@ ...@@ -3,6 +3,15 @@
{%- endmacro %} {%- endmacro %}
{% macro measurement_options(selected=none) %}
{% for meas in g.measurements.values() %}
<option value="{{ meas.slug }}"
{{- _selected(meas == selected) }}>
{{- meas.title | title -}}
</option>
{% endfor %}
{% endmacro %}
{% macro station_options(selected=none) %} {% macro station_options(selected=none) %}
{% for station in g.stations %} {% for station in g.stations %}
<option value="{{ station['id'] }}" <option value="{{ station['id'] }}"
...@@ -20,19 +29,10 @@ ...@@ -20,19 +29,10 @@
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}
{% macro measurement_options(selected=none) %}
{% for meas in g.measurements.values() %}
<option value="{{ meas.slug }}"
{{- _selected(meas == selected) }}>
{{- meas.title | title -}}
</option>
{% endfor %}
{% endmacro %}
{% set options = { {% set options = {
'measurement': measurement_options,
'station': station_options, 'station': station_options,
'year': year_options, 'year': year_options,
'measurement': measurement_options,
} %} } %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment