Skip to content

Commit

Permalink
Merge pull request #381 from datacite/feat_person_metrics
Browse files Browse the repository at this point in the history
Feat person metrics
  • Loading branch information
kjgarza authored Dec 31, 2019
2 parents 028f736 + 2463506 commit 206400b
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,56 @@ 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

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)
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] }
end

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] }
end

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] }
end

def https_to_http(url)
orcid = orcid_from_url(url)
return nil unless orcid.present?
Expand Down

0 comments on commit 206400b

Please sign in to comment.