BigW Consortium Gitlab

Commit 91d30c90 by Dmitriy Zaporozhets

Merge branch 'refactor-graphs' into 'master'

Improving graphs: add new commits graphs page This MR adds new page to graphs sections with commits statistic ![Screenshot 2014-09-26 20.32.01](https://dev.gitlab.org/uploads/dzaporozhets/gitlabhq/61fd84c4d6/Screenshot_2014-09-26_20.32.01.png) See merge request !1124
parents 477214cd 83a21c33
......@@ -22,6 +22,7 @@
#= require raphael
#= require g.raphael-min
#= require g.bar-min
#= require chart-lib.min
#= require branch-graph
#= require highlight.pack
#= require ace/ace
......
@Chart =
labels: []
values: []
init: (labels, values, title) ->
r = Raphael('activity-chart')
fin = ->
@flag = r.popup(@bar.x, @bar.y, @bar.value or "0").insertBefore(this)
fout = ->
@flag.animate
opacity: 0, 300, -> @remove()
r.text(160, 10, title).attr font: "13px sans-serif"
r.barchart(
10, 20, 560, 200,
[values],
{colors:["#456"]}
).label(labels, true)
.hover(fin, fout)
......@@ -13,6 +13,14 @@ class Projects::GraphsController < Projects::ApplicationController
end
end
def commits
@commits = @project.repository.commits(nil, nil, 2000, 0, true)
@commits_graph = Gitlab::Graphs::Commits.new(@commits)
@commits_per_week_days = @commits_graph.commits_per_week_days
@commits_per_time = @commits_graph.commits_per_time
@commits_per_month = @commits_graph.commits_per_month
end
private
def fetch_graph
......
%ul.nav.nav-tabs
= nav_link(action: :show) do
= link_to 'Contributors', project_graph_path
= nav_link(action: :commits) do
= link_to 'Commits', commits_project_graph_path
= render 'head'
%p.lead
Commits statistic for
%strong #{@repository.root_ref}
#{@commits_graph.start_date.strftime('%b %d')} - #{@commits_graph.end_date.strftime('%b %d')}
.row
.col-md-6
%ul
%li
%p.lead
%strong #{@commits_graph.commits.size}
commits during
%strong #{@commits_graph.duration}
days
%li
%p.lead
Average
%strong #{@commits_graph.commit_per_day}
commits per day
%li
%p.lead
Contributed by
%strong #{@commits_graph.authors}
authors
.col-md-6
%div
%p.slead
Commits per day of month
%canvas#month-chart{width: 800, height: 400}
.row
.col-md-6
%div
%p.slead
Commits per day hour (UTC)
%canvas#hour-chart{width: 800, height: 400}
.col-md-6
%div
%p.slead
Commits per weekday
%canvas#weekday-chart{width: 800, height: 400}
:coffeescript
data = {
labels : #{@commits_per_time.keys.to_json},
datasets : [{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#EEE",
data : #{@commits_per_time.values.to_json}
}]
}
ctx = $("#hour-chart").get(0).getContext("2d");
new Chart(ctx).Line(data,{"scaleOverlay": true, responsive: true});
data = {
labels : #{@commits_per_week_days.keys.to_json},
datasets : [{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#EEE",
data : #{@commits_per_week_days.values.to_json}
}]
}
ctx = $("#weekday-chart").get(0).getContext("2d");
new Chart(ctx).Line(data,{"scaleOverlay": true, responsive: true});
data = {
labels : #{@commits_per_month.keys.to_json},
datasets : [{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#EEE",
data : #{@commits_per_month.values.to_json}
}]
}
ctx = $("#month-chart").get(0).getContext("2d");
new Chart(ctx).Line(data,{"scaleOverlay": true, responsive: true});
= render 'head'
.loading-graph
.center
%h3.page-title
......
......@@ -206,7 +206,11 @@ Gitlab::Application.routes.draw do
resources :compare, only: [:index, :create]
resources :blame, only: [:show], constraints: {id: /.+/}
resources :network, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/}
resources :graphs, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/}
resources :graphs, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/} do
member do
get :commits
end
end
match "/compare/:from...:to" => "compare#show", as: "compare", via: [:get, :post], constraints: {from: /.+/, to: /.+/}
......
......@@ -2,8 +2,13 @@ Feature: Project Graph
Background:
Given I sign in as a user
And I own project "Shop"
And I visit project "Shop" graph page
@javascript
Scenario: I should see project graphs
When I visit project "Shop" graph page
Then page should have graphs
@javascript
Scenario: I should see project commits graphs
When I visit project "Shop" commits graph page
Then page should have commits graphs
......@@ -10,4 +10,14 @@ class Spinach::Features::ProjectGraph < Spinach::FeatureSteps
project = Project.find_by(name: "Shop")
visit project_graph_path(project, "master")
end
step 'I visit project "Shop" commits graph page' do
project = Project.find_by(name: "Shop")
visit commits_project_graph_path(project, "master")
end
step 'page should have commits graphs' do
page.should have_content "Commits statistic for master"
page.should have_content "Commits per day of month"
end
end
module Gitlab
module Graphs
class Commits
attr_reader :commits, :start_date, :end_date, :duration,
:commits_per_week_days, :commits_per_time, :commits_per_month
def initialize(commits)
@commits = commits
@start_date = commits.last.committed_date.to_date
@end_date = commits.first.committed_date.to_date
@duration = (@end_date - @start_date).to_i
collect_data
end
def authors
@authors ||= @commits.map(&:author_email).uniq.size
end
def commit_per_day
@commit_per_day ||= (@commits.size.to_f / @duration).round(1)
end
def collect_data
@commits_per_week_days = {}
Date::DAYNAMES.each { |day| @commits_per_week_days[day] = 0 }
@commits_per_time = {}
(0..23).to_a.each { |hour| @commits_per_time[hour] = 0 }
@commits_per_month = {}
(1..31).to_a.each { |day| @commits_per_month[day] = 0 }
@commits.each do |commit|
hour = commit.committed_date.strftime('%k').to_i
day_of_month = commit.committed_date.strftime('%e').to_i
weekday = commit.committed_date.strftime('%A')
@commits_per_week_days[weekday] ||= 0
@commits_per_week_days[weekday] += 1
@commits_per_time[hour] ||= 0
@commits_per_time[hour] += 1
@commits_per_month[day_of_month] ||= 0
@commits_per_month[day_of_month] += 1
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment