Skip to content

Commit

Permalink
get metrics only if results
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Nov 29, 2019
1 parent 038e2e5 commit c6d1956
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
30 changes: 22 additions & 8 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class EventsController < ApplicationController
include Facetable

include BatchLoaderHelper
require 'benchmark'



prepend_before_action :authenticate_user!, except: [:index, :show]
Expand Down Expand Up @@ -120,21 +122,33 @@ 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 = 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 = params[:doi].present? ? EventsQuery.new.citations(params[:doi]) : []
dois_usage = total.positive? && 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 = total.positive? && 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 = params[:doi].present? ? EventsQuery.new.views_histogram(params[:doi]) : []
downloads_histogram = params[:doi].present? ? EventsQuery.new.downloads_histogram(params[:doi]) : []
views_histogram = total.positive? && params[:doi].present? ? EventsQuery.new.views_histogram(params[:doi]) : []
downloads_histogram = total.positive? && 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]) : []
views = total.positive? && params[:doi].present? ? EventsQuery.new.views(params[:doi]) : []
downloads = total.positive? && params[:doi].present? ? EventsQuery.new.downloads(params[:doi]) : []
unique_obj_count = total.positive? && aggregations.include?("advanced_aggregations") ? response.response.aggregations.unique_obj_count.value : nil
unique_subj_count = total.positive? && aggregations.include?("advanced_aggregations") ? response.response.aggregations.unique_subj_count.value : nil



bmt = Benchmark.ms {
total.positive? && params[:doi].present? ? EventsQuery.new.citations(params[:doi]) : []
}
if bmt > 10000
logger.warn "[Benchmark Warning] citations " + bmt.to_s + " ms"
else
logger.info "[Benchmark] citations " + bmt.to_s + " ms"
end


results = response.results

options = {}
Expand All @@ -150,7 +164,7 @@ def index
registrants: registrants,
"doisRelationTypes": dois,
"doisUsageTypes": dois_usage,
"doisCitations": dois_citations,
# "doisCitations": dois_citations,
"citationsHistogram": citations_histogram,
"uniqueCitations": citations,
"references": references,
Expand Down
10 changes: 1 addition & 9 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,7 @@ def self.query_aggregations
pairings: { terms: { field: "registrant_id", size: 50, min_doc_count: 1 }, aggs: { recipient: { terms: { field: "registrant_id", size: 50, min_doc_count: 1 }, aggs: { "total" => { sum: { field: "total" } } } } } },
citation_types: { terms: { field: "citation_type", size: 50, min_doc_count: 1 }, aggs: { year_months: { date_histogram: { field: "occurred_at", interval: "month", min_doc_count: 1 }, aggs: { "total_by_year_month" => { sum: { field: "total" } } } } } },
relation_types: { terms: { field: "relation_type_id", size: 50, min_doc_count: 1 }, aggs: { year_months: { date_histogram: { field: "occurred_at", interval: "month", min_doc_count: 1 }, aggs: { "total_by_year_month" => { sum: { field: "total" } } } }, "sum_distribution" => sum_distribution } },
dois: { terms: { field: "obj_id", size: 50, min_doc_count: 1 }, aggs: { relation_types: { terms: { field: "relation_type_id", size: 50, min_doc_count: 1 }, aggs: { "total_by_type" => { sum: { field: "total" } } } } } },
dois_citations: {
filter: {
script: {
script: "#{INCLUDED_RELATION_TYPES}.contains(doc['relation_type_id'].value)"
}
},
aggs: { years: { date_histogram: { field: "occurred_at", interval: "year", min_doc_count: 1 }, aggs: { "total_by_year" => { sum: { field: "total" } } } }, "sum_distribution" => sum_year_distribution }
}
dois: { terms: { field: "obj_id", size: 50, min_doc_count: 1 }, aggs: { relation_types: { terms: { field: "relation_type_id", size: 50, min_doc_count: 1 }, aggs: { "total_by_type" => { sum: { field: "total" } } } } } }
}
end

Expand Down

0 comments on commit c6d1956

Please sign in to comment.