Period distribution, that is, the proportion of the two time differences.
The more commonly used ones are:
Defect repair cycle = repair time-creation time
Defect verification cycle = verification time-repair time
Defect lifetime = closing time-creation time
Therefore, you only need to find out the time to be counted, then calculate the time difference, and then count the number according to the time difference to get the period proportion
One, realize
1. Database statistics
It can be seen from the above time difference calculation formula that time covers the entire defect life cycle
So we can get the time from the resolved defect table jira_resolution_issues (the statistical period of unresolved defects may not be accurate, although closed defects can also be reopened, but it is relatively reliable)
For example, the defect life cycle can be written like this
2. Realization of life cycle distribution
For data with an inventory period greater than or equal to 7 days, we merge, because the defects survive for more than 7 days, we think they are all unqualified, and the data does not seem too messy
def cake_cycle(self):
"""
存活周期 TIMESTAMPDIFF(DAY,DATE_FORMAT(created,'%Y-%m-%d'),DATE_FORMAT(resolutiondate,'%Y-%m-%d')) AS date_diff
:return:
"""
sql = """
SELECT A.date_diff,COUNT(A.date_diff) AS counts
from
(
SELECT
project,
TIMESTAMPDIFF(DAY,DATE_FORMAT(created,'%Y-%m-%d'),DATE_FORMAT(resolutiondate,'%Y-%m-%d')) AS date_diff
FROM
jira_resolution_issues
WHERE
project='{}' AND issuetype='故障' AND repair_date IS NOT NULL
) A
GROUP BY
A.project,
A.date_diff
ORDER BY A.date_diff;
""".format(self.project_name)
datas = MysqlUntil().mysql_select(sql)
# 开发人员以及各严重等级BUG数量
date_diff, counts, k = [], [], 0
for data in datas:
if data['date_diff'] >= 7:
k += int(data['counts'])
if '>=7 天' not in date_diff:
date_diff.append('>=7 Day')
else:
date_diff.append(str(data['date_diff']) + ' Day')
counts.append(int(data['counts']))
counts.append(k)
if sum(counts) > 0:
Draw(self.report_path).drawing_cake(counts, date_diff, self.project_name,
' Issues Survive Cycle Distribution (ALL CYCLE)')
print('项目{}最近{}周缺陷存活周期占比分布图统计完成'.format(self.project_name, self.weeks))
else:
print('项目{}最近{}周未验证缺陷,无法统计存活周期占比分布图'.format(self.project_name, self.weeks))
3. Execution statistics
cake_cycle()
Two, optimization
1. Optimize ideas
The survival cycle distribution statistics are completed, followed by the repair cycle and the verification cycle
However, we can find that the three periodic distributions have one thing in common, that is, they are all seeking the time difference between the two dates, and then looking at the proportion according to the number
In this case, we can reuse the method of life cycle, only need to modify slightly
We pass in the time that needs to be calculated in the form of parameters, so the survival period, repair period, and verification period distribution are all available, and other period distributions can also be expanded, such as review period
def cake_cycle(self, date_early, date_late):
"""
存活周期 TIMESTAMPDIFF(DAY,DATE_FORMAT(created,'%Y-%m-%d'),DATE_FORMAT(resolutiondate,'%Y-%m-%d')) AS date_diff
修复周期 TIMESTAMPDIFF(DAY,DATE_FORMAT(created,'%Y-%m-%d'),DATE_FORMAT(repair_date,'%Y-%m-%d')) AS date_diff
验证周期 TIMESTAMPDIFF(DAY,DATE_FORMAT(repair_date,'%Y-%m-%d'),DATE_FORMAT(verify_date,'%Y-%m-%d')) AS date_diff
:return:
"""
sql = """
SELECT A.date_diff,COUNT(A.date_diff) AS counts
from
(
SELECT
project,
TIMESTAMPDIFF(DAY,DATE_FORMAT({date_early},'%Y-%m-%d'),DATE_FORMAT({date_late},'%Y-%m-%d')) AS date_diff
FROM
jira_resolution_issues
WHERE
project='{project_name}' AND issuetype='故障'
) A
GROUP BY
A.project,
A.date_diff
HAVING A.date_diff <> ''
ORDER BY A.date_diff;
""".format(date_early=date_early, date_late=date_late, project_name=self.project_name)
print(sql)
datas = MysqlUntil().mysql_select(sql)
print(datas)
# 开发人员以及各严重等级BUG数量
date_diff, counts, k = [], [], 0
for data in datas:
if data['date_diff'] >= 7:
k += int(data['counts'])
if '>=7 天' not in date_diff:
date_diff.append('>=7 Day')
else:
date_diff.append(str(data['date_diff']) + ' Day')
counts.append(int(data['counts']))
counts.append(k)
if sum(counts) > 0:
Draw(self.report_path).drawing_cake(counts, date_diff, self.project_name,
' Issues Cycle Distribution (ALL CYCLE)')
print('项目{}最近{}周缺陷存活周期占比分布图统计完成'.format(self.project_name, self.weeks))
else:
print('项目{}最近{}周未验证缺陷,无法统计存活周期占比分布图'.format(self.project_name, self.weeks))
2. Execution statistics
c = Cake(project_name, test_jira, first_day, last_day, types, weeks, project_report_path)
c.cake_cycle('created', 'resolutiondate') # 存活周期
c.cake_cycle('created', 'repair_date') # 修复周期
c.cake_cycle('repair_date', 'verify_date') # 验证周期