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

Give plots even better filenames using headers

parent 0ee56251
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,10 @@ def plot_time_series(): ...@@ -61,7 +61,10 @@ def plot_time_series():
name = station['name'] name = station['name']
plt.suptitle(f'{meas.title} measurements, {name} Station, ' plt.suptitle(f'{meas.title} measurements, {name} Station, '
f'{data[0][0].year}') f'{data[0][0].year}')
return savefig_response(fig) return savefig_response(
fig,
filename=f'time-series.{station_id}.{year}.{meas.url_name}.png',
)
@add_plotter('overlay', 'Overlay') @add_plotter('overlay', 'Overlay')
...@@ -119,7 +122,12 @@ def plot_overlay(): ...@@ -119,7 +122,12 @@ def plot_overlay():
title_dsets = ' / '.join(f'{dset.name} Station, {dset.data[0][0].year}' title_dsets = ' / '.join(f'{dset.name} Station, {dset.data[0][0].year}'
for dset in datasets) for dset in datasets)
plt.suptitle(f'{meas.title} measurements, {title_dsets}') plt.suptitle(f'{meas.title} measurements, {title_dsets}')
return savefig_response(fig) filename_dsets = '.'.join(f'{dset.station_id}.{dset.year}'
for dset in datasets)
return savefig_response(
fig,
filename=f'overlay.{filename_dsets}.{meas.url_name}.png',
)
@add_plotter('boxplot', 'Boxplot') @add_plotter('boxplot', 'Boxplot')
...@@ -169,11 +177,17 @@ def plot_boxplot(): ...@@ -169,11 +177,17 @@ def plot_boxplot():
name = station['name'] name = station['name']
plt.suptitle(f'{meas.title} measurements, {name} Station, ' plt.suptitle(f'{meas.title} measurements, {name} Station, '
f'{start_year} - {end_year}.') f'{start_year} - {end_year}.')
return savefig_response(fig) return savefig_response(
fig,
filename=(f'boxplot.{station_id}.{year1}.{year2}.{meas.url_name}.png'),
)
def savefig_response(fig): def savefig_response(fig, filename=None):
"""Make an image response with `fig.savefig()`.""" """Make an image response with `fig.savefig()`."""
buf = BytesIO() buf = BytesIO()
fig.savefig(buf, format='png') fig.savefig(buf, format='png')
return Response(buf.getvalue(), mimetype='image/png') res = Response(buf.getvalue(), mimetype='image/png')
if filename is not None:
res.headers['Content-Disposition'] = f'inline; filename="{filename}"'
return res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment