Skip to content

Commit

Permalink
show number of ORCID ids by year. #629
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Sep 15, 2020
1 parent 324daa5 commit 4073275
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6981,6 +6981,7 @@ type PersonConnectionWithTotal {
publicationConnectionCount: Int!
softwareConnectionCount: Int!
totalCount: Int!
years: [Facet!]
}

"""
Expand Down
22 changes: 22 additions & 0 deletions app/graphql/types/person_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ class PersonConnectionWithTotalType < BaseConnection
edge_type(PersonEdgeType)
field_class GraphQL::Cache::Field

# data from Tom Demeranville (ORCID) on Sep 15, 2020
YEARS = [
{ "id" => "2012", "title" => "2012", "count" => 44270 },
{ "id" => "2013", "title" => "2013", "count" => 426775 },
{ "id" => "2014", "title" => "2014", "count" => 612300 },
{ "id" => "2015", "title" => "2015", "count" => 788650 },
{ "id" => "2016", "title" => "2016", "count" => 1068295 },
{ "id" => "2017", "title" => "2017", "count" => 1388796 },
{ "id" => "2018", "title" => "2018", "count" => 1585851 },
{ "id" => "2019", "title" => "2019", "count" => 2006672 },
]

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :publication_connection_count, Integer, null: false, cache: true
field :dataset_connection_count, Integer, null: false, cache: true
field :software_connection_count, Integer, null: false, cache: true
Expand All @@ -13,6 +26,15 @@ class PersonConnectionWithTotalType < BaseConnection
def total_count
object.total_count
end

def years
count = YEARS.reduce(0) do |sum, i|
sum += i["count"]
sum
end
this_year = object.total_count > count ? { "id" => "2020", "title" => "2020", "count" => object.total_count - count } : nil
this_year ? YEARS << this_year : YEARS
end

def publication_connection_count
Event.query(nil, citation_type: "Person-ScholarlyArticle", page: { number: 1, size: 0 }).results.total
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions spec/graphql/types/person_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,29 @@
end
end

describe "query all people", elasticsearch: true, vcr: true do
let(:query) do
%(query {
people {
totalCount
years {
id
title
count
}
}
})
end

it "returns people information" do
response = LupoSchema.execute(query).as_json

expect(response.dig("data", "people", "totalCount")).to eq(9688620)
expect(response.dig("data", "people", "years").first).to eq("count"=>44270, "id"=>"2012", "title"=>"2012")
expect(response.dig("data", "people", "years").last).to eq("count"=>1767011, "id"=>"2020", "title"=>"2020")
end
end

describe "query people", elasticsearch: true, vcr: true do
let(:query) do
%(query {
Expand Down

0 comments on commit 4073275

Please sign in to comment.