diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index 5910e5c80..2a0876672 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -106,7 +106,7 @@ def facet_by_provider(arr) end end - def facet_by_providers_totals(arr) + def providers_totals(arr) # generate hash with id and name for each provider in facet ids = arr.map { |hsh| hsh["key"] }.join(",") @@ -128,7 +128,24 @@ def facet_by_providers_totals(arr) end end - def facet_by_clients_totals(arr) + def prefixes_totals(arr) + # generate hash with id and name for each provider in facet + + arr.map do |hsh| + { "id" => hsh["key"], + "title" => hsh["key"], + "count" => hsh["doc_count"], + "temporal" => { + "this_month" => facet_anual(hsh.this_month.buckets), + "this_year" => facet_anual(hsh.this_year.buckets), + "last_year" => facet_anual(hsh.last_year.buckets)}, + "states" => facet_by_key(hsh.states.buckets) + } + end + end + + + def clients_totals(arr) # generate hash with id and name for each provider in facet ids = arr.map { |hsh| hsh["key"] }.join(",") @@ -138,7 +155,6 @@ def facet_by_clients_totals(arr) end arr.map do |hsh| - puts hsh { "id" => hsh["key"], "title" => clients[hsh["key"]], "count" => hsh["doc_count"], @@ -181,58 +197,6 @@ def facet_by_client(arr) end end - def prefixes_totals params={} - page = { size: 0, number: 1 } - - prefixes = params[:client_id] ? Client.where(symbol: params[:client_id]).first.prefix_ids : Prefix.query("") - - ttl = prefixes.map do |prefix| - prefix = prefix.respond_to?("downcase") ? prefix : prefix.prefix - response = Doi.query("", client_id: params[:client_id], prefix: prefix, state: params[:state] || "",page: page) - total = response.results.total - states = total > 0 ? facet_by_key(response.response.aggregations.states.buckets) : nil - temporal ={} - temporal[:this_month] = total > 0 ? facet_by_date(response.response.aggregations.this_month.buckets) : nil - temporal[:this_year] = total > 0 ? facet_anual(response.response.aggregations.this_year.buckets) : nil - temporal[:last_year] = total > 0 ? facet_anual(response.response.aggregations.last_year.buckets) : nil - id = prefix - {id: id, title: id, count: total, states: states, temporal: temporal} - end - ttl - end - - def totals_formatter item, response, page - total = response.results.total - states = total > 0 ? facet_by_key(response.response.aggregations.states.buckets) : nil - temporal ={} - temporal[:this_month] = total > 0 ? facet_by_date(response.response.aggregations.this_month.buckets) : nil - temporal[:this_year] = total > 0 ? facet_anual(response.response.aggregations.this_year.buckets) : nil - temporal[:last_year] = total > 0 ? facet_anual(response.response.aggregations.last_year.buckets) : nil - id = item.symbol - {id: id, title: item.name, count: total, states: states, temporal: temporal} - end - - def providers_totals params={} - page = { size: 0, number: 1} - page_prov = { size: 500, number: 1} - - ttl = Provider.query(nil, page: page_prov).map do |item| - response = Doi.query(nil, provider_id: item.symbol.downcase, state: params[:state] || "", page: page) - totals_formatter item, response, page - end - ttl - end - - def clients_totals params={} - page = { size: 0, number: 1 } - page_prov = { size: 2000, number: 1 } - - ttl = Client.query(nil, page: page_prov, provider_id: params[:provider_id]).map do |item| - response = Doi.query(nil, provider_id: params[:provider_id], client_id: item.symbol.downcase, state: params[:state] || "",page: page) - totals_formatter item, response, page - end - ttl - end # def get_all_providers_aggs # page = { size: 25, number: 1}