From 038e2e509c11ca4a1a8f9f0d3686047dd5cbfa70 Mon Sep 17 00:00:00 2001 From: Kristian Garza Date: Fri, 29 Nov 2019 11:42:47 +0100 Subject: [PATCH] update query object changes --- app/controllers/events_controller.rb | 10 +++--- app/graphql/types/metric_interface.rb | 44 +++++++++++---------------- app/models/concerns/indexable.rb | 3 +- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index e683f278e..db96d6672 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -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]) : [] diff --git a/app/graphql/types/metric_interface.rb b/app/graphql/types/metric_interface.rb index 6cb8a63f9..af3ea3a57 100644 --- a/app/graphql/types/metric_interface.rb +++ b/app/graphql/types/metric_interface.rb @@ -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]} @@ -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 diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 15a49e804..14e7e134d 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -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