From df8c477fba6505e61122d7dd302d721f740667f8 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 31 Dec 2019 14:09:07 +0100 Subject: [PATCH 1/3] countesr for metrics per user addresses https://github.com/datacite/lupo/issues/372 --- app/graphql/types/person_type.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/graphql/types/person_type.rb b/app/graphql/types/person_type.rb index ad431e533..d4f4e804d 100644 --- a/app/graphql/types/person_type.rb +++ b/app/graphql/types/person_type.rb @@ -21,6 +21,10 @@ class PersonType < BaseObject argument :first, Int, required: false, default_value: 25 end + field :view_count, Integer, null: true, description: "The count of DOI views according to the COUNTER code of Practice" + field :download_count, Integer, null: true, description: "The count of DOI dowloands according to the COUNTER code of Practice" + field :citation_count, Integer, null: true, description: "The count of DOI events that represents citations" + def type "Person" end @@ -46,6 +50,27 @@ def software_source_codes(**args) ElasticsearchLoader.for(Doi).load_many(ids) end + def citation_count(**args) + dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.lazy.map do |e| + doi_from_url(e.subj_id) + end + EventsQuery.new.citations(dois) + end + + def view_count(**args) + dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.lazy.map do |e| + doi_from_url(e.subj_id) + end + EventsQuery.new.views(dois) + end + + def download_count(**args) + dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.lazy.map do |e| + doi_from_url(e.subj_id) + end + EventsQuery.new.downloads(dois) + end + def https_to_http(url) orcid = orcid_from_url(url) return nil unless orcid.present? From 5f68b9dc1c488029cc3bb74bf55fd8699b2e9e94 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 31 Dec 2019 14:13:31 +0100 Subject: [PATCH 2/3] sums totals addresses #372 --- app/graphql/types/person_type.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/graphql/types/person_type.rb b/app/graphql/types/person_type.rb index d4f4e804d..428eac398 100644 --- a/app/graphql/types/person_type.rb +++ b/app/graphql/types/person_type.rb @@ -51,24 +51,24 @@ def software_source_codes(**args) end def citation_count(**args) - dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.lazy.map do |e| + dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.map do |e| doi_from_url(e.subj_id) end - EventsQuery.new.citations(dois) + EventsQuery.new.citations(dois).sum {|h| h[:count] } end def view_count(**args) - dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.lazy.map do |e| + dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.map do |e| doi_from_url(e.subj_id) end - EventsQuery.new.views(dois) + EventsQuery.new.views(dois).sum {|h| h[:count] } end def download_count(**args) - dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.lazy.map do |e| + dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.map do |e| doi_from_url(e.subj_id) end - EventsQuery.new.downloads(dois) + EventsQuery.new.downloads(dois).sum {|h| h[:count] } end def https_to_http(url) From 246350602452ff3b89531c37da979ea43a098996 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Tue, 31 Dec 2019 15:44:01 +0100 Subject: [PATCH 3/3] added space and _ --- app/graphql/types/person_type.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/graphql/types/person_type.rb b/app/graphql/types/person_type.rb index 428eac398..749f5399e 100644 --- a/app/graphql/types/person_type.rb +++ b/app/graphql/types/person_type.rb @@ -29,46 +29,46 @@ def type "Person" end - def datasets(**args) + def datasets(**_args) ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Dataset-Person").results.to_a.map do |e| doi_from_url(e.subj_id) end ElasticsearchLoader.for(Doi).load_many(ids) end - def publications(**args) + def publications(**_args) ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-ScholarlyArticle").results.to_a.map do |e| doi_from_url(e.subj_id) end ElasticsearchLoader.for(Doi).load_many(ids) end - def software_source_codes(**args) + def software_source_codes(**_args) ids = Event.query(nil, obj_id: https_to_http(object[:id]), citation_type: "Person-SoftwareSourceCode").results.to_a.map do |e| doi_from_url(e.subj_id) end ElasticsearchLoader.for(Doi).load_many(ids) end - def citation_count(**args) + def citation_count(**_args) dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.map do |e| doi_from_url(e.subj_id) end - EventsQuery.new.citations(dois).sum {|h| h[:count] } + EventsQuery.new.citations(dois).sum { |h| h[:count] } end - def view_count(**args) + def view_count(**_args) dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.map do |e| doi_from_url(e.subj_id) end - EventsQuery.new.views(dois).sum {|h| h[:count] } + EventsQuery.new.views(dois).sum { |h| h[:count] } end - def download_count(**args) + def download_count(**_args) dois = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.map do |e| doi_from_url(e.subj_id) end - EventsQuery.new.downloads(dois).sum {|h| h[:count] } + EventsQuery.new.downloads(dois).sum { |h| h[:count] } end def https_to_http(url)