-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/datacite/lupo
- Loading branch information
Showing
10 changed files
with
290 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,61 @@ | ||
require "pp" | ||
module MetricsHelper | ||
extend ActiveSupport::Concern | ||
include Helpable | ||
|
||
class_methods do | ||
def doi_citations(doi) | ||
EventsQuery.new.doi_citations(doi) | ||
included do | ||
def get_metrics_array(dois) | ||
citations = EventsQuery.new.citations(dois) | ||
usage = EventsQuery.new.views_and_downloads(dois) | ||
merge_array_hashes(citations, usage) | ||
end | ||
|
||
def doi_views(doi) | ||
EventsQuery.new.doi_views(doi) | ||
def get_person_metrics(orcid) | ||
dois = get_person_dois(orcid).join(",") | ||
usage = EventsQuery.new.views_and_downloads(dois) | ||
{ | ||
citations: EventsQuery.new.citations(dois).sum { |h| h[:citations] }, | ||
views: usage.sum { |h| h[:views] }, | ||
downloads: usage.sum { |h| h[:downloads] }, | ||
} | ||
end | ||
|
||
def doi_downloads(doi) | ||
EventsQuery.new.doi_downloads(doi) | ||
def get_person_dois(orcid) | ||
Event.query(nil, page: { size: 500 }, obj_id: https_to_http(orcid)).results.to_a.map do |e| | ||
doi_from_url(e.subj_id) | ||
end | ||
end | ||
|
||
def https_to_http(url) | ||
orcid = orcid_from_url(url) | ||
return nil if orcid.blank? | ||
|
||
"https://orcid.org/#{orcid}" | ||
end | ||
|
||
def mix_in_metrics_array(metadata_array_objects, metrics_array_hashes) | ||
return [] if metadata_array_objects.empty? | ||
|
||
metadata_array_objects.map do |metadata| | ||
metadata_hash = metadata.to_hash | ||
metrics = metrics_array_hashes.select { |hash| hash[:id] == metadata_hash["_source"]["uid"] }.first | ||
Hashie::Mash.new(metadata_hash)._source.shallow_update(metrics) | ||
end | ||
end | ||
|
||
def mix_in_metrics(metadata, metrics) | ||
metadata_hash = metadata.attributes | ||
metrics[:doi] = metrics.delete :id | ||
metrics[:uid] = metrics[:doi] | ||
metrics[:doi] = metrics[:doi].upcase | ||
metadata_hash.merge!(metrics) | ||
Hashie::Mash.new(metadata_hash) | ||
end | ||
end | ||
|
||
# class_methods do | ||
# # def mix_in_metrics(doi, metrics_array_hashes) | ||
# # metrics_array_hashes.select { |hash| hash[:id] == doi }.first | ||
# # end | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.