Skip to content

Commit

Permalink
Merge pull request #417 from datacite/citations-through-events
Browse files Browse the repository at this point in the history
index events with dois. #390
  • Loading branch information
Martin Fenner authored Feb 15, 2020
2 parents 0ec8f0d + 9b0cd14 commit 280c2c6
Show file tree
Hide file tree
Showing 27 changed files with 220 additions and 1,317 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: ruby
rvm:
- 2.6.5
sudo: required
dist: xenial

services:
- mysql
Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ GEM
audited (4.9.0)
activerecord (>= 4.2, < 6.1)
aws-eventstream (1.0.3)
aws-partitions (1.271.0)
aws-sdk-core (3.89.1)
aws-partitions (1.273.0)
aws-sdk-core (3.90.1)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.28.0)
aws-sdk-kms (1.29.0)
aws-sdk-core (~> 3, >= 3.71.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.60.2)
Expand Down Expand Up @@ -158,7 +158,7 @@ GEM
colorize (0.8.1)
commonmarker (0.17.13)
ruby-enum (~> 0.5)
concurrent-ruby (1.1.5)
concurrent-ruby (1.1.6)
countries (2.1.4)
i18n_data (~> 0.8.0)
money (~> 6.9)
Expand Down Expand Up @@ -274,7 +274,7 @@ GEM
multi_json (~> 1.14)
rack (~> 2.0)
rdf (~> 3.1)
json-ld-preloaded (3.1.0)
json-ld-preloaded (3.1.1)
json-ld (~> 3.1)
rdf (~> 3.1)
jsonapi-renderer (0.2.2)
Expand Down Expand Up @@ -349,7 +349,7 @@ GEM
namae (1.0.1)
netrc (0.11.0)
nio4r (2.5.2)
nokogiri (1.10.7)
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
oj (3.10.2)
oj_mimic_json (1.0.1)
Expand All @@ -371,7 +371,7 @@ GEM
pwqgen.rb (0.1.0)
docopt (~> 0.5)
sysrandom
rack (2.2.1)
rack (2.2.2)
rack-accept (0.4.5)
rack (>= 0.4)
rack-cors (1.1.1)
Expand Down Expand Up @@ -515,7 +515,7 @@ GEM
sprockets (>= 3.0.0)
string_pattern (2.2.1)
regexp_parser (~> 1.3, >= 1.3.0)
strip_attributes (1.9.0)
strip_attributes (1.9.1)
activemodel (>= 3.0, < 7.0)
strong_migrations (0.6.2)
activerecord (>= 5)
Expand Down Expand Up @@ -543,7 +543,7 @@ GEM
uuid (2.3.9)
macaddr (~> 1.0)
vcr (3.0.3)
webmock (3.8.1)
webmock (3.8.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down
60 changes: 0 additions & 60 deletions app/controllers/concerns/metrics_helper.rb

This file was deleted.

44 changes: 6 additions & 38 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
class DoisController < ApplicationController
include ActionController::MimeResponds
include Crosscitable
include MetricsHelper # mixes in your helper method as class method

prepend_before_action :authenticate_user!
before_action :set_include, only: [:index, :show, :create, :update]
Expand Down Expand Up @@ -197,22 +196,9 @@ def index
}
logger.warn method: "GET", path: "/dois", message: "AggregationsLinkChecks /dois", duration: bm

if params[:mix_in] == "metrics"
dois_names = results.map { |result| result.dig(:_source, :doi) }.join(',')
metrics_array = get_metrics_array(dois_names)
results = mix_in_metrics_array(results, metrics_array)
end

if params[:user_stats]
person_metrics = get_person_metrics(params[:user_id])
citations = person_metrics[:citations]
views = person_metrics[:views]
downloads = person_metrics[:downloads]
else
citations = total.positive? ? metric_facet_by_year(response.aggregations.citations.buckets) : nil
views = total.positive? ? metric_facet_by_year(response.aggregations.views.buckets) : nil
downloads = total.positive? ? metric_facet_by_year(response.aggregations.downloads.buckets) : nil
end
citations = total.positive? ? metric_facet_by_year(response.aggregations.citations.buckets) : nil
views = total.positive? ? metric_facet_by_year(response.aggregations.views.buckets) : nil
downloads = total.positive? ? metric_facet_by_year(response.aggregations.downloads.buckets) : nil

respond_to do |format|
format.json do
Expand Down Expand Up @@ -263,9 +249,6 @@ def index
options[:params] = {
current_ability: current_ability,
detail: params[:detail],
events: params[:events],
mix_in: params[:mix_in],
metrics: metrics_array,
affiliation: params[:affiliation],
is_collection: options[:is_collection],
}
Expand Down Expand Up @@ -305,21 +288,14 @@ def show
doi = Doi.where(doi: params[:id]).first
fail ActiveRecord::RecordNotFound if not_allowed_by_doi_and_user(doi: doi, user: current_user)

if params[:mix_in] == "metrics"
metrics_array = get_metrics_array(doi.uid) || []
doi = mix_in_metrics(doi, metrics_array.first)
end

respond_to do |format|
format.json do
options = {}
options[:include] = @include
options[:is_collection] = false
options[:params] = {
current_ability: current_ability,
events: params[:events],
detail: true,
mix_in: params[:mix_in],
affiliation: params[:affiliation],
}

Expand Down Expand Up @@ -540,18 +516,10 @@ def status
def set_include
if params[:include].present?
@include = params[:include].split(",").map { |i| i.downcase.underscore.to_sym }

if params[:events].present?
@include = @include & [:client, :media, :references, :citations, :parts, :versions]
else
@include = @include & [:client, :media]
end

@include = @include & [:client, :media]
else
if params[:events].present?
@include = [:client, :media, :references, :citations, :parts, :versions]
else
@include = [:client, :media]
end
@include = [:client, :media]
end
end

Expand Down
30 changes: 0 additions & 30 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,7 @@ 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? ? EventsQuery.new.usage(params[:doi]) : nil
# dois_citations = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_citations_by_year_v1(response.response.aggregations.dois_citations) : nil
citations = total.positive? ? EventsQuery.new.citations(params[:doi]) : nil
citations_histogram = total.positive? ? EventsQuery.new.citations_histogram(params[:doi]) : nil
references = total.positive? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.references.dois.buckets) : nil
relations = total.positive? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.relations.dois.buckets) : nil

views_histogram = total.positive? ? EventsQuery.new.views_histogram(params[:doi]) : nil
downloads_histogram = total.positive? ? EventsQuery.new.downloads_histogram(params[:doi]) : nil

# views = total.positive? ? EventsQuery.new.views(params[:doi]) : nil
# downloads = total.positive? ? EventsQuery.new.downloads(params[:doi]) : nil
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
states = total.positive? && aggregations.include?("state_aggregations") ? facet_by_source(response.response.aggregations.states.buckets) : nil

}
Rails.logger.warn method: "GET", path: "/events", message: "Aggregations /events", duration: bm

Expand All @@ -202,22 +187,7 @@ def index
"relationTypes" => relation_types,
pairings: pairings,
registrants: registrants,
"doisRelationTypes": dois,
"doisUsageTypes": dois_usage,
# "doisCitations": dois_citations,
"citationsHistogram": citations_histogram,
"uniqueCitations": citations,
"references": references,
"relations": relations,
"states": states,
"uniqueNodes": {
"objCount": unique_obj_count,
"subjCount": unique_subj_count
},
"viewsHistogram": views_histogram,
# "views": views,
"downloadsHistogram": downloads_histogram
# "downloads": downloads
}.compact

options[:links] = {
Expand Down
Loading

0 comments on commit 280c2c6

Please sign in to comment.