Skip to content

Commit

Permalink
update query object changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Nov 29, 2019
1 parent 01e48b1 commit 038e2e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
10 changes: 4 additions & 6 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,15 @@ def index
registrants = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_registrants(response.response.aggregations.registrants.buckets) : nil
pairings = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_pairings(response.response.aggregations.pairings.buckets) : nil
dois = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_dois(response.response.aggregations.dois.buckets) : nil
# dois_usage = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_dois(response.response.aggregations.dois_usage.dois.buckets) : nil
dois_usage = params[:doi].present? ? EventsQuery.new.usage(params[:doi]) : []
dois_citations = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_citations_by_year_v1(response.response.aggregations.dois_citations) : nil
citations_histogram = total.positive? && params[:doi].present? && aggregations.include?("citations_aggregations") ? facet_citations_by_year(response.response.aggregations.citations_histogram) : nil
citations = params[:doi].present? ? EventsQuery.new.citations(params[:doi]) : []
citations_histogram = params[:doi].present? ? EventsQuery.new.citations_histogram(params[:doi]) : []
references = total.positive? && params[:doi].present? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.references.dois.buckets) : nil
relations = total.positive? && params[:doi].present? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.relations.dois.buckets) : nil
views_histogram = total.positive? && aggregations.include?("metrics_aggregations") ? facet_counts_by_year_month(response.response.aggregations.views_histogram) : nil
downloads_histogram = total.positive? && aggregations.include?("metrics_aggregations") ? facet_counts_by_year_month(response.response.aggregations.downloads_histogram) : nil
# views = total.positive? && aggregations.include?("metrics_aggregations") ? facet_by_source(response.response.aggregations.views.dois.buckets) : nil
# downloads = total.positive? && aggregations.include?("metrics_aggregations") ? facet_by_source(response.response.aggregations.downloads.dois.buckets) : nil

views_histogram = params[:doi].present? ? EventsQuery.new.views_histogram(params[:doi]) : []
downloads_histogram = params[:doi].present? ? EventsQuery.new.downloads_histogram(params[:doi]) : []

views = params[:doi].present? ? EventsQuery.new.views(params[:doi]) : []
downloads = params[:doi].present? ? EventsQuery.new.downloads(params[:doi]) : []
Expand Down
44 changes: 18 additions & 26 deletions app/graphql/types/metric_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def citation_count
EventsQuery.new.doi_citations(doi_from_url(object.identifier))
end

def reference_count
meta = references_aggs
meta.first.fetch("total", {}).fetch("value", nil) if meta.any?
end
# def reference_count
# meta = references_aggs
# meta.first.fetch("total", {}).fetch("value", nil) if meta.any?
# end

def relation_count
meta = relations_aggs
meta.first.fetch("total", {}).fetch("value", nil) if meta.any?
end
# def relation_count
# meta = relations_aggs
# meta.first.fetch("total", {}).fetch("value", nil) if meta.any?
# end

# def references_list
# references_aggs.map { |item| item[:key]}
Expand All @@ -56,27 +56,19 @@ def relation_count
# # end
# end

def citations_aggs
aggregation_results(id: object.identifier, aggregations: "citations_aggregations" ).citations.dois.buckets
end
# def citations_aggs
# aggregation_results(id: object.identifier, aggregations: "citations_aggregations" ).citations.dois.buckets
# end

def references_aggs
aggregation_results(id: object.identifier, aggregations: "citations_aggregations").references.dois.buckets
end
# def references_aggs
# aggregation_results(id: object.identifier, aggregations: "citations_aggregations").references.dois.buckets
# end

def relations_aggs
aggregation_results(id: object.identifier, aggregations: "citations_aggregations").relations.dois.buckets
end
# def relations_aggs
# aggregation_results(id: object.identifier, aggregations: "citations_aggregations").relations.dois.buckets
# end

def citation_histogram
hash = aggregation_results(id: object.identifier, aggregations: "citations_aggregations").citations_histogram

hash.dig('years', 'buckets').map do |h|
year = h['key']
{
'id' => year,
'sum' => h.dig('total_by_year', 'value')
}
end
EventsQuery.new.citations_histogram(doi_from_url(object.identifier))
end
end
3 changes: 1 addition & 2 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def get_aggregations_hash(options={})
aggs = {}
aggregations.split(",").each do |agg|
agg = :query_aggregations if agg.blank? || !respond_to?(agg)
doi = options[:doi].present? ? options[:doi].downcase.split(",").first : nil
aggs.merge! send(agg,doi)
aggs.merge! send(agg)
end
aggs
end
Expand Down

0 comments on commit 038e2e5

Please sign in to comment.