Module: Usgs::Statistics
- Included in:
- Client
- Defined in:
- lib/usgs/statistics.rb
Instance Method Summary collapse
-
#get_stats(sites:, parameter_cd: nil, report_type: :daily, stat_year_type: nil) ⇒ Array<Usgs::Models::Statistic>
Fetch statistics from USGS NWIS.
Instance Method Details
#get_stats(sites:, parameter_cd: nil, report_type: :daily, stat_year_type: nil) ⇒ Array<Usgs::Models::Statistic>
Fetch statistics from USGS NWIS
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/usgs/statistics.rb', line 19 def get_stats(sites:, parameter_cd: nil, report_type: :daily, stat_year_type: nil) site_list = Array(sites).join(",") param_list = resolve_parameter_codes(parameter_cd) type_str = report_type.to_s raise ArgumentError, "report_type must be :daily, :monthly, or :annual" unless %w[daily monthly annual].include?(type_str) raise ArgumentError, "stat_year_type is only valid when report_type: :annual" if type_str != "annual" && stat_year_type query = { format: "rdb,1.0", sites: site_list, parameterCd: param_list, statReportType: type_str, statTypeCd: "all" } query[:statYearType] = stat_year_type if stat_year_type raw = api_get("/stat/", query) Parser.parse_statistics(raw.body).map { |row| Models::Statistic.new(row) } end |