Allinea i KPI su due righe e aggiunge lo storico orario degli invii confermati.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
class Mailings::HourlyThroughput
|
||||
HOUR = 1.hour
|
||||
RECENT = 15.minutes
|
||||
HISTORY_HOURS = 12
|
||||
|
||||
def initialize(project, now: Time.current)
|
||||
@project = project
|
||||
@@ -23,6 +24,31 @@ class Mailings::HourlyThroughput
|
||||
sent + failed
|
||||
end
|
||||
|
||||
def hourly_history
|
||||
@hourly_history ||= begin
|
||||
from = (@now - (HISTORY_HOURS - 1).hours).beginning_of_hour
|
||||
keyed = recipients.sent
|
||||
.where(sent_at: from..@now)
|
||||
.pluck(:sent_at)
|
||||
.each_with_object(Hash.new(0)) do |sent_at, counts|
|
||||
counts[sent_at.in_time_zone.beginning_of_hour] += 1
|
||||
end
|
||||
|
||||
HISTORY_HOURS.times.map do |index|
|
||||
at = from + index.hours
|
||||
{ at: at, count: keyed[at] || 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def history_total
|
||||
hourly_history.sum { |bucket| bucket[:count] }
|
||||
end
|
||||
|
||||
def history_max
|
||||
[hourly_history.map { |bucket| bucket[:count] }.max, 1].max
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sent_since(window)
|
||||
|
||||
Reference in New Issue
Block a user