diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-05 14:41:02 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-05 14:41:02 +0300 |
commit | 4b74c55b1572da19d78fa6982edf54916d09eec3 (patch) | |
tree | 8acbf6788fca6b8f7f31f51c43ad9556dc74e09b /lib | |
parent | 22005da2377275e3a80d37bfa689e474869b645a (diff) | |
download | gitlab-ci-4b74c55b1572da19d78fa6982edf54916d09eec3.tar.gz |
More charts. Correct routes to actual page names
Diffstat (limited to 'lib')
-rw-r--r-- | lib/charts.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/charts.rb b/lib/charts.rb new file mode 100644 index 0000000..45ad22e --- /dev/null +++ b/lib/charts.rb @@ -0,0 +1,54 @@ +module Charts + class Chart + attr_reader :labels, :total, :success, :project + + def initialize(project) + @labels = [] + @total = [] + @success = [] + @project = project + + collect + end + + + def push(from, to, format) + @labels << from.strftime(format) + @total << project.builds.where("? > created_at AND created_at > ?", to, from).count + @success << project.builds.where("? > created_at AND created_at > ?", to, from).success.count + end + end + + class YearChart < Chart + def collect + 13.times do |i| + start_month = (Date.today.years_ago(1) + i.month).beginning_of_month + end_month = start_month.end_of_month + + push(start_month, end_month, "%d %B %Y") + end + end + end + + class MonthChart < Chart + def collect + 30.times do |i| + start_day = Date.today - 30.days + i.days + end_day = Date.today - 30.days + i.day + 1.day + + push(start_day, end_day, "%d %B") + end + end + end + + class WeekChart < Chart + def collect + 7.times do |i| + start_day = Date.today - 7.days + i.days + end_day = Date.today - 7.days + i.day + 1.day + + push(start_day, end_day, "%d %B") + end + end + end +end |