Commit 63e50323 by Tấn Trần Thanh

show data for sheet raw task new

parent 8636b97c
Pipeline #1563 failed with stages
in 0 seconds
= workflow_report
Description goes here
class WorkflowReportController < ApplicationController
def index
@thead = ['root_id', 'project', 'subject', 'target_version', ' created_on ', ' closed_on ', ' due_date ', ' status ', ' Estimated_hours (*final version) ', 'Actual time', 'Diff', 'Estimated_hours (*Initial version)',
'Number of estimation changes', 'Note of estimation changes', '1. Requirement', '2. Design', '3. Coding', '4. Testing', '5. Bug fixing', '6. Release', 'Others', '1. Requirement', '2. Design', '3. Coding',
'4. Testing', '5. Bug fixing', '6. Release', 'Others', 'testcases', 'vn STG bug', 'Jp STG bug', 'Production', 'Issue', 'Issue comment', 'PR comment', 'Review comment', 'Commits', 'File changed', 'Addtion', 'Deletetion']
github = Github.new oauth_token: "your github token"
kuruma_project_ids = [139, 138, 94, 90, 93, 120, 128, 147, 121, 116]
@result = Array.new(@thead.length)
root_ids = Issue.select('issues.root_id')
.joins('INNER JOIN projects ON projects.id = issues.project_id')
.joins('LEFT OUTER JOIN time_entries ON issues.id = time_entries.issue_id')
.joins('INNER JOIN enabled_modules ON enabled_modules.project_id = projects.id')
.where('projects.status <> 9')
.where("projects.id IN (#{kuruma_project_ids.join(',')})")
.where(['enabled_modules.name = ? ', 'time_tracking'])
.where([
'((time_entries.spent_on IS NOT NULL AND time_entries.tyear = ? AND time_entries.tmonth = ?) OR (issues.closed_on BETWEEN ? AND ?))',
2023,
3,
DateTime.new(2023, 3).beginning_of_day,
DateTime.new(2023, 3, -1).end_of_day
])
.distinct.pluck(:root_id)
return unless root_ids.length > 0
sum_hours_records = Issue.select('issues.root_id, sum(time_entries.hours) as hours, max(IFNULL(c1.value,-1)) as testcases, max(IFNULL(c2.value,-1)) as bugs,max(IFNULL(stg.value,-1)) as stg_bugs, max(IFNULL(prod.value,-1)) as prod_bugs')
.joins('INNER JOIN time_entries ON issues.id = time_entries.issue_id')
.joins('LEFT OUTER JOIN custom_values c1 ON c1.customized_id = issues.id and c1.custom_field_id=22')
.joins('LEFT OUTER JOIN custom_values c2 ON c2.customized_id = issues.id and c2.custom_field_id=23')
.joins('LEFT OUTER JOIN custom_values stg ON stg.customized_id = issues.id and stg.custom_field_id=27')
.joins('LEFT OUTER JOIN custom_values prod ON prod.customized_id = issues.id and prod.custom_field_id=28')
.where("issues.root_id IN (#{root_ids.join(',')})")
.where('issues.tracker_id <> 1')
.group('issues.root_id')
raw_tasks_records = Issue.select('issues.root_id, issues.id, tracker_id, issues.subject, issues.due_date, issues.created_on, issues.closed_on, estimated_hours, issue_statuses.name as status, versions.name as target_version, projects.name as project, pr.value as pr, jr.value as jp_request')
.joins('INNER JOIN projects ON projects.id = issues.project_id')
.joins('INNER JOIN issue_statuses ON issue_statuses.id = issues.status_id')
.joins('LEFT JOIN versions ON issues.fixed_version_id = versions.id')
.joins('LEFT OUTER JOIN custom_values jr ON jr.customized_id = issues.id and jr.custom_field_id=16')
.joins('LEFT OUTER JOIN custom_values pr ON pr.customized_id = issues.id and pr.custom_field_id=18')
.where("issues.root_id IN (#{root_ids.join(',')})")
.where('issues.tracker_id <> 1')
.order('issues.root_id')
@result.map! { |item| item = [] }
raw_tasks_records.group_by(&:root_id).each do |root_id, record|
sum_hours_record = sum_hours_records.find { |hr| hr.root_id == root_id }
issue_ids = record.map(&:id)
journals = ActiveRecord::Base.connection.execute("select journalized_id, old_value, value, created_on, notes FROM journals
INNER JOIN journal_details ON journals.id = journal_id WHERE journalized_id IN (#{issue_ids.join(',')})
AND prop_key = 'estimated_hours' ORDER BY journalized_id, journals.id").to_a
@result[0] << root_id
@result[1] << record.first[:project].gsub(/[^[:print:]]/, '')
@result[2] << record.first[:subject].gsub(/[^[:print:]]/, '')
@result[3] << record.first[:target_version]
issue_created_on = record.min_by { |i| i[:created_on] if i[:created_on].present? }
if issue_created_on.present?
@result[4] << issue_created_on[:created_on]&.strftime('%Y-%m-%d %H:%M:%S')
else
@result[4] << nil
end
issue_closed_on = record.max_by { |i| i[:closed_on] if i[:closed_on].present? }
if issue_closed_on.present?
@result[5] << issue_closed_on[:closed_on]&.strftime('%Y-%m-%d %H:%M:%S')
else
@result[5] << nil
end
issue_due_dates = record.map(&:due_date).compact
issue_due_date = issue_due_dates.max_by { |a| a }
if issue_due_date.present?
@result[6] << issue_due_date&.strftime('%Y-%m-%d %H:%M:%S')
else
@result[6] << nil
end
@result[7] << record.first[:status]
sum_estimated_hours = record.map { |i| i[:estimated_hours] }.compact.sum
@result[8] << sum_estimated_hours
if sum_hours_record.present?
@result[9] << sum_hours_record[:hours]
@result[10] << (sum_hours_record[:hours] - sum_estimated_hours)
else
@result[9] << nil
@result[10] << nil
end
if journals.length > 0
number_of_est_changes = journals.count { |j| !j[1].nil? } || nil
est_changes = journals.reject { |j| j[1].nil? }.select { |e| e[4].present? }
notes = est_changes.inject("") { |all, i| all + i[4] + "\n" } || nil
original_est_hours = journals.group_by(&:shift).inject(0) { |sum, i| sum + i[1][0][1].to_f unless i.nil? }
@result[11] << original_est_hours
@result[12] << number_of_est_changes
@result[13] << notes
else
@result[11] << nil
@result[12] << nil
@result[13] << nil
end
pull_request = ''
jp_request = ''
record.each do |issue|
if issue.tracker_id == 12
pull_request = issue.pr
jp_request = issue.jp_request
end
process = get_process(issue.subject.gsub(/[^[:print:]]/, ''))
index_1 = 14 # first index for estimation detail
index_2 = 21 # first index for actual detail
case process
when '1. Requirement'
@result[index_1] << issue.estimated_hours if issue.estimated_hours.present?
@result[index_2] << +issue.spent_hours if issue.spent_hours > 0
when '2. Design'
@result[index_1 + 1] << issue.estimated_hours if issue.estimated_hours.present?
@result[index_2 + 1] << issue.spent_hours if issue.spent_hours > 0
when '3. Coding'
@result[index_1 + 2] << issue.estimated_hours if issue.estimated_hours.present?
@result[index_2 + 2] << issue.spent_hours if issue.spent_hours > 0
when '4. Testing'
@result[index_1 + 3] << issue.estimated_hours if issue.estimated_hours.present?
@result[index_2 + 3] << issue.spent_hours if issue.spent_hours > 0
when '5. Bug fixing'
@result[index_1 + 4] << issue.estimated_hours if issue.estimated_hours.present?
@result[index_2 + 4] << issue.spent_hours if issue.spent_hours > 0
when '6. Release'
@result[index_1 + 5] << issue.estimated_hours if issue.estimated_hours.present?
@result[index_2 + 5] << issue.spent_hours if issue.spent_hours > 0
else
if issue.estimated_hours.present?
# if @result[index_1+ 6 ].present? // recheck
# @result[index_1+ 6 ] << worksheet[row, index_1 + 6].to_f + issue.estimated_hours
# else
@result[index_1 + 6] << issue.estimated_hours
# end
end
if issue.spent_hours > 0
# if @result[index_2 + 6].present?
# @result[index_2 + 6] << worksheet[row, index_2 + 6].to_f + issue.spent_hours
# else
@result[index_2 + 6] << issue.spent_hours
# end
end
end
end
if sum_hours_record.nil?
# testcases
@result[28] << nil
# internal bug
@result[29] << nil
# stg bug
@result[30] << nil
# prod bug
@result[31] << nil
else
# testcases
@result[28] << sum_hours_record[:testcases] if sum_hours_record[:testcases].to_i >= 0
# internal bug
@result[29] << sum_hours_record[:bugs] if sum_hours_record[:bugs].to_i >= 0
# stg bug
@result[30] << sum_hours_record[:stg_bugs] if sum_hours_record[:stg_bugs].to_i >= 0
# prod bug
@result[31] << sum_hours_record[:prod_bugs] if sum_hours_record[:prod_bugs].to_i >= 0
if jp_request.present?
jp_request = jp_request.strip
@result[32] << jp_request
jp_request_arr = URI(jp_request).path.split('/').reject { |element| element.blank? }
next unless jp_request_arr.length == 4 && jp_request_arr[3].to_i > 0
issue_detail = github.issues.find user: jp_request_arr[0], repo: jp_request_arr[1], number: jp_request_arr[3]
@result[33] << issue_detail.comments if issue_detail.success?
end
# pr detail
if pull_request.present?
pr_comments = 0
pr_review_comments = 0
pr_commits = 0
pr_additions = 0
pr_deletions = 0
pr_changed_files = 0
prs = pull_request.split("\r\n").compact
prs.each do |link|
pr_link_arr = URI(link.strip).path.split('/').compact_blank
next unless pr_link_arr.length == 4
pr_detail = github.pull_requests.find user: pr_link_arr[0], repo: pr_link_arr[1], number: pr_link_arr[3]
if pr_detail.success?
pr_comments += pr_detail.comments
pr_review_comments += pr_detail.review_comments
pr_commits += pr_detail.commits
pr_additions += pr_detail.additions
pr_deletions += pr_detail.deletions
pr_changed_files += pr_detail.changed_files
end
@result[34] << pr_comments
@result[35] << pr_review_comments
@result[36] << pr_commits
@result[37] << pr_changed_files
@result[38] << pr_additions
@result[39] << pr_deletions
end
end
end
end
end
private
def get_process(subject)
name = ''
if !subject.nil? && index = subject.strip.index(' -')
subject = subject.strip
id = subject[0, 1]
name = subject[0, index]
if id.to_i != 0
if ["3. Code review"].include? name
name = "3. Coding"
elsif ["4. Create Test case"].include? name
name = "4. Testing"
else
name
end
else
if name.include? "Requirement"
name = "1. " + name
elsif name.include? "Design"
name = "2. " + name
elsif ["Coding", "Code review"].include? name
name = "3. Coding"
elsif ["Testing", "Create Test case"].include? name
name = "4. Testing"
elsif name.include? "Bug fixing"
name = "5. " + name
elsif name.include? "Release"
name = "6. " + name
end
end
end
name.strip
end
end
= stylesheet_link_tag 'style', plugin: 'workflow_report'
.table-container
table[border="1"]
tr
- @thead.each do |head|
th = head
- @result[0].each_with_index do |_root_id, index|
tr
- (0..(@thead.length - 1)).each do |i|
td = @result[i][index]
.table-container {
overflow-x: auto;
}
table {
table-layout: fixed;
border-collapse: collapse;
}
# English strings go here for Rails i18n
en:
# my_label: "My label"
# Plugin's routes
# See: http://guides.rubyonrails.org/routing.html
get 'workflow_report', to: 'workflow_report#index'
require 'redmine'
Rails.configuration.to_prepare do
require_dependency 'issue'
end
Redmine::Plugin.register :workflow_report do
name 'Workflow Report plugin'
author 'Author name'
description 'This is a plugin for Redmine'
version '0.0.1'
url 'http://example.com/path/to/plugin'
author_url 'http://example.com/about'
menu :top_menu, :workflow_report, { controller: 'workflow_report', action: 'index' }, caption: 'Workflow Report'
end
# Load the Redmine helper
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
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