Module: Cdss::Structures
Overview
Provides methods for accessing water structures data from the CDSS API.
This module includes functionality for retrieving water structures, diversion records, stage/volume data, and water classes.
Instance Method Summary collapse
-
#get_diversion_records_ts(wdid:, wc_identifier: nil, start_date: nil, end_date: nil, timescale: "day") ⇒ Array<Models::DiversionRecord>
Fetches diversion records time series data.
-
#get_stage_volume_ts(wdid:, start_date: nil, end_date: nil) ⇒ Array<Models::DiversionRecord>
Fetches stage/volume record data.
-
#get_structures(aoi: nil, radius: nil, county: nil, division: nil, gnis_id: nil, water_district: nil, wdid: nil) ⇒ Array<Models::Structure>
Fetches a list of administrative structures based on various filtering criteria.
-
#get_water_classes(**params) ⇒ Array<Models::WaterClass>
Fetches water classes for structures.
Methods included from Utils
#batch_dates, #build_query, #fetch_paginated_data, #format_date, #format_query_param, #parse_timestamp, #safe_float, #safe_integer
Instance Method Details
#get_diversion_records_ts(wdid:, wc_identifier: nil, start_date: nil, end_date: nil, timescale: "day") ⇒ Array<Models::DiversionRecord>
Fetches diversion records time series data.
58 59 60 61 62 63 |
# File 'lib/cdss/structures.rb', line 58 def get_diversion_records_ts(wdid:, wc_identifier: nil, start_date: nil, end_date: nil, timescale: "day") validate_timescale!(timescale) method_name = "fetch_diversion_records_#{timescale}" send(method_name, wdid: wdid, wc_identifier: wc_identifier, start_date: start_date, end_date: end_date) end |
#get_stage_volume_ts(wdid:, start_date: nil, end_date: nil) ⇒ Array<Models::DiversionRecord>
Fetches stage/volume record data.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cdss/structures.rb', line 71 def get_stage_volume_ts(wdid:, start_date: nil, end_date: nil) query = build_query({ wdid: wdid, "min-dataMeasDate": format_date(start_date), "max-dataMeasDate": format_date(end_date) }) fetch_paginated_data( endpoint: "/structures/divrec/stagevolume/", query: query ) do |data| Parser.parse_diversion_records(data, type: :stage_volume) end end |
#get_structures(aoi: nil, radius: nil, county: nil, division: nil, gnis_id: nil, water_district: nil, wdid: nil) ⇒ Array<Models::Structure>
Fetches a list of administrative structures based on various filtering criteria.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cdss/structures.rb', line 22 def get_structures(aoi: nil, radius: nil, county: nil, division: nil, gnis_id: nil, water_district: nil, wdid: nil) query = build_query({ county: county, division: division, gnisId: gnis_id, waterDistrict: water_district, wdid: Array(wdid).join("%2C+"), units: "miles" }) if aoi coords = process_aoi(aoi) query.merge!({ latitude: coords[:lat], longitude: coords[:lng], radius: radius || 20 }) end fetch_paginated_data( endpoint: "/structures/", query: query ) do |data| Parser.parse_structures(data) end end |
#get_water_classes(**params) ⇒ Array<Models::WaterClass>
Fetches water classes for structures.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cdss/structures.rb', line 103 def get_water_classes(**params) query = build_query({ wdid: Array(params[:wdid]).join("%2C+"), county: params[:county], division: params[:division], waterDistrict: params[:water_district], wcIdentifier: format_wc_identifier(params[:wc_identifier]), timestep: params[:timestep], "min-porStart": format_date(params[:start_date]), "min-porEnd": format_date(params[:end_date]), divrectype: params[:divrectype], ciuCode: params[:ciu_code], gnisId: params[:gnis_id] }) if params[:aoi] coords = process_aoi(params[:aoi]) query.merge!({ latitude: coords[:lat], longitude: coords[:lng], radius: params[:radius] || 20, units: "miles" }) end fetch_paginated_data( endpoint: "/structures/divrec/waterclasses/", query: query ) do |data| Parser.parse_water_classes(data) end end |