From f99c54095e369c498707b3bd3831f0b31f2b19b1 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sat, 10 Oct 2020 17:40:09 +0200 Subject: [PATCH] fix citation count per person. #624 --- app/graphql/types/funder_type.rb | 6 +++--- app/graphql/types/organization_type.rb | 6 +++--- app/graphql/types/person_type.rb | 6 +++--- app/graphql/types/repository_type.rb | 6 +++--- app/models/doi.rb | 24 +++------------------- spec/graphql/types/funder_type_spec.rb | 6 ++++-- spec/graphql/types/person_type_spec.rb | 4 +++- spec/graphql/types/repository_type_spec.rb | 2 +- 8 files changed, 23 insertions(+), 37 deletions(-) diff --git a/app/graphql/types/funder_type.rb b/app/graphql/types/funder_type.rb index 88406f46f..80c340303 100644 --- a/app/graphql/types/funder_type.rb +++ b/app/graphql/types/funder_type.rb @@ -179,19 +179,19 @@ def works(**args) def view_count args = { first: 0 } r = response(args) - aggregate_count(r.response.aggregations.views.buckets) + r.response.aggregations.view_count.value.to_i end def download_count args = { first: 0 } r = response(args) - aggregate_count(r.response.aggregations.downloads.buckets) + r.response.aggregations.download_count.value.to_i end def citation_count args = { first: 0 } r = response(args) - aggregate_count(r.response.aggregations.citations.buckets) + r.response.aggregations.citation_count.value.to_i end def response(**args) diff --git a/app/graphql/types/organization_type.rb b/app/graphql/types/organization_type.rb index 065725e42..60e792b19 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -244,19 +244,19 @@ def people(**args) def view_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.views.buckets) : 0 + r.response.aggregations.view_count.value.to_i end def download_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.downloads.buckets) : 0 + r.response.aggregations.download_count.value.to_i end def citation_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.citations.buckets) : 0 + r.response.aggregations.citation_count.value.to_i end def response(**args) diff --git a/app/graphql/types/person_type.rb b/app/graphql/types/person_type.rb index 7e3d1292d..5ec11c966 100644 --- a/app/graphql/types/person_type.rb +++ b/app/graphql/types/person_type.rb @@ -138,19 +138,19 @@ def works(**args) def view_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.views.buckets) : 0 + r.response.aggregations.view_count.value.to_i end def download_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.downloads.buckets) : 0 + r.response.aggregations.download_count.value.to_i end def citation_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.citations.buckets) : 0 + r.response.aggregations.citation_count.value.to_i end def response(**args) diff --git a/app/graphql/types/repository_type.rb b/app/graphql/types/repository_type.rb index 841a67a97..1bbb9865e 100644 --- a/app/graphql/types/repository_type.rb +++ b/app/graphql/types/repository_type.rb @@ -206,19 +206,19 @@ def prefixes(**args) def view_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.views.buckets) : 0 + r.response.aggregations.view_count.value.to_i end def download_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.downloads.buckets) : 0 + r.response.aggregations.download_count.value.to_i end def citation_count args = { first: 0 } r = response(args) - r.results.total.positive? ? aggregate_count(r.response.aggregations.citations.buckets) : 0 + r.response.aggregations.citation_count.value.to_i end def response(**args) diff --git a/app/models/doi.rb b/app/models/doi.rb index 42d02f914..2026b3659 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -574,27 +574,9 @@ def self.gql_query_aggregations }, licenses: { terms: { field: 'rights_list.rightsIdentifier', size: 10, min_doc_count: 1 } }, languages: { terms: { field: 'language', size: 10, min_doc_count: 1 } }, - views: { - date_histogram: { field: 'publication_year', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 }, - aggs: { - metric_count: { sum: { field: "view_count" } }, - bucket_truncate: { bucket_sort: { size: 10 } }, - }, - }, - downloads: { - date_histogram: { field: 'publication_year', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 }, - aggs: { - metric_count: { sum: { field: "download_count" } }, - bucket_truncate: { bucket_sort: { size: 10 } }, - }, - }, - citations: { - date_histogram: { field: 'publication_year', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 }, - aggs: { - metric_count: { sum: { field: "citation_count" } }, - bucket_truncate: { bucket_sort: { size: 10 } }, - }, - }, + view_count: { sum: { field: "view_count" } }, + download_count: { sum: { field: "download_count" } }, + citation_count: { sum: { field: "citation_count" } }, } end diff --git a/spec/graphql/types/funder_type_spec.rb b/spec/graphql/types/funder_type_spec.rb index 8aa9bfeca..42b147b1d 100644 --- a/spec/graphql/types/funder_type_spec.rb +++ b/spec/graphql/types/funder_type_spec.rb @@ -80,8 +80,10 @@ expect(response.dig("data", "funder", "id")).to eq("https://doi.org/10.13039/501100009053") expect(response.dig("data", "funder", "name")).to eq("The Wellcome Trust DBT India Alliance") - expect(response.dig("data", "funder", "citationCount")).to eq(0) - + expect(response.dig("data", "funder", "citationCount")).to eq(2) + expect(response.dig("data", "funder", "viewCount")).to eq(0) + expect(response.dig("data", "funder", "downloadCount")).to eq(0) + expect(response.dig("data", "funder", "works", "totalCount")).to eq(1) expect(Base64.urlsafe_decode64(response.dig("data", "funder", "works", "pageInfo", "endCursor")).split(",", 2).last).to eq(doi.uid) expect(response.dig("data", "funder", "works", "pageInfo", "hasNextPage")).to be false diff --git a/spec/graphql/types/person_type_spec.rb b/spec/graphql/types/person_type_spec.rb index 2be37f7c4..b81b8464d 100644 --- a/spec/graphql/types/person_type_spec.rb +++ b/spec/graphql/types/person_type_spec.rb @@ -116,7 +116,9 @@ expect(response.dig("data", "person", "identifiers")).to eq([{"identifier"=>"kjgarza", "identifierType"=>"GitHub", "identifierUrl"=>"https://github.com/kjgarza"}]) expect(response.dig("data", "person", "country")).to eq("id"=>"DE", "name"=>"Germany") expect(response.dig("data", "person", "employment")).to eq([{"endDate"=>nil, "organizationId"=>nil, "organizationName"=>"DataCite", "roleTitle"=>"Application Developer", "startDate"=>"2016-08-01T00:00:00Z"}]) - expect(response.dig("data", "person", "citationCount")).to eq(0) + expect(response.dig("data", "person", "citationCount")).to eq(2) + expect(response.dig("data", "person", "viewCount")).to eq(0) + expect(response.dig("data", "person", "downloadCount")).to eq(0) expect(response.dig("data", "person", "works", "totalCount")).to eq(1) expect(response.dig("data", "person", "works", "published")).to eq([{"count"=>1, "id"=>"2011", "title"=>"2011"}]) expect(response.dig("data", "person", "works", "resourceTypes")).to eq([{"count"=>1, "id"=>"dataset", "title"=>"Dataset"}]) diff --git a/spec/graphql/types/repository_type_spec.rb b/spec/graphql/types/repository_type_spec.rb index 2708d9e55..ab8765a7e 100644 --- a/spec/graphql/types/repository_type_spec.rb +++ b/spec/graphql/types/repository_type_spec.rb @@ -218,7 +218,7 @@ expect(response.dig("data", "repository", "id")).to eq("testr.testr") expect(response.dig("data", "repository", "name")).to eq("My data center") - expect(response.dig("data", "repository", "citationCount")).to eq(0) + expect(response.dig("data", "repository", "citationCount")).to eq(2) expect(response.dig("data", "repository", "works", "totalCount")).to eq(3) expect(response.dig("data", "repository", "works", "published")).to eq([{"count"=>3, "id"=>"2011", "title"=>"2011"}]) expect(response.dig("data", "repository", "works", "resourceTypes")).to eq([{"count"=>3, "id"=>"dataset", "title"=>"Dataset"}])