Class: LevelUp::HomeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/level_up/home_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/level_up/home_controller.rb', line 9

def index
  @metrics = {created: {}, started: {}, ended: {}, canceled: {}}
  [:created, :started, :ended, :canceled].each do |type|
    start_date = Date.today - 1.month
    values = LevelUp::Job.where(created_at: start_date..Date.today).order(:created_at).group("DATE(#{type}_at)").count

    while start_date != Date.today do
      @metrics[type][start_date.to_s] = values[start_date.to_s] ? values[start_date.to_s] : 0
      start_date += 1.day
    end
  end
end