Class: Stats::Actions

Inherits:
Object
  • Object
show all
Defined in:
app/models/stats/actions.rb

Constant Summary collapse

SECONDS_PER_DAY =
86400

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Actions

Returns a new instance of Actions


7
8
9
# File 'app/models/stats/actions.rb', line 7

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user


6
7
8
# File 'app/models/stats/actions.rb', line 6

def user
  @user
end

Instance Method Details

#completedObject (private)


73
74
75
# File 'app/models/stats/actions.rb', line 73

def completed
  @completed ||= user.todos.completed.select("completed_at, created_at")
end

#completion_chartsObject


31
32
33
34
35
36
37
38
39
# File 'app/models/stats/actions.rb', line 31

def completion_charts
  @completion_charts ||= %w{
 actions_done_last30days_data
 actions_done_last12months_data
 actions_completion_time_data
  }.map do |action|
    Stats::Chart.new(action)
  end
end

#created_last12monthsObject


27
28
29
# File 'app/models/stats/actions.rb', line 27

def created_last12months
  @sum_actions_created_last12months ||= new_since(one_year)
end

#created_last30daysObject


23
24
25
# File 'app/models/stats/actions.rb', line 23

def created_last30days
  @sum_actions_created_last30days ||= new_since(one_month)
end

#done_last12monthsObject


19
20
21
# File 'app/models/stats/actions.rb', line 19

def done_last12months
  @done_last12months ||= done_since(one_year)
end

#done_last30daysObject


15
16
17
# File 'app/models/stats/actions.rb', line 15

def done_last30days
  @done_last30days ||= done_since(one_month)
end

#done_since(cutoff) ⇒ Object (private)


69
70
71
# File 'app/models/stats/actions.rb', line 69

def done_since(cutoff)
  user.todos.completed.completed_after(cutoff).count
end

#new_since(cutoff) ⇒ Object (private)


65
66
67
# File 'app/models/stats/actions.rb', line 65

def new_since(cutoff)
  user.todos.created_after(cutoff).count
end

#one_monthObject (private)


61
62
63
# File 'app/models/stats/actions.rb', line 61

def one_month
  @one_month ||= 1.month.ago.beginning_of_day
end

#one_yearObject (private)


57
58
59
# File 'app/models/stats/actions.rb', line 57

def one_year
  @one_year ||= 12.months.ago.beginning_of_day
end

#timing_chartsObject


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/stats/actions.rb', line 41

def timing_charts
  @timing_charts ||= %w{
  actions_visible_running_time_data
  actions_running_time_data
  actions_open_per_week_data
  actions_day_of_week_all_data
  actions_day_of_week_30days_data
  actions_time_of_day_all_data
  actions_time_of_day_30days_data
  }.map do |action|
    Stats::Chart.new(action)
  end
end

#ttcObject


11
12
13
# File 'app/models/stats/actions.rb', line 11

def ttc
  @ttc ||= TimeToComplete.new(completed)
end