Skip to content

Commit

Permalink
fix citation count per person. #624
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 10, 2020
1 parent a5d54e6 commit f99c540
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 37 deletions.
6 changes: 3 additions & 3 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/repository_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 3 additions & 21 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions spec/graphql/types/funder_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion spec/graphql/types/person_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}])
Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/types/repository_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}])
Expand Down

0 comments on commit f99c540

Please sign in to comment.