Może się komuś przyda: https://github.com/sevos/kpi
Pomaga zdefiniować raport i wysyła go mailem.
Reszta - w readme
Może się komuś przyda: https://github.com/sevos/kpi
Pomaga zdefiniować raport i wysyła go mailem.
Reszta - w readme
Gem jest nieco zaktualizowany. Obecna wersja 0.5.3
Changelog:
[code=ruby] class DailyKpiReport < KPI::Report
def users_count
result “Users count”, User.count, :description => “Total users count”
end
def today_registrations_count
result "Today registrations count", User.where("created_at > ?", @time - 24.hours)
end
def total_income
result "Total income", Order.sum(:total), :unit => 'EUR'
end
def today_income
result "Today income", Order.where(:created_at => today).sum(:total), :unit => 'EUR'
end
private
def today
((time - 24.hours)..time)
end
end[/code]
[code=ruby] today = DailyKpiReport.new
yesterday = DailyKpiReport.new(:time => 1.day.ago)
before_yesterday = DailyKpiReport.new(:time => 2.days.ago)
avg = KPI::MergedReport.new(today, yesterday, before_yesterday) do |*entries|
average = entries.map(&:value).inject(:+).to_f / entries.size
KPI::Entry.new “$$ (avg)”, average, :description => “Average value of $$”
end
avg.today_income.name
avg.today_income.value
avg.today_income.description
avg.today_income.unit
Zapraszam do komentowania i rozwijania