Skip to content

Commit

Permalink
Merge pull request #338 from datacite/feature_count_unique_doi
Browse files Browse the repository at this point in the history
obtain unique doi count
  • Loading branch information
kjgarza authored Aug 26, 2019
2 parents 9508252 + 6a00bbd commit b062db3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def index
downloads_histogram = total.positive? && aggregations.include?("metrics_aggregations") ? facet_counts_by_year_month(response.response.aggregations.downloads_histogram) : nil
views = total.positive? && aggregations.include?("metrics_aggregations") ? facet_by_source(response.response.aggregations.views.dois.buckets) : nil
downloads = total.positive? && aggregations.include?("metrics_aggregations") ? facet_by_source(response.response.aggregations.downloads.dois.buckets) : nil
unique_obj_count = total.positive? && aggregations.include?("advanced_aggregations") ? response.response.aggregations.unique_obj_count.value : nil
unique_subj_count = total.positive? && aggregations.include?("advanced_aggregations") ? response.response.aggregations.unique_subj_count.value : nil

results = response.results

Expand All @@ -151,6 +153,10 @@ def index
"doisCitations": dois_citations,
"citationsHistogram": citations_histogram,
"uniqueCitations": citations,
"uniqueNodes": {
"objCount": unique_obj_count,
"subjCount": unique_subj_count
},
"viewsHistogram": views_histogram,
"views": views,
"downloadsHistogram": downloads_histogram,
Expand Down
7 changes: 7 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def self.metrics_aggregations
}
end

def self.advanced_aggregations
{
unique_obj_count: { cardinality: { field: 'obj_id' }},
unique_subj_count: { cardinality: { field: 'subj_id' }}
}
end

# return results for one or more ids
def self.find_by_id(ids, options={})
ids = ids.split(",") if ids.is_a?(String)
Expand Down

0 comments on commit b062db3

Please sign in to comment.