mirror of
https://github.com/tomgi/git_stats.git
synced 2024-09-28 11:41:29 +02:00
day of week chart
This commit is contained in:
parent
4a590ddd40
commit
628b650e2f
@ -18,3 +18,6 @@ en:
|
||||
lines_by_extension: Lines by extension
|
||||
hour_of_day: Hour of day
|
||||
hour: Hour
|
||||
percentage: Percentage
|
||||
day: Day
|
||||
day_of_week: Day of week
|
@ -1,6 +1,8 @@
|
||||
class Hash
|
||||
def to_key_indexed_array
|
||||
def to_key_indexed_array(params = {})
|
||||
raise ArgumentError.new('all the keys must be numbers to convert to key indexed array') unless all? { |k, v| k.is_a? Numeric }
|
||||
inject([]) { |acc, (k, v)| acc[k] = v; acc }
|
||||
min_size = params[:min_size] || 0
|
||||
default = params[:default]
|
||||
inject(Array.new(min_size, default)) { |acc, (k, v)| acc[k] = v; acc }.map { |e| e || default }
|
||||
end
|
||||
end
|
@ -10,10 +10,18 @@ module GitStats
|
||||
@by_hour ||= default_hash
|
||||
end
|
||||
|
||||
def by_hour_array
|
||||
by_hour.to_key_indexed_array(min_size: 24, default: 0)
|
||||
end
|
||||
|
||||
def by_wday
|
||||
@by_wday ||= default_hash
|
||||
end
|
||||
|
||||
def by_wday_array
|
||||
by_wday.to_key_indexed_array(min_size: 7, default: 0)
|
||||
end
|
||||
|
||||
def by_wday_hour
|
||||
@by_wday_hour ||= default_double_hash
|
||||
end
|
||||
|
@ -13,7 +13,19 @@ module GitStats
|
||||
y_text: :commits.t,
|
||||
x_text: :hour.t,
|
||||
data_x: (0..23),
|
||||
data_y: @activity.by_hour.to_key_indexed_array
|
||||
data_y: @activity.by_hour_array
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def activity_by_wday
|
||||
Chart.new do |f|
|
||||
f.simple_column_chart(
|
||||
title: :commits_by_wday.t,
|
||||
y_text: :commits.t,
|
||||
x_text: :day.t,
|
||||
data_x: Date::ABBR_DAYNAMES,
|
||||
data_y: @activity.by_wday_array
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module GitStats
|
||||
delegate :files_by_extension, :lines_by_extension, :files_by_date, :lines_by_date,
|
||||
:lines_added_by_author, :lines_deleted_by_author, to: :repo_charts
|
||||
delegate :by_authors_wday, to: :authors_charts
|
||||
delegate :activity_by_hour, to: :activity_charts
|
||||
delegate :activity_by_hour, :activity_by_wday, to: :activity_charts
|
||||
|
||||
attr_reader :repo
|
||||
|
||||
|
@ -11,5 +11,15 @@ describe Hash do
|
||||
hash = {1 => 'x', 'b' => 2}
|
||||
expect { hash.to_key_indexed_array }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
context 'should take optional min_size and default parameters' do
|
||||
let(:hash) { {1 => 'x', 2 => 1, 5 => 'a'} }
|
||||
it 'should fill array with defaults up to min_size' do
|
||||
hash.to_key_indexed_array(min_size: 8, default: 0).should == [0, 'x', 1, 0, 0, 'a', 0, 0]
|
||||
end
|
||||
it 'should use default value where key is not in hash' do
|
||||
hash.to_key_indexed_array(min_size: 2, default: 0).should == [0, 'x', 1, 0, 0, 'a']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,3 +1,34 @@
|
||||
.page-header
|
||||
%h1.pagination-centered= :hour_of_day.t
|
||||
%table{:class => "table table-bordered table-condensed"}
|
||||
%tr
|
||||
%th= :hour.t
|
||||
- (0..23).each do |h|
|
||||
%th= h
|
||||
%tr
|
||||
%td= :commits.t
|
||||
- repo.activity.by_hour_array.each do |commits|
|
||||
%td= commits
|
||||
%tr
|
||||
%td= :percentage.t
|
||||
- repo.activity.by_hour_array.each do |commits|
|
||||
%td= (commits * 100.0 / repo.activity.by_hour_array.sum).round(2)
|
||||
= high_chart("activity_by_hour", charts.activity_by_hour)
|
||||
|
||||
|
||||
.page-header
|
||||
%h1.pagination-centered= :day_of_week.t
|
||||
%table{:class => "table table-bordered table-condensed"}
|
||||
%tr
|
||||
%th= :day.t
|
||||
- Date::ABBR_DAYNAMES.each do |d|
|
||||
%th= d
|
||||
%tr
|
||||
%td= :commits.t
|
||||
- repo.activity.by_wday_array.each do |commits|
|
||||
%td= commits
|
||||
%tr
|
||||
%td= :percentage.t
|
||||
- repo.activity.by_wday_array.each do |commits|
|
||||
%td= (commits * 100.0 / repo.activity.by_wday_array.sum).round(2)
|
||||
= high_chart("activity_by_wday", charts.activity_by_wday)
|
Loading…
Reference in New Issue
Block a user