Jira-based defect automated report analysis (eight) matplotlib line chart: defect discovery, repair, and remaining quantity trend analysis

One, get data

The previous article is  based on Jira's automatic defect report analysis (5) Defect statistics by project  We have counted the number of project defects found, the number of remaining, and the number of repairs on a daily basis.

 

Here we can directly obtain the data using

 

Second, draw a line chart

We follow the   article on Jira-based defect automated report analysis (7) matplotlib pie chart: defect severity distribution , and add a method to draw a line chart in the Draw class

From the data, we can see that there are three pieces of data for defect discovery, repair, and number of remaining data, which means that three broken lines need to be drawn with date as the horizontal axis and quantity as the vertical axis.

# coding=utf-8
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

plt.rcParams['font.sans-serif'] = ['simhei'] # Used to display Chinese labels normally
plt.rcParams['axes.unicode_minus'] = False # Used to display the negative sign normally


class Draw:
    """
    Drawing
    """
    def __init__(self, reportpath):
        self.reportpath = reportpath

    # Only display >1 tags
    def my_autopct(self, pct, limit=1):
        return ('%.2f%%' % pct) if pct > limit else ''

    def drawing_cake(self):
        """
        Draw a pie chart
        """
        pass
        

    def drawing_histogram(self):
        """
        Histogram
        """
        pass 
        

    def drawing_linechart_more(self, project_name, title, x_lebal, *y_labels, **kw):
        """
        Draw a line chart: support multi-line
        """
        fig, ax = plt.subplots(1, 1)
        # Set the x-axis display density
        tick_spacing = 10
        ax.xaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))
        for i in range(len(y_labels)):
            plt.plot(x_lebal, y_labels[i], kw['marker'][i], linewidth=1, label=kw['label'][i])
        plt.legend() # Let the legend take effect
        x = range (len (x_lebal))
        plt.xticks(x, x_lebal, rotation=90, fontsize=6)
        plt.margins(0)
        plt.subplots_adjust(bottom=0.15)
        plt.xlabel("Date(day)") # X axis label
        plt.ylabel("Number") # Y axis label
        plt.title(project_name + title) # Title
        plt.savefig(self.reportpath + "/" + project_name + title + '.png')
        plt.show()
        plt.cla ()
        plt.close("all")

 

3. Statistics and graphing

1. Import dependent modules

from ana_jira import Ana_jira
from draw import Draw
from common.mysqluntil import MysqlUntil

2. Define a class to count polyline data

class Line:
    def __init__(self, project_name, test_jira, first_day, last_day, types, weeks, report_path):
        self.project_name = project_name
        self.test_jira = test_jira
        self.first_day = first_day
        self.last_day = last_day
        self.types = types
        self.weeks = weeks
        self.report_path = report_path

    
    # Line chart-discovery, repair, and remaining quantity trend chart
    def line_lave(self):
        sql = '''
        SELECT
            `date`,
            `amount_find`,
            `amount_lave`,
            `amount_repair`
        FROM
            `project_issues`
        WHERE
            `project` = '{}'
        AND `date` BETWEEN '{}'
        AND '{}';
        '''.format(self.project_name, self.first_day, self.last_day)
        datas = MysqlUntil().mysql_select(sql)
        date, amount_find, amount_lave, amount_repair = [], [], [], []
        for data in datas:
            date.append(data['date'] if data['date'] else '未填写')
            amount_find.append(int(data['amount_find']) if data['amount_find'] else 0)  #
            amount_lave.append(int(data['amount_lave']) if data['amount_lave'] else 0)  # 遗留数量
            amount_repair.append(int(data['amount_repair']) if data['amount_repair'] else 0)
        if date:
            marker = ('b-.','r-','g--') # line style, color
            label = ('find','lave','repair') # legend
            Draw(self.report_path).drawing_linechart_more(self.project_name,
                                                          " Issues Trend Analysis (IT WEEK)",
                                                          date,
                                                          amount_find, amount_lave, amount_repair,
                                                          marker=marker, label=label
                                                          )
            print('Comprehensive defect trend chart: data statistics completed in recent {}weeks'.format(self.weeks))
        else:
            print('Defect comprehensive trend chart: No data in recent {}weeks'.format(self.weeks))

3. Expand statistical methods

The above is based on the daily statistics of project defect data. In addition, we can also directly execute JQL query data

For example, the number of statistical findings

def days(start_time, weeks, m=0):
    days = []
    for i in range(m, 7*weeks+m):
        enddays = start_time + datetime.timedelta (days = i)
        time_Stamp1 = int(time.mktime(enddays.timetuple())) # Convert to timestamp:
        t1 = time.localtime(time_Stamp1) # Converted into time ancestor
        day = time.strftime("%Y-%m-%d", t1) # Convert to other string format:
        days.append(day)
    return days
def line(self):
    """
    Draw a line graph: find the number
    :param project_name:
    :return:
    """
    start_time = datetime.datetime.strptime(self.first_day + ' 00:00:00', "%Y-%m-%d %H:%M:%S")
    # x axis
    start = days(start_time, self.weeks)
    end = days(start_time, self.weeks, 1)
    y_lebal = []
    for m, n in zip(start, end):
        everyday_find_jql = 'project="{}" AND created >= {} AND created <= {}'.format(self.project_name, m, n)
        one_line = Ana_jira (self.test_jira, everyday_find_jql) .req_jira () # 缺 陷 Quantity
        y_lebal.append(one_line)
    if sum(y_lebal) > 0:
        marker = ('b-.')
        label = ('find')
        Draw(self.report_path).drawing_linechart_more(self.project_name,
                                                      " Issues Discovery Trend Analysis (IT WEEK)",
                                                      start,
                                                      y_lebal,
                                                      marker=marker, label=label
                                                      )
        print('Project {} recent {} week defect discovery trend statistics completed'.format(self.project_name, self.weeks))
    else:
        print('Project {} has not submitted BUG in recent {} week, unable to analyze the trend of defect discovery'.format(self.project_name, self.weeks))

 

Four, execution statistics

li = Line(project_name, test_jira, first_day, last_day, types, weeks, project_report_path)
# li.line() # (Project) Discover the quantity trend
li.line_lave() # (Project) Comprehensive trend analysis: discovery, repair, remaining quantity (whether the trend converges)

Guess you like

Origin blog.csdn.net/kk_gods/article/details/110821193