[closes #16] days without commits are not ommited on date charts anymore

This commit is contained in:
Tomasz Gieniusz 2013-08-09 15:18:31 +02:00
parent 74761f8750
commit b5da25d52c
3 changed files with 22 additions and 6 deletions

View File

@ -6,4 +6,19 @@ class Hash
default = params[:default] default = params[:default]
inject(Array.new(min_size, default)) { |acc, (k, v)| acc[k] = v; acc }.map { |e| e || default } inject(Array.new(min_size, default)) { |acc, (k, v)| acc[k] = v; acc }.map { |e| e || default }
end end
def fill_empty_days!(params = {:aggregated => false})
return self if self.empty?
days_with_data = self.keys.map(&:to_date).sort.uniq
prev = 0
days_with_data.first.upto(days_with_data.last) do |day|
if days_with_data.include? day
prev = self[day]
else
self[day] = params[:aggregated] ? prev : 0
end
end
self
end
end end

View File

@ -50,17 +50,17 @@ module GitStats
def files_count_by_date def files_count_by_date
@files_count_each_day ||= Hash[commits.map { |commit| @files_count_each_day ||= Hash[commits.map { |commit|
[commit.date, commit.files_count] [commit.date.to_date, commit.files_count]
}] }].fill_empty_days!(aggregated: true)
end end
def lines_count_by_date def lines_count_by_date
sum = 0 sum = 0
Hash[commits.map { |commit| @lines_count_each_day ||= Hash[commits.map { |commit|
sum += commit.short_stat.insertions sum += commit.short_stat.insertions
sum -= commit.short_stat.deletions sum -= commit.short_stat.deletions
[commit.date, sum] [commit.date.to_date, sum]
}] }].fill_empty_days!(aggregated: true)
end end
def last_commit def last_commit

View File

@ -104,7 +104,7 @@ module GitStats
series( series(
name: params[:name], name: params[:name],
type: "spline", type: "spline",
data: params[:data].map { |date, value| [date.to_i * 1000, value] } data: Hash[params[:data]].fill_empty_days!.map { |date, value| [date.to_datetime.to_i * 1000, value] }.sort_by { |d| d[0] }
) )
end end
@ -113,6 +113,7 @@ module GitStats
type "column" type "column"
x_categories params[:data_x] x_categories params[:data_x]
end end
end end
end end
end end