From d5a5a3ef886bfcc072381fd01e2a65b4dbf806b1 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 18 Feb 2020 00:24:44 +0100 Subject: [PATCH] correctly sort citations over time, only show in detail view. #418 --- app/models/doi.rb | 6 +++--- app/serializers/doi_serializer.rb | 2 +- app/serializers/work_serializer.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/doi.rb b/app/models/doi.rb index 27561905a..cd7d7011c 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -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 @@ -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 @@ -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 diff --git a/app/serializers/doi_serializer.rb b/app/serializers/doi_serializer.rb index 2faa00467..6b8f64b12 100644 --- a/app/serializers/doi_serializer.rb +++ b/app/serializers/doi_serializer.rb @@ -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]} diff --git a/app/serializers/work_serializer.rb b/app/serializers/work_serializer.rb index 848991681..3f5229020 100644 --- a/app/serializers/work_serializer.rb +++ b/app/serializers/work_serializer.rb @@ -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