Skip to content

Commit

Permalink
added citations distribution for graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Nov 4, 2019
1 parent e7db3c0 commit dec26c5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/graphql/types/metric_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module MetricInterface
field :citation_count, Integer, null: true, description: "The count of DOI events that represents citations"
field :reference_count, Integer, null: true, description: "The count of DOI events that represents references"
field :relation_count, Integer, null: true, description: "The count of DOI events that represents relations"
field :citation_histogram, GraphQL::Types::JSON, null: true, description: "The citations distribution overtime"

# field :citations_list, [String], null: true, description: "List of DOIS citing a given DOI"
# field :referenceslist, [String], null: true, description: "List of DOIS that a given DOI references to"
# field :relations_list, [String], null: true, description: "List of DOIS relations a given DOI has"
Expand Down Expand Up @@ -68,4 +70,16 @@ def references_aggs
def relations_aggs
aggregation_results(id: object.identifier, aggregations: "citations_aggregations").relations.dois.buckets
end

def citation_histogram
hash = aggregation_results(id: object.identifier, aggregations: "citations_aggregations").citations_histogram

hash.dig('years', 'buckets').map do |h|
year = h['key']
{
'id' => year,
'sum' => h.dig('total_by_year', 'value')
}
end
end
end

0 comments on commit dec26c5

Please sign in to comment.