authors activity

This commit is contained in:
Tomasz Gieniusz 2012-10-21 20:05:12 +02:00
parent 81ad4e0e42
commit 56bfb8582e
10 changed files with 164 additions and 134 deletions

View File

@ -46,4 +46,7 @@ en:
lines_deleted: Lines deleted lines_deleted: Lines deleted
first_commit: First_commit first_commit: First_commit
last_commit: Last commit last_commit: Last commit
author: Author author: Author
show_more: Show more
close: Close
more_data_not_available: More data not available

View File

@ -2,63 +2,64 @@ module GitStats
module StatsView module StatsView
module Charts module Charts
class ActivityCharts class ActivityCharts
def initialize(activity) def initialize(repo)
@activity = activity @repo = repo
@activity = repo.activity
end end
def activity_by_date def activity_by_date(author)
Chart.new do |f| Chart.new do |f|
f.date_column_chart( f.date_column_chart(
data: @activity.by_date, data: author.activity.by_date,
title: :commits_by_date.t, title: :commits_by_date.t,
y_text: :commits.t y_text: :commits.t
) )
end end
end end
def activity_by_hour def activity_by_hour(author)
Chart.new do |f| Chart.new do |f|
f.simple_column_chart( f.simple_column_chart(
title: :commits_by_hour.t, title: :commits_by_hour.t,
y_text: :commits.t, y_text: :commits.t,
x_text: :hour.t, x_text: :hour.t,
data_x: (0..23), data_x: (0..23),
data_y: @activity.by_hour_array data_y: author.activity.by_hour_array
) )
end end
end end
def activity_by_wday def activity_by_wday(author)
Chart.new do |f| Chart.new do |f|
f.simple_column_chart( f.simple_column_chart(
title: :commits_by_wday.t, title: :commits_by_wday.t,
y_text: :commits.t, y_text: :commits.t,
x_text: :day.t, x_text: :day.t,
data_x: Date::ABBR_DAYNAMES, data_x: Date::ABBR_DAYNAMES,
data_y: @activity.by_wday_array data_y: author.activity.by_wday_array
) )
end end
end end
def activity_by_month def activity_by_month(author)
Chart.new do |f| Chart.new do |f|
f.simple_column_chart( f.simple_column_chart(
title: :commits_by_month.t, title: :commits_by_month.t,
y_text: :commits.t, y_text: :commits.t,
x_text: :month.t, x_text: :month.t,
data_x: Date::ABBR_MONTHNAMES[1..-1], data_x: Date::ABBR_MONTHNAMES[1..-1],
data_y: @activity.by_month_array data_y: author.activity.by_month_array
) )
end end
end end
def activity_by_year def activity_by_year(author)
Chart.new do |f| Chart.new do |f|
f.column_hash_chart( f.column_hash_chart(
title: :commits_by_year.t, title: :commits_by_year.t,
y_text: :commits.t, y_text: :commits.t,
x_text: :year.t, x_text: :year.t,
data: @activity.by_year data: author.activity.by_year
) )
end end
end end

View File

@ -25,7 +25,7 @@ module GitStats
end end
def activity_charts def activity_charts
@activity_charts ||= Charts::ActivityCharts.new(repo.activity) @activity_charts ||= Charts::ActivityCharts.new(repo)
end end
end end

View File

@ -1,14 +1,18 @@
module GitStats module GitStats
module StatsView module StatsView
class Template class Template
def initialize(name, layout) def initialize(name, layout=nil)
@name = name @name = name
@layout = layout @layout = layout
@template = Tilt.new("templates/#@name.haml") @template = Tilt.new("templates/#@name.haml")
end end
def render(data, all_templates) def render(data, params={})
@layout.render(data, :active_page => @name, :all_templates => all_templates) { @template.render(data) } if @layout
@layout.render(data, :active_page => @name, :all_templates => params[:all_templates]) { @template.render(data, params) }
else
@template.render(data, params)
end
end end
end end
end end

View File

@ -12,7 +12,7 @@ module GitStats
layout = Tilt.new("templates/layout.haml") layout = Tilt.new("templates/layout.haml")
all_templates.each do |template| all_templates.each do |template|
output = Template.new(template, layout).render(@view_data, all_templates) output = Template.new(template, layout).render(@view_data, all_templates: all_templates)
File.open("#@out_path/#{template}.html", 'w') { |f| f.write output } File.open("#@out_path/#{template}.html", 'w') { |f| f.write output }
end end
end end

View File

@ -13,6 +13,10 @@ module GitStats
@charts ||= Charts::All.new(repo) @charts ||= Charts::All.new(repo)
end end
def render(template_name, params = {})
Template.new(template_name).render(self, params)
end
end end
end end
end end

114
templates/_activity.haml Normal file
View File

@ -0,0 +1,114 @@
.tabbable.tabs-left
%ul.nav.nav-tabs
%li.active
%a{:href => "#activity_by_date-#{author.hash}", 'data-toogle' => 'tab'}= :activity_by_date.t
%li
%a{:href => "#hour_of_day-#{author.hash}", 'data-toogle' => 'tab'}= :hour_of_day.t
%li
%a{:href => "#day_of_week-#{author.hash}", 'data-toogle' => 'tab'}= :day_of_week.t
%li
%a{:href => "#hour_of_week-#{author.hash}", 'data-toogle' => 'tab'}= :hour_of_week.t
%li
%a{:href => "#month_of_year-#{author.hash}", 'data-toogle' => 'tab'}= :month_of_year.t
%li
%a{:href => "#year-#{author.hash}", 'data-toogle' => 'tab'}= :year.t
%li
%a{:href => "#year_month-#{author.hash}", 'data-toogle' => 'tab'}= :year_month.t
.tab-content
.tab-pane.active{id: "activity_by_date-#{author.hash}"}
.page-header
%h1.pagination-centered= :activity_by_date.t
= high_stock("charts.activity_by_date-#{author.hash}", charts.activity_by_date(author))
.tab-pane{id: "hour_of_day-#{author.hash}"}
.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
%th= :commits.t
- author.activity.by_hour_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- author.activity.by_hour_array.each do |commits|
%td= (commits * 100.0 / author.activity.by_hour_array.sum).round(1)
= high_chart("charts.activity_by_hour-#{author.hash}", charts.activity_by_hour(author))
.tab-pane{id: "day_of_week-#{author.hash}"}
.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
%th= :commits.t
- author.activity.by_wday_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- author.activity.by_wday_array.each do |commits|
%td= (commits * 100.0 / author.activity.by_wday_array.sum).round(1)
= high_chart("charts.activity_by_wday-#{author.hash}", charts.activity_by_wday(author))
.tab-pane{id: "hour_of_week-#{author.hash}"}
.page-header
%h1.pagination-centered= :hour_of_week.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th
- (0..23).each do |h|
%th= h
- (0..6).each do |day|
%tr
%th= Date::ABBR_DAYNAMES[day]
- (0..23).each do |hour|
%td= author.activity.by_wday_hour[day][hour]
.tab-pane{id: "month_of_year-#{author.hash}"}
.page-header
%h1.pagination-centered= :month_of_year.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th= :day.t
- Date::ABBR_MONTHNAMES[1..-1].each do |m|
%th= m
%tr
%th= :commits.t
- author.activity.by_month_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- author.activity.by_month_array.each do |commits|
%td= (commits * 100.0 / author.activity.by_month_array.sum).round(1)
= high_chart("charts.activity_by_month-#{author.hash}", charts.activity_by_month(author))
.tab-pane{id: "year-#{author.hash}"}
.page-header
%h1.pagination-centered= :year.t
= high_chart("charts.activity_by_year-#{author.hash}", charts.activity_by_year(author))
.tab-pane{id: "year_month-#{author.hash}"}
.page-header
%h1.pagination-centered= :year_month.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th
- Date::ABBR_MONTHNAMES[1..-1].each do |h|
%th= h
- author.activity.by_year_month.each do |year, months|
%tr
%th= year
- (1..12).each do |month|
%td= months[month]

View File

@ -1,113 +1 @@
.tabbable.tabs-left = render '_activity', author: repo
%ul.nav.nav-tabs
%li.active
%a{:href => '#activity_by_date', 'data-toogle' => 'tab'}= :activity_by_date.t
%li
%a{:href => '#hour_of_day', 'data-toogle' => 'tab'}= :hour_of_day.t
%li
%a{:href => '#day_of_week', 'data-toogle' => 'tab'}= :day_of_week.t
%li
%a{:href => '#hour_of_week', 'data-toogle' => 'tab'}= :hour_of_week.t
%li
%a{:href => '#month_of_year', 'data-toogle' => 'tab'}= :month_of_year.t
%li
%a{:href => '#year', 'data-toogle' => 'tab'}= :year.t
%li
%a{:href => '#year_month', 'data-toogle' => 'tab'}= :year_month.t
.tab-content
.tab-pane.active{id: 'activity_by_date'}
.page-header
%h1.pagination-centered= :activity_by_date.t
= high_stock("charts.activity_by_date", charts.activity_by_date)
.tab-pane{id: 'hour_of_day'}
.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
%th= :commits.t
- repo.activity.by_hour_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- repo.activity.by_hour_array.each do |commits|
%td= (commits * 100.0 / repo.activity.by_hour_array.sum).round(1)
= high_chart("charts.activity_by_hour", charts.activity_by_hour)
.tab-pane{id: 'day_of_week'}
.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
%th= :commits.t
- repo.activity.by_wday_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- repo.activity.by_wday_array.each do |commits|
%td= (commits * 100.0 / repo.activity.by_wday_array.sum).round(1)
= high_chart("charts.activity_by_wday", charts.activity_by_wday)
.tab-pane{id: 'hour_of_week'}
.page-header
%h1.pagination-centered= :hour_of_week.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th
- (0..23).each do |h|
%th= h
- (0..6).each do |day|
%tr
%th= Date::ABBR_DAYNAMES[day]
- (0..23).each do |hour|
%td= repo.activity.by_wday_hour[day][hour]
.tab-pane{id: 'month_of_year'}
.page-header
%h1.pagination-centered= :month_of_year.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th= :day.t
- Date::ABBR_MONTHNAMES[1..-1].each do |m|
%th= m
%tr
%th= :commits.t
- repo.activity.by_month_array.each do |commits|
%td= commits
%tr
%th= :percentage.t
- repo.activity.by_month_array.each do |commits|
%td= (commits * 100.0 / repo.activity.by_month_array.sum).round(1)
= high_chart("charts.activity_by_month", charts.activity_by_month)
.tab-pane{id: 'year'}
.page-header
%h1.pagination-centered= :year.t
= high_chart("charts.activity_by_year", charts.activity_by_year)
.tab-pane{id: 'year_month'}
.page-header
%h1.pagination-centered= :year_month.t
%table{:class => "table table-bordered table-condensed"}
%tr
%th
- Date::ABBR_MONTHNAMES[1..-1].each do |h|
%th= h
- repo.activity.by_year_month.each do |year, months|
%tr
%th= year
- (1..12).each do |month|
%td= months[month]

View File

@ -27,7 +27,9 @@
%th= :lines_deleted.t %th= :lines_deleted.t
%th= :first_commit.t %th= :first_commit.t
%th= :last_commit.t %th= :last_commit.t
- repo.authors.sort_by { |a| -a.commits.size}.each do |author| %th
- sorted_authors = repo.authors.sort_by { |a| -a.commits.size}
- sorted_authors.each_with_index do |author, i|
%tr %tr
%th= author.name %th= author.name
%td= author.commits.size %td= author.commits.size
@ -35,6 +37,19 @@
%td= author.lines_deleted %td= author.lines_deleted
%td= author.commits.first.try(:date).try(:to_formatted_s, :long) %td= author.commits.first.try(:date).try(:to_formatted_s, :long)
%td= author.commits.last.try(:date).try(:to_formatted_s, :long) %td= author.commits.last.try(:date).try(:to_formatted_s, :long)
%td
- if i <= 4
%a.btn{:href => "##{author.hash}-modal", :role => "button", 'data-toggle'=>"modal"}= :show_more.t
- else
= :more_data_not_available.t
- sorted_authors[0..4].each do |author|
.modal.hide{:id => "#{author.hash}-modal", :role => "dialog", :style => "width: 1140px; margin-left:-570px; top: 30%;"}
.modal-header
%h1.pagination-centered= "#{author.name} <#{author.email}>"
.modal-body{:style => "height: 650px; max-height: 800px;"}
= render '_activity', author: author
.modal-footer
%a.btn{'data-dismiss' => "modal"}= :close.t
.tab-pane{id: 'commits_count_by_author'} .tab-pane{id: 'commits_count_by_author'}
.page-header .page-header

View File

@ -17,8 +17,9 @@
$('.tabbable ul a').click(function (e) { $('.tabbable ul a').click(function (e) {
e.preventDefault(); e.preventDefault();
$(this).tab('show'); $(this).tab('show');
$(document.body).trigger('load'); });
}) $('.modal').on('shown', function (e) {
});
}); });
%body %body
%div.navbar.navbar-fixed-top %div.navbar.navbar-fixed-top