Skip to content

Commit

Permalink
integrate graphQL with new citations algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Nov 1, 2019
1 parent 30a9ab1 commit c71ccaa
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions app/graphql/types/metric_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module MetricInterface
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"
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"
# 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"

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
Event.query(nil, doi: doi_from_url(args[:id]), "page[size]": 0, aggregations: args[:aggregations] || "metrics_aggregations", source_id: args[:source_id] || nil).response.aggregations
end

def view_count
Expand All @@ -26,44 +26,44 @@ def download_count

def citation_count
meta = citations_aggs
meta.first.fetch("unique_citations", {}).fetch("value", nil) if meta.any?
meta.first.fetch("total", {}).fetch("value", nil) if meta.any?
end

def references_count
meta = references_aggs
meta.first.fetch("references", {}).fetch("value", nil) if meta.any?
meta.first.fetch("total", {}).fetch("value", nil) if meta.any?
end

def relations_count
meta = relations_aggs
meta.first.fetch("relations", {}).fetch("value", nil) if meta.any?
meta.first.fetch("total", {}).fetch("value", nil) if meta.any?
end

def references_list
references_aggs.map { |item| item[:key]}
end
# def references_list
# references_aggs.map { |item| item[:key]}
# end

def relations_list
relations_aggs.map { |item| item[:key]}
end
# def relations_list
# relations_aggs.map { |item| item[:key]}
# end

def citations_list
citations_aggs.map { |item| item[:key]}
# citations_aggs.map do |item|
# puts item[:key]
# puts Doi.find_by_id(item[:key]).results.first
# end
end
# def citations_list
# citations_aggs.map { |item| item[:key]}
# # citations_aggs.map do |item|
# # puts item[:key]
# # puts Doi.find_by_id(item[:key]).results.first
# # end
# end

def citations_aggs
aggregation_results(id: object.identifier).citations.dois.buckets
aggregation_results(id: object.identifier, aggregations: "citations_aggregations" ).citations.dois.buckets
end

def references_aggs
aggregation_results(id: object.identifier).references.dois.buckets
aggregation_results(id: object.identifier, aggregations: "citations_aggregations").references.dois.buckets
end

def relations_aggs
aggregation_results(id: object.identifier).relations.dois.buckets
aggregation_results(id: object.identifier, aggregations: "citations_aggregations").relations.dois.buckets
end
end

0 comments on commit c71ccaa

Please sign in to comment.