diff --git a/app/graphql/types/metric_interface.rb b/app/graphql/types/metric_interface.rb index ac84929fe..523a35ef4 100644 --- a/app/graphql/types/metric_interface.rb +++ b/app/graphql/types/metric_interface.rb @@ -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" @@ -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