Skip to content

Commit

Permalink
correctly sort citations over time, only show in detail view. #418
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 17, 2020
1 parent 524a808 commit d5a5a3e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ def view_count
def views_over_time
view_events.pluck(:occurred_at, :total)
.map { |v| { "yearMonth" => v[0].present? ? v[0].utc.iso8601[0..6] : nil, "total" => v[1] } }
.sort_by { |h| h[:year_month] }
.sort_by { |h| h["yearMonth"] }
end

def download_count
Expand All @@ -1002,7 +1002,7 @@ def download_count
def downloads_over_time
download_events.pluck(:occurred_at, :total)
.map { |v| { "yearMonth" => v[0].present? ? v[0].utc.iso8601[0..6] : nil, "total" => v[1] } }
.sort_by { |h| h[:year_month] }
.sort_by { |h| h["yearMonth"] }
end

def reference_event_ids
Expand All @@ -1028,7 +1028,7 @@ def citations_over_time
citation_events.pluck(:occurred_at, :source_doi).uniq { |v| v[1] }
.group_by { |v| v[0].utc.iso8601[0..3] }
.map { |k, v| { "year" => k, "total" => v.length } }
.sort_by { |h| h[:year] }
.sort_by { |h| h["year"] }
end

# def part_ids
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class DoiSerializer
# don't cache dois, as works are cached using the doi model

attributes :doi, :prefix, :suffix, :identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :view_count, :views_over_time, :download_count, :downloads_over_time, :reference_count, :citation_count, :citations_over_time, :created, :registered, :published, :updated
attributes :prefix, :suffix, if: Proc.new { |object, params| params && params[:detail] }
attributes :prefix, :suffix, :views_over_time, :downloads_over_time, :citations_over_time, if: Proc.new { |object, params| params && params[:detail] }

belongs_to :client, record_type: :clients
has_many :media, record_type: :media, id_method_name: :uid, if: Proc.new { |object, params| params && params[:detail] && !params[:is_collection]}
Expand Down
4 changes: 2 additions & 2 deletions app/serializers/work_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class WorkSerializer
set_id :identifier
cache_options enabled: true, cache_length: 24.hours

attributes :doi, :identifier, :url, :author, :title, :container_title, :description, :resource_type_subtype, :data_center_id, :member_id, :resource_type_id, :version, :license, :schema_version, :results, :related_identifiers, :citation_count, :view_count, :views_over_time, :download_count, :downloads_over_time, :published, :registered, :checked, :updated, :media, :xml
attributes :doi, :identifier, :url, :author, :title, :container_title, :description, :resource_type_subtype, :data_center_id, :member_id, :resource_type_id, :version, :license, :schema_version, :results, :related_identifiers, :citation_count, :citations_over_time, :view_count, :views_over_time, :download_count, :downloads_over_time, :published, :registered, :checked, :updated, :media, :xml

belongs_to :client, key: "data-center", record_type: "data-centers", serializer: :DataCenter
belongs_to :client, key: "data-center", record_type: "data-centers", serializer: DataCenter
belongs_to :provider, key: :member, record_type: :members, serializer: :Member
belongs_to :resource_type, record_type: "resource-types", serializer: :ResourceType

Expand Down

0 comments on commit d5a5a3e

Please sign in to comment.