Skip to content

Commit

Permalink
facet methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Feb 12, 2019
1 parent 2f3ace4 commit 5373313
Showing 1 changed file with 19 additions and 55 deletions.
74 changes: 19 additions & 55 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
Expand All @@ -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(",")
Expand All @@ -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"],
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 5373313

Please sign in to comment.