Class: Deployinator::Views::Stats

Inherits:
Layout
  • Object
show all
Defined in:
views/stats.rb

Direct Known Subclasses

MonthStatsLag, StatsLag

Instance Method Summary collapse

Instance Method Details

#deploysObject


6
7
8
9
10
11
12
13
14
# File 'views/stats.rb', line 6

def deploys
  @deploys ||= begin
    log_to_hash({
      :no_global => true, :env => "production",
      :no_limit => true
      # :limit => 200
    })
  end
end

#per_dayObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'views/stats.rb', line 20

def per_day
  early_day = Time.now.strftime("%Y-%m-%d")
  stack_days = deploys.inject({}) do |h, deploy|
    if deploy[:time] && deploy[:stack]
      original_zone = ENV["TZ"]
      ENV["TZ"] = "US/Eastern"
      day = Date.parse(deploy[:time].localtime.strftime("%Y-%m-%d"))
      early_day = day if day.to_s < early_day.to_s
      ENV["TZ"] = original_zone
      h[deploy[:stack]] ||= {}
      h[deploy[:stack]][day] ||= 0
      h[deploy[:stack]][day] += 1
    end
    h
  end

  # fill in zero days
  day_seconds = 24 * 60 * 60
  (0..((Time.now - Time.parse(early_day.to_s)) / day_seconds).to_i).each do |days_ago|
    stack_days.keys.each do |stack|
      day = Date.parse((Time.now - (day_seconds * days_ago)).strftime("%Y-%m-%d"))
      stack_days[stack][day] ||= 0
    end
  end

  n = stack_days.keys.map do |stack|
    data = []
    json = []
    stack_days[stack].sort.reverse.each do |d,c|
      data << {:date => d, :count => c}
      json << [d.strftime("%s").to_i * 1000, c]
    end
    {:stack => stack, :data => data, :json => json.to_json}
  end
end

#timingsObject


16
17
18
# File 'views/stats.rb', line 16

def timings
  deploys
end