Commit 1735d895 by Tấn Trần Thanh

50% for coding

parent 679e4d78
......@@ -45,9 +45,9 @@ class WorkflowReportController < ApplicationController
def export
team = params[:team]
project_ids = $workflow_report_config['teams'].select { |hash| hash.key?(team) }[0][team]
result = Rails.cache.fetch("#{team}_#{params[:year]}_#{params[:month]}", expires_in: 1.hours) do
WorkflowReport.build_report(params[:year].to_i, params[:month].to_i, project_ids)
end
# result = Rails.cache.fetch("#{team}_#{params[:year]}_#{params[:month]}", expires_in: 1.hours) do
result= WorkflowReport.build_report(params[:year].to_i, params[:month].to_i, project_ids)
#end
respond_to do |format|
format.js { render 'build_table', locals: { result: result[:workflow_report], error_links: result[:error_links], thead: TABLE_HEADER } }
end
......
class WorkflowReportCustomValue < CustomValue
belongs_to :workflow_report_issue, class_name: 'WorkflowReportCustomValue', foreign_key: 'custom_field_id'
end
......@@ -6,14 +6,17 @@ class WorkflowReportIssue < Issue
PR_FIELD_ID = 18
JP_REQUEST_FIELD_ID = 16
belongs_to :workflow_report_version, class_name: 'Version', foreign_key: 'fixed_version_id'
has_many :workflow_report_custom_values, class_name: 'WorkflowReportCustomValue', foreign_key: 'customized_id'
scope :find_root_ids, ->(year, month, project_ids) {
joins(:project, project: :enabled_modules)
.joins('LEFT OUTER JOIN time_entries ON issues.id = time_entries.issue_id')
.where.not(projects: { status: 9 })
includes(:project, :workflow_report_version, :workflow_report_custom_values, :time_entries, :status, project: :enabled_modules)
.where.not(projects: { status: 9 }, issues: { tracker_id: 1 })
.where(root_id: 59050)
.where(projects: { id: project_ids }, 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 ?))',
year, month, DateTime.new(year, month).beginning_of_day, DateTime.new(year, month, -1).end_of_day])
.distinct.pluck(:root_id)
.order(:root_id)
}
scope :find_sum_hours_records, ->(root_ids) {
......
class WorkflowReportVersion < Version
has_many :workflow_report_issues, foreign_key: 'fixed_version_id'
end
......@@ -13,24 +13,23 @@ module WorkflowReport
github = Github.new oauth_token: $workflow_report_config['github_token']
error_links = []
result = TABLE_HEADER.length.times.map { [] }
root_ids = WorkflowReportIssue.find_root_ids(year, month, project_ids)
return { workflow_report: [], error_links: [] } if root_ids.empty?
raw_tasks = WorkflowReportIssue.find_root_ids(year, month, project_ids)
return { workflow_report: [], error_links: [] } if raw_tasks.empty?
sum_hours_records = WorkflowReportIssue.find_sum_hours_records(root_ids)
raw_tasks = WorkflowReportIssue.raw_tasks_records(root_ids)
# sum_hours_records = WorkflowReportIssue.find_sum_hours_records(root_ids)
# raw_tasks = WorkflowReportIssue.raw_tasks_records(root_ids)
raw_tasks.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)
sum_hours_record = record.first.time_entries.all
journals = WorkflowReportJournal.find_journal_by_issue_ids(issue_ids).to_a
result[0] << root_id
result[1] << record.first[:project].gsub(/[^[:print:]]/, '')
result[1] << record.first.project.name.gsub(/[^[:print:]]/, '')
result[2] << record.first[:subject].gsub(/[^[:print:]]/, '')
result[3] << record.first[:target_version]
result[3] << record.first.workflow_report_version.name
issue_created_on = record.min_by { |i| i[:created_on] if i[:created_on].present? }
result[4].push(issue_created_on.present? ? issue_created_on[:created_on]&.strftime('%Y-%m-%d %H:%M:%S') : '')
result[4].push(issue_created_on.present? ? issue_created_on.created_on&.strftime('%Y-%m-%d %H:%M:%S') : '')
closed_on_issues = record.map(&:closed_on).compact
issue_closed_on = closed_on_issues.max_by { |close_on| close_on }
result[5].push(issue_closed_on.present? ? issue_closed_on.strftime('%Y-%m-%d %H:%M:%S') : '')
......@@ -39,12 +38,13 @@ module WorkflowReport
issue_due_date = issue_due_dates.max_by { |due_date| due_date }
result[6].push(issue_due_date.present? ? issue_due_date&.strftime('%Y-%m-%d %H:%M:%S') : '')
result[7].push(record.first[:status].present? ? record.first[:status] : '')
sum_estimated_hours = record.map { |i| i[:estimated_hours] }.compact.sum
result[7].push(record.first.status.name.present? ? record.first.status.name : '')
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)
actual_time = record.map { |item| item.time_entries.all.map(&:hours).sum }.sum
if actual_time.present?
result[9] << actual_time
result[10] << (actual_time - sum_estimated_hours)
else
result[9] << ''
result[10] << ''
......@@ -62,10 +62,14 @@ module WorkflowReport
end
pull_request = ''
jp_request = ''
test_case = 0
staging_bug = 0
jp_bug = 0
proc_bug = 0
record.each do |issue|
if issue.tracker_id == 12
pull_request = issue.pr
jp_request = issue.jp_request
pull_request = issue.custom_values.find_by(custom_field_id: 18).value
jp_request = issue.custom_values.find_by(custom_field_id: 16).value
end
process = get_process(issue.subject.gsub(/[^[:print:]]/, ''))
......@@ -83,15 +87,20 @@ module WorkflowReport
build_est_to_actual_time!(result, EST_DETAIL_FIRST_COL, issue.estimated_hours.to_f, 6)
build_est_to_actual_time!(result, ACTUAL_TIME_DETAIL_FIRST_COL, issue.spent_hours.to_f, 6)
end
test = issue.custom_values.where(custom_field_id: 22)
end
if sum_hours_record.nil?
# testcases, internal bug, stg bug, prod bug
(28..31).each { |i| result[i] << '' }
else
byebug
a=record.select{|item| p item.custom_values.where('custom_field_id= 22').length != 0}
# testcases, internal bug, stg bug, prod bug
BUGS.each do |status, column|
result[column].push(sum_hours_record[status].to_i >= 0 ? sum_hours_record[status] : '')
end
# BUGS.each do |status, column|
# rs = record.map { |item| item.time_entries.all.map(&:hours).sum }.sum
# result[column].push(sum_hours_record[status].to_i >= 0 ? sum_hours_record[status] : '')
# end
end
if jp_request.present?
jp_request = jp_request.strip
......@@ -111,7 +120,7 @@ module WorkflowReport
result[33] << ''
end
# pr detail
pr = { pr_comments: 0, pr_review_comments: 0, pr_commits: 0, pr_additions: 0, pr_deletions: 0, pr_changed_files: 0 }
pr = { pr_comments: 0, pr_review_comments: 0, pr_commits: 0, pr_changed_files: 0, pr_additions: 0, pr_deletions: 0 }
if pull_request.present?
prs = pull_request.split("\r\n").compact
......@@ -125,9 +134,9 @@ module WorkflowReport
pr[:pr_comments] += pr_detail.comments
pr[:pr_review_comments] += pr_detail.review_comments
pr[:pr_commits] += pr_detail.commits
pr[:pr_changed_files] += pr_detail.changed_files
pr[:pr_additions] += pr_detail.additions
pr[:pr_deletions] += pr_detail.deletions
pr[:pr_changed_files] += pr_detail.changed_files
end
rescue => e
error_links << "##{root_id} Error occurred during the build with the PR link:\r\n - #{link} \r\n - #{e.message.gsub(/(?<=access_token=).*/, '123')}"
......
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