-
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 pull request #339 from datacite/feature_get_metrics
Feature get metrics from GraphQL API
- Loading branch information
Showing
6 changed files
with
34 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module MetricInterface | ||
include GraphQL::Schema::Interface | ||
|
||
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 aggregation_results(**args) | ||
Event.query(nil, doi: doi_from_url(args[:id]), "page[size]": 0, aggregations: "metrics_aggregations", source_id: args[:source_id] || nil).response.aggregations | ||
end | ||
|
||
def view_count | ||
meta = aggregation_results(id: object.identifier).views.dois.buckets | ||
meta.first.fetch("total_by_type", {}).fetch("value", nil) if meta.any? | ||
end | ||
|
||
def download_count | ||
meta = aggregation_results(id: object.identifier).downloads.dois.buckets | ||
meta.first.fetch("total_by_type", {}).fetch("value", nil) if meta.any? | ||
end | ||
|
||
def citation_count | ||
meta = aggregation_results(id: object.identifier).citations.dois.buckets | ||
meta.first.fetch("unique_citations", {}).fetch("value", nil) if meta.any? | ||
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