From 407327512e7ebfddc9879a3dd8c71e97d11cdd10 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 15 Sep 2020 19:09:13 +0200 Subject: [PATCH] show number of ORCID ids by year. #629 --- app/graphql/schema.graphql | 1 + .../person_connection_with_total_type.rb | 22 +++++++++ .../returns_people_information.yml | 49 +++++++++++++++++++ spec/graphql/types/person_type_spec.rb | 23 +++++++++ 4 files changed, 95 insertions(+) create mode 100644 spec/fixtures/vcr_cassettes/PersonType/query_all_people/returns_people_information.yml diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index e045986d9..5d9032928 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -6981,6 +6981,7 @@ type PersonConnectionWithTotal { publicationConnectionCount: Int! softwareConnectionCount: Int! totalCount: Int! + years: [Facet!] } """ diff --git a/app/graphql/types/person_connection_with_total_type.rb b/app/graphql/types/person_connection_with_total_type.rb index 33e076761..c83068895 100644 --- a/app/graphql/types/person_connection_with_total_type.rb +++ b/app/graphql/types/person_connection_with_total_type.rb @@ -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 @@ -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 diff --git a/spec/fixtures/vcr_cassettes/PersonType/query_all_people/returns_people_information.yml b/spec/fixtures/vcr_cassettes/PersonType/query_all_people/returns_people_information.yml new file mode 100644 index 000000000..8b0e4cb48 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/PersonType/query_all_people/returns_people_information.yml @@ -0,0 +1,49 @@ +--- +http_interactions: +- request: + method: get + uri: https://pub.orcid.org/v3.0/expanded-search/?q=*&rows=25&start=0 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.7.2; mailto:info@datacite.org) + Accept: + - application/json;charset=UTF-8 + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx/1.16.1 + Cache-Control: + - no-cache, no-store, max-age=0, must-revalidate + Content-Type: + - application/json;charset=UTF-8 + Date: + - Tue, 15 Sep 2020 16:36:06 GMT + Expires: + - '0' + Pragma: + - no-cache + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + X-Content-Type-Options: + - nosniff + Connection: + - keep-alive + Set-Cookie: + - X-Mapping-fjhppofk=16FE77A10C90007D85F4078C6A4BB780; path=/ + X-Frame-Options: + - DENY + body: + encoding: ASCII-8BIT + string: !binary |- + eyJleHBhbmRlZC1yZXN1bHQiOlt7Im9yY2lkLWlkIjoiMDAwMC0wMDAyLTUzODctNjQwNyIsImdpdmVuLW5hbWVzIjoiTW9oYW1tZWQiLCJmYW1pbHktbmFtZXMiOiJBbC1EaGFoaXIiLCJjcmVkaXQtbmFtZSI6bnVsbCwib3RoZXItbmFtZSI6WyJNb2hhbW1lZCBBbGkgQWwtRGhhaGlyIl0sImVtYWlsIjpbXSwiaW5zdGl0dXRpb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XMiOiJBWUFOIiwiZmFtaWx5LW5hbWVzIjoiS0FSIiwiY3JlZGl0LW5hbWUiOm51bGwsIm90aGVyLW5hbWUiOltdLCJlbWFpbCI6W10sImluc3RpdHV0aW9uLW5hbWUiOltdfSx7Im9yY2lkLWlkIjoiMDAwMC0wMDAzLTIwNjQtNDQyMCIsImdpdmVuLW5hbWVzIjoiUGllcnJlIENocmlzdGlhbiIsImZhbWlseS1uYW1lcyI6IkthbmEgTmd1ZW5lIiwiY3JlZGl0LW5hbWUiOm51bGwsIm90aGVyLW5hbWUiOltdLCJlbWFpbCI6W10sImluc3RpdHV0aW9uLW5hbWUiOltdfSx7Im9yY2lkLWlkIjoiMDAwMC0wMDAyLTQ4NTctNDUxOSIsImdpdmVuLW5hbWVzIjoiQmlhbmNhIiwiZmFtaWx5LW5hbWVzIjoiU2FtcGFpbyBEb3R0byBGaXV6YSIsImNyZWRpdC1uYW1lIjpudWxsLCJvdGhlci1uYW1lIjpbXSwiZW1haWwiOltdLCJpbnN0aXR1dGlvbi1uYW1lIjpbXX0seyJvcmNpZC1pZCI6IjAwMDAtMDAwMy0wMjU1LTAzNTkiLCJnaXZlbi1uYW1lcyI6IkRhbmllbCIsImZhbWlseS1uYW1lcyI6IkJ1bGhvZXMiLCJjcmVkaXQtbmFtZSI6bnVsbCwib3RoZXItbmFtZSI6W10sImVtYWlsIjpbXSwiaW5zdGl0dXRpb24tbmFtZSI6W119XSwibnVtLWZvdW5kIjo5Njg4NjIwfQ== + http_version: null + recorded_at: Tue, 15 Sep 2020 16:36:06 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/graphql/types/person_type_spec.rb b/spec/graphql/types/person_type_spec.rb index c68a24720..2be37f7c4 100644 --- a/spec/graphql/types/person_type_spec.rb +++ b/spec/graphql/types/person_type_spec.rb @@ -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 {