Associating graphs display with the issues tab
This commit is contained in:
parent
bf61b20956
commit
263391e6ce
|
@ -2,213 +2,215 @@ require 'SVG/Graph/TimeSeries'
|
||||||
|
|
||||||
class GraphsController < ApplicationController
|
class GraphsController < ApplicationController
|
||||||
|
|
||||||
before_filter :find_version, :only => [:target_version_graph]
|
menu_item :issues, :only => [:issue_growth, :old_issues]
|
||||||
before_filter :find_open_issues, :only => [:old_issues, :issue_age_graph]
|
|
||||||
before_filter :find_optional_project, :only => [:issue_growth, :issue_growth_graph]
|
|
||||||
|
|
||||||
helper IssuesHelper
|
before_filter :find_version, :only => [:target_version_graph]
|
||||||
|
before_filter :find_open_issues, :only => [:old_issues, :issue_age_graph]
|
||||||
|
before_filter :find_optional_project, :only => [:issue_growth, :issue_growth_graph]
|
||||||
|
|
||||||
def issue_growth
|
helper IssuesHelper
|
||||||
end
|
|
||||||
|
|
||||||
# Displays projects by total issues over time
|
def issue_growth
|
||||||
def issue_growth_graph
|
end
|
||||||
|
|
||||||
# Initialize the graph
|
# Displays projects by total issues over time
|
||||||
graph = SVG::Graph::TimeSeries.new({
|
def issue_growth_graph
|
||||||
:area_fill => true,
|
|
||||||
:height => 300,
|
|
||||||
:min_y_value => 0,
|
|
||||||
:no_css => true,
|
|
||||||
:show_x_guidelines => true,
|
|
||||||
:scale_x_integers => true,
|
|
||||||
:scale_y_integers => true,
|
|
||||||
:show_data_points => false,
|
|
||||||
:show_data_values => false,
|
|
||||||
:stagger_x_labels => true,
|
|
||||||
:style_sheet => "/plugin_assets/redmine_graphs/stylesheets/issue_growth.css",
|
|
||||||
:timescale_divisions => "1 months",
|
|
||||||
:width => 720,
|
|
||||||
:x_label_format => "%b %Y"
|
|
||||||
})
|
|
||||||
|
|
||||||
# Get the top visible projects by issue count
|
# Initialize the graph
|
||||||
sql = "SELECT project_id, COUNT(*) as issue_count"
|
graph = SVG::Graph::TimeSeries.new({
|
||||||
sql << " FROM issues"
|
:area_fill => true,
|
||||||
sql << " LEFT JOIN #{Project.table_name} ON #{Issue.table_name}.project_id = #{Project.table_name}.id"
|
:height => 300,
|
||||||
sql << " WHERE (%s)" % Project.allowed_to_condition(User.current, :view_issues)
|
:min_y_value => 0,
|
||||||
sql << " AND (project_id = #{@project.id})" unless @project.nil?
|
:no_css => true,
|
||||||
sql << " GROUP BY project_id"
|
:show_x_guidelines => true,
|
||||||
sql << " ORDER BY issue_count DESC"
|
:scale_x_integers => true,
|
||||||
sql << " LIMIT 6"
|
:scale_y_integers => true,
|
||||||
top_projects = ActiveRecord::Base.connection.select_all(sql).collect { |p| p["project_id"] }
|
:show_data_points => false,
|
||||||
|
:show_data_values => false,
|
||||||
|
:stagger_x_labels => true,
|
||||||
|
:style_sheet => "/plugin_assets/redmine_graphs/stylesheets/issue_growth.css",
|
||||||
|
:timescale_divisions => "1 months",
|
||||||
|
:width => 720,
|
||||||
|
:x_label_format => "%b %Y"
|
||||||
|
})
|
||||||
|
|
||||||
# Get the issues created per project, per day
|
# Get the top visible projects by issue count
|
||||||
sql = "SELECT project_id, date(#{Issue.table_name}.created_on) as date, COUNT(*) as issue_count"
|
sql = "SELECT project_id, COUNT(*) as issue_count"
|
||||||
sql << " FROM #{Issue.table_name}"
|
sql << " FROM issues"
|
||||||
sql << " WHERE project_id IN (%s)" % top_projects.compact.join(',')
|
sql << " LEFT JOIN #{Project.table_name} ON #{Issue.table_name}.project_id = #{Project.table_name}.id"
|
||||||
sql << " GROUP BY project_id, date"
|
sql << " WHERE (%s)" % Project.allowed_to_condition(User.current, :view_issues)
|
||||||
issue_counts = ActiveRecord::Base.connection.select_all(sql).group_by { |c| c["project_id"] }
|
sql << " AND (project_id = #{@project.id})" unless @project.nil?
|
||||||
|
sql << " GROUP BY project_id"
|
||||||
|
sql << " ORDER BY issue_count DESC"
|
||||||
|
sql << " LIMIT 6"
|
||||||
|
top_projects = ActiveRecord::Base.connection.select_all(sql).collect { |p| p["project_id"] }
|
||||||
|
|
||||||
# Generate the created_on lines
|
# Get the issues created per project, per day
|
||||||
top_projects.each do |project_id, total_count|
|
sql = "SELECT project_id, date(#{Issue.table_name}.created_on) as date, COUNT(*) as issue_count"
|
||||||
counts = issue_counts[project_id].sort { |a,b| a["date"]<=>b["date"] }
|
sql << " FROM #{Issue.table_name}"
|
||||||
created_count = 0
|
sql << " WHERE project_id IN (%s)" % top_projects.compact.join(',')
|
||||||
created_on_line = Hash.new
|
sql << " GROUP BY project_id, date"
|
||||||
created_on_line[(Date.parse(counts.first["date"])-1).to_s] = 0
|
issue_counts = ActiveRecord::Base.connection.select_all(sql).group_by { |c| c["project_id"] }
|
||||||
counts.each { |count| created_count += count["issue_count"].to_i; created_on_line[count["date"]] = created_count }
|
|
||||||
created_on_line[Date.today.to_s] = created_count
|
|
||||||
graph.add_data({
|
|
||||||
:data => created_on_line.sort.flatten,
|
|
||||||
:title => Project.find(project_id).to_s
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
# Compile the graph
|
# Generate the created_on lines
|
||||||
headers["Content-Type"] = "image/svg+xml"
|
top_projects.each do |project_id, total_count|
|
||||||
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
|
counts = issue_counts[project_id].sort { |a,b| a["date"]<=>b["date"] }
|
||||||
end
|
created_count = 0
|
||||||
|
created_on_line = Hash.new
|
||||||
|
created_on_line[(Date.parse(counts.first["date"])-1).to_s] = 0
|
||||||
|
counts.each { |count| created_count += count["issue_count"].to_i; created_on_line[count["date"]] = created_count }
|
||||||
|
created_on_line[Date.today.to_s] = created_count
|
||||||
|
graph.add_data({
|
||||||
|
:data => created_on_line.sort.flatten,
|
||||||
|
:title => Project.find(project_id).to_s
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
def old_issues
|
# Compile the graph
|
||||||
@issues_by_created_on = @issues.sort {|a,b| a.created_on<=>b.created_on}
|
headers["Content-Type"] = "image/svg+xml"
|
||||||
@issues_by_updated_on = @issues.sort {|a,b| a.updated_on<=>b.updated_on}
|
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Displays issues by creation date, cumulatively
|
def old_issues
|
||||||
def issue_age_graph
|
@issues_by_created_on = @issues.sort {|a,b| a.created_on<=>b.created_on}
|
||||||
|
@issues_by_updated_on = @issues.sort {|a,b| a.updated_on<=>b.updated_on}
|
||||||
|
end
|
||||||
|
|
||||||
# Initialize the graph
|
# Displays issues by creation date, cumulatively
|
||||||
graph = SVG::Graph::TimeSeries.new({
|
def issue_age_graph
|
||||||
:area_fill => true,
|
|
||||||
:height => 300,
|
|
||||||
:min_y_value => 0,
|
|
||||||
:no_css => true,
|
|
||||||
:show_x_guidelines => true,
|
|
||||||
:scale_x_integers => true,
|
|
||||||
:scale_y_integers => true,
|
|
||||||
:show_data_points => false,
|
|
||||||
:show_data_values => false,
|
|
||||||
:stagger_x_labels => true,
|
|
||||||
:style_sheet => "/plugin_assets/redmine_graphs/stylesheets/issue_age.css",
|
|
||||||
:timescale_divisions => "1 weeks",
|
|
||||||
:width => 720,
|
|
||||||
:x_label_format => "%b %d"
|
|
||||||
})
|
|
||||||
|
|
||||||
# Group issues
|
# Initialize the graph
|
||||||
issues_by_created_on = @issues.group_by {|issue| issue.created_on.to_date }.sort
|
graph = SVG::Graph::TimeSeries.new({
|
||||||
issues_by_updated_on = @issues.group_by {|issue| issue.updated_on.to_date }.sort
|
:area_fill => true,
|
||||||
|
:height => 300,
|
||||||
|
:min_y_value => 0,
|
||||||
|
:no_css => true,
|
||||||
|
:show_x_guidelines => true,
|
||||||
|
:scale_x_integers => true,
|
||||||
|
:scale_y_integers => true,
|
||||||
|
:show_data_points => false,
|
||||||
|
:show_data_values => false,
|
||||||
|
:stagger_x_labels => true,
|
||||||
|
:style_sheet => "/plugin_assets/redmine_graphs/stylesheets/issue_age.css",
|
||||||
|
:timescale_divisions => "1 weeks",
|
||||||
|
:width => 720,
|
||||||
|
:x_label_format => "%b %d"
|
||||||
|
})
|
||||||
|
|
||||||
# Generate the created_on line
|
# Group issues
|
||||||
created_count = 0
|
issues_by_created_on = @issues.group_by {|issue| issue.created_on.to_date }.sort
|
||||||
created_on_line = Hash.new
|
issues_by_updated_on = @issues.group_by {|issue| issue.updated_on.to_date }.sort
|
||||||
issues_by_created_on.each { |created_on, issues| created_on_line[(created_on-1).to_s] = created_count; created_count += issues.size; created_on_line[created_on.to_s] = created_count }
|
|
||||||
created_on_line[Date.today.to_s] = created_count
|
|
||||||
graph.add_data({
|
|
||||||
:data => created_on_line.sort.flatten,
|
|
||||||
:title => l(:field_created_on)
|
|
||||||
})
|
|
||||||
|
|
||||||
# Generate the closed_on line
|
# Generate the created_on line
|
||||||
updated_count = 0
|
created_count = 0
|
||||||
updated_on_line = Hash.new
|
created_on_line = Hash.new
|
||||||
issues_by_updated_on.each { |updated_on, issues| updated_on_line[(updated_on-1).to_s] = updated_count; updated_count += issues.size; updated_on_line[updated_on.to_s] = updated_count }
|
issues_by_created_on.each { |created_on, issues| created_on_line[(created_on-1).to_s] = created_count; created_count += issues.size; created_on_line[created_on.to_s] = created_count }
|
||||||
updated_on_line[Date.today.to_s] = updated_count
|
created_on_line[Date.today.to_s] = created_count
|
||||||
graph.add_data({
|
graph.add_data({
|
||||||
:data => updated_on_line.sort.flatten,
|
:data => created_on_line.sort.flatten,
|
||||||
:title => l(:field_updated_on)
|
:title => l(:field_created_on)
|
||||||
})
|
})
|
||||||
|
|
||||||
# Compile the graph
|
# Generate the closed_on line
|
||||||
headers["Content-Type"] = "image/svg+xml"
|
updated_count = 0
|
||||||
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
|
updated_on_line = Hash.new
|
||||||
end
|
issues_by_updated_on.each { |updated_on, issues| updated_on_line[(updated_on-1).to_s] = updated_count; updated_count += issues.size; updated_on_line[updated_on.to_s] = updated_count }
|
||||||
|
updated_on_line[Date.today.to_s] = updated_count
|
||||||
|
graph.add_data({
|
||||||
|
:data => updated_on_line.sort.flatten,
|
||||||
|
:title => l(:field_updated_on)
|
||||||
|
})
|
||||||
|
|
||||||
# Displays open and total issue counts over time
|
# Compile the graph
|
||||||
def target_version_graph
|
headers["Content-Type"] = "image/svg+xml"
|
||||||
|
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
|
||||||
|
end
|
||||||
|
|
||||||
# Initialize the graph
|
# Displays open and total issue counts over time
|
||||||
graph = SVG::Graph::TimeSeries.new({
|
def target_version_graph
|
||||||
:area_fill => true,
|
|
||||||
:height => 300,
|
|
||||||
:no_css => true,
|
|
||||||
:show_x_guidelines => true,
|
|
||||||
:scale_x_integers => true,
|
|
||||||
:scale_y_integers => true,
|
|
||||||
:show_data_points => true,
|
|
||||||
:show_data_values => false,
|
|
||||||
:stagger_x_labels => true,
|
|
||||||
:style_sheet => "/plugin_assets/redmine_graphs/stylesheets/target_version.css",
|
|
||||||
:width => 800,
|
|
||||||
:x_label_format => "%b %d"
|
|
||||||
})
|
|
||||||
|
|
||||||
# Group issues
|
# Initialize the graph
|
||||||
issues_by_created_on = @version.fixed_issues.group_by {|issue| issue.created_on.to_date }.sort
|
graph = SVG::Graph::TimeSeries.new({
|
||||||
issues_by_updated_on = @version.fixed_issues.group_by {|issue| issue.updated_on.to_date }.sort
|
:area_fill => true,
|
||||||
issues_by_closed_on = @version.fixed_issues.collect { |issue| issue if issue.closed? }.compact.group_by {|issue| issue.updated_on.to_date }.sort
|
:height => 300,
|
||||||
|
:no_css => true,
|
||||||
|
:show_x_guidelines => true,
|
||||||
|
:scale_x_integers => true,
|
||||||
|
:scale_y_integers => true,
|
||||||
|
:show_data_points => true,
|
||||||
|
:show_data_values => false,
|
||||||
|
:stagger_x_labels => true,
|
||||||
|
:style_sheet => "/plugin_assets/redmine_graphs/stylesheets/target_version.css",
|
||||||
|
:width => 800,
|
||||||
|
:x_label_format => "%b %d"
|
||||||
|
})
|
||||||
|
|
||||||
# Set the scope of the graph
|
# Group issues
|
||||||
scope_end_date = issues_by_updated_on.keys.last
|
issues_by_created_on = @version.fixed_issues.group_by {|issue| issue.created_on.to_date }.sort
|
||||||
scope_end_date = @version.effective_date if !@version.effective_date.nil? && @version.effective_date > scope_end_date
|
issues_by_updated_on = @version.fixed_issues.group_by {|issue| issue.updated_on.to_date }.sort
|
||||||
scope_end_date = Date.today if !@version.completed?
|
issues_by_closed_on = @version.fixed_issues.collect { |issue| issue if issue.closed? }.compact.group_by {|issue| issue.updated_on.to_date }.sort
|
||||||
line_end_date = Date.today
|
|
||||||
line_end_date = scope_end_date if scope_end_date < line_end_date
|
|
||||||
|
|
||||||
# Generate the created_on line
|
# Set the scope of the graph
|
||||||
created_count = 0
|
scope_end_date = issues_by_updated_on.keys.last
|
||||||
created_on_line = Hash.new
|
scope_end_date = @version.effective_date if !@version.effective_date.nil? && @version.effective_date > scope_end_date
|
||||||
issues_by_created_on.each { |created_on, issues| created_on_line[(created_on-1).to_s] = created_count; created_count += issues.size; created_on_line[created_on.to_s] = created_count }
|
scope_end_date = Date.today if !@version.completed?
|
||||||
created_on_line[scope_end_date.to_s] = created_count
|
line_end_date = Date.today
|
||||||
graph.add_data({
|
line_end_date = scope_end_date if scope_end_date < line_end_date
|
||||||
:data => created_on_line.sort.flatten,
|
|
||||||
:title => l(:label_total).capitalize
|
|
||||||
})
|
|
||||||
|
|
||||||
# Generate the closed_on line
|
# Generate the created_on line
|
||||||
closed_count = 0
|
created_count = 0
|
||||||
closed_on_line = Hash.new
|
created_on_line = Hash.new
|
||||||
issues_by_closed_on.each { |closed_on, issues| closed_on_line[(closed_on-1).to_s] = closed_count; closed_count += issues.size; closed_on_line[closed_on.to_s] = closed_count }
|
issues_by_created_on.each { |created_on, issues| created_on_line[(created_on-1).to_s] = created_count; created_count += issues.size; created_on_line[created_on.to_s] = created_count }
|
||||||
closed_on_line[line_end_date.to_s] = closed_count
|
created_on_line[scope_end_date.to_s] = created_count
|
||||||
graph.add_data({
|
graph.add_data({
|
||||||
:data => closed_on_line.sort.flatten,
|
:data => created_on_line.sort.flatten,
|
||||||
:title => l(:label_closed_issues).capitalize
|
:title => l(:label_total).capitalize
|
||||||
})
|
})
|
||||||
|
|
||||||
# Add the version due date marker
|
# Generate the closed_on line
|
||||||
graph.add_data({
|
closed_count = 0
|
||||||
:data => [@version.effective_date.to_s, created_count],
|
closed_on_line = Hash.new
|
||||||
:title => l(:field_due_date).capitalize
|
issues_by_closed_on.each { |closed_on, issues| closed_on_line[(closed_on-1).to_s] = closed_count; closed_count += issues.size; closed_on_line[closed_on.to_s] = closed_count }
|
||||||
}) unless @version.effective_date.nil?
|
closed_on_line[line_end_date.to_s] = closed_count
|
||||||
|
graph.add_data({
|
||||||
|
:data => closed_on_line.sort.flatten,
|
||||||
|
:title => l(:label_closed_issues).capitalize
|
||||||
|
})
|
||||||
|
|
||||||
|
# Add the version due date marker
|
||||||
|
graph.add_data({
|
||||||
|
:data => [@version.effective_date.to_s, created_count],
|
||||||
|
:title => l(:field_due_date).capitalize
|
||||||
|
}) unless @version.effective_date.nil?
|
||||||
|
|
||||||
|
|
||||||
# Compile the graph
|
# Compile the graph
|
||||||
headers["Content-Type"] = "image/svg+xml"
|
headers["Content-Type"] = "image/svg+xml"
|
||||||
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
|
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_open_issues
|
def find_open_issues
|
||||||
find_optional_project
|
find_optional_project
|
||||||
@issues = Issue.visible.find(:all, :include => [:status], :conditions => ["#{IssueStatus.table_name}.is_closed=?", false]) if @project.nil?
|
@issues = Issue.visible.find(:all, :include => [:status], :conditions => ["#{IssueStatus.table_name}.is_closed=?", false]) if @project.nil?
|
||||||
@issues = @project.issues.collect { |issue| issue unless issue.closed? }.compact unless @project.nil?
|
@issues = @project.issues.collect { |issue| issue unless issue.closed? }.compact unless @project.nil?
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_optional_project
|
def find_optional_project
|
||||||
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
|
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
|
||||||
deny_access unless User.current.allowed_to?(:view_issues, @project, :global => true)
|
deny_access unless User.current.allowed_to?(:view_issues, @project, :global => true)
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_version
|
def find_version
|
||||||
@version = Version.find(params[:id])
|
@version = Version.find(params[:id])
|
||||||
deny_access unless User.current.allowed_to?(:view_issues, @version.project)
|
deny_access unless User.current.allowed_to?(:view_issues, @version.project)
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user