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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/error_radar/digest.rb', line 28
def self.build(since:)
now = Time.current
counts = ErrorLog.group(:status).count
inv = ErrorLog.statuses.invert
open_count = counts[ErrorLog.statuses['open']] || 0
in_prog_count = counts[ErrorLog.statuses['in_progress']] || 0
resolved = counts[ErrorLog.statuses['resolved']] || 0
ignored = counts[ErrorLog.statuses['ignored']] || 0
total = counts.values.sum
unresolved = open_count + in_prog_count
new_this_period = ErrorLog.where('first_seen_at >= ?', since).count
resolved_this_period = ErrorLog.where('resolved_at >= ?', since).count
reopened_this_period = ErrorLog.unresolved.where('resolved_at < ?', since)
.where('last_seen_at >= ?', since).count
top_unresolved = ErrorLog.unresolved.order(occurrences: :desc).limit(10).to_a
recent_new = ErrorLog.where('first_seen_at >= ?', since)
.order(first_seen_at: :desc).limit(10).to_a
by_severity = ErrorLog.unresolved.group(:severity).count
.transform_keys { |k| ErrorLog.severities.invert[k] || k.to_s }
by_category = ErrorLog.unresolved.group(:category).count
.transform_keys { |k| ErrorLog.categories.invert[k] || k.to_s }
trend = build_trend(since, now)
{
period_start: since,
period_end: now,
total: total,
open: open_count,
in_progress: in_prog_count,
unresolved: unresolved,
resolved_total: resolved,
ignored_total: ignored,
new_this_period: new_this_period,
resolved_this_period: resolved_this_period,
reopened_this_period: reopened_this_period,
top_unresolved: top_unresolved,
recent_new: recent_new,
by_severity: by_severity,
by_category: by_category,
trend: trend
}
end
|