Module: Housekeeping::Timestamps

Extended by:
ActiveSupport::Concern
Included in:
GeographicArea, GeographicAreaType, GeographicItem, Language, Namespace, Person, PreparationType, Project, ProjectMember, Repository, Role, Serial, SerialChronology, Source, User
Defined in:
lib/housekeeping/timestamps.rb

Overview

Concern that provides timestamp related methods for housekeeping.

!! https://github.com/ankane/groupdate is now included in TW, and includes many grouping scopes!

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (Array) data_breakdown_for_chartkick_recent

Returns:

  • (Array)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/housekeeping/timestamps.rb', line 92

def data_breakdown_for_chartkick_recent
  Rails.application.eager_load!
  data = []
  has_many_relationships.each do |name|

    today      = self.send(name).created_today.count # in_project(self).count
    this_week  = self.send(name).created_this_week.count # in_project(self).count
    this_month = self.send(name).created_in_last(4.weeks).count # in_project(self).count

    if this_month > 0
      data.push({
                  name: name.to_s.humanize,
                  data: {
                    'this week'  => this_week,
                    today:       today,
                    'this month' => this_month
                  }
                })
    end
  end
  data
end