Skip to content

Commit

Permalink
add ror statistics by year. #660
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 18, 2020
1 parent 5babfe3 commit 39fab86
Show file tree
Hide file tree
Showing 4 changed files with 163 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 @@ -6403,6 +6403,7 @@ type OrganizationConnectionWithTotal {
personConnectionCount: Int!
totalCount: Int!
types: [Facet!]
years: [Facet!]
}

"""
Expand Down
19 changes: 19 additions & 0 deletions app/graphql/types/organization_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,30 @@ class OrganizationConnectionWithTotalType < BaseConnection
edge_type(OrganizationEdgeType)
field_class GraphQL::Cache::Field

# data from GRID taken on Oct 18, 2020 https://grid.ac/downloads
# using latest release in any given year, starting with end of 2017,
# right before ROR was launched in January 2018
YEARS = [
{ "id" => "2017", "title" => "2017", "count" => 80248 },
{ "id" => "2018", "title" => "2018", "count" => 11392 },
{ "id" => "2019", "title" => "2019", "count" => 6179 },
]

field :total_count, Integer, null: false, cache: true
field :years, [FacetType], null: true, cache: true
field :types, [FacetType], null: true, cache: true
field :countries, [FacetType], null: true, cache: true
field :person_connection_count, Integer, null: false, cache: true

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 total_count
object.total_count
end
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/organization_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,29 @@
end
end

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

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

expect(response.dig("data", "organizations", "totalCount")).to eq(98332)
expect(response.dig("data", "organizations", "years").first).to eq("count"=>80248, "id"=>"2017", "title"=>"2017")
expect(response.dig("data", "organizations", "years").last).to eq("count"=>513, "id"=>"2020", "title"=>"2020")
end
end

describe "query organizations", elasticsearch: true, vcr: true do
let!(:dois) { create_list(:doi, 3) }
let!(:doi) { create(:doi, aasm_state: "findable", creators:
Expand Down

0 comments on commit 39fab86

Please sign in to comment.