From 88d52ebd9e217170fa07355ba856ffc66427d063 Mon Sep 17 00:00:00 2001 From: Ben Bradford Date: Thu, 27 Jul 2023 14:29:26 -0500 Subject: [PATCH] improve awon download filenames --- app/controllers/awon_controller.rb | 8 ++++++-- app/models/t401.rb | 4 ++++ app/models/t403.rb | 4 ++++ app/models/t406.rb | 4 ++++ app/models/t411.rb | 4 ++++ app/models/t412.rb | 4 ++++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/controllers/awon_controller.rb b/app/controllers/awon_controller.rb index bae130c9..7ca66303 100644 --- a/app/controllers/awon_controller.rb +++ b/app/controllers/awon_controller.rb @@ -79,10 +79,14 @@ def download_data render plain: text end format.csv do + filename = begin + "#{stn.name} #{@db_class.description} - #{start_date} to #{end_date}.csv" + rescue + "awon data.csv" + end text = @db_class.csv_header(use_abbrevs, @ahrs) text += @results.collect { |rec| rec.to_csv(@ahrs) }.join("") - # render plain: text - send_data text, filename: "awon_data.csv" + send_data(text, filename:) end end end diff --git a/app/models/t401.rb b/app/models/t401.rb index d61639a7..916acb51 100644 --- a/app/models/t401.rb +++ b/app/models/t401.rb @@ -3,6 +3,10 @@ class T401 < ApplicationRecord belongs_to :awon_station + def self.description + "Five-Minute Precip and Wind" + end + def self.attr_human_readables [ ["date", "Date"], diff --git a/app/models/t403.rb b/app/models/t403.rb index 67575e7a..6119c635 100644 --- a/app/models/t403.rb +++ b/app/models/t403.rb @@ -3,6 +3,10 @@ class T403 < ApplicationRecord belongs_to :awon_station + def self.description + "Pre-2000 Half-Hourly Weather and Soil" + end + def self.attr_human_readables [ ["date", "Date"], diff --git a/app/models/t406.rb b/app/models/t406.rb index 24222aa4..06660e4c 100644 --- a/app/models/t406.rb +++ b/app/models/t406.rb @@ -4,6 +4,10 @@ class T406 < ApplicationRecord belongs_to :awon_station + def self.description + "Hourly Weather and Soil" + end + def self.attr_human_readables [ ["date", "Date"], diff --git a/app/models/t411.rb b/app/models/t411.rb index 5c151b2b..9efecf4d 100644 --- a/app/models/t411.rb +++ b/app/models/t411.rb @@ -4,6 +4,10 @@ class T411 < ApplicationRecord belongs_to :awon_station + def self.description + "Daily Weather" + end + def self.attr_human_readables [ ["date", "Date"], diff --git a/app/models/t412.rb b/app/models/t412.rb index bfed8aef..bdc7b62d 100644 --- a/app/models/t412.rb +++ b/app/models/t412.rb @@ -4,6 +4,10 @@ class T412 < ApplicationRecord belongs_to :awon_station + def self.description + "Daily Soil" + end + def self.attr_human_readables [ ["date", "Date"],