Jiraベースの欠陥自動レポート分析(8)matplotlib折れ線グラフ:欠陥の発見、修復、および残りの数量の傾向分析

1つは、データを取得する

前回の記事は 、Jiraの自動欠陥レポート分析に基づいています。(5)プロジェクト ごとの欠陥統計プロジェクトの欠陥の検出数、残りの数、および修理の数を毎日カウントしています。

 

ここでは、を使用してデータを直接取得できます

 

次に、折れ線グラフを描きます

Jiraベースの欠陥自動レポート分析(7)matplotlib円グラフ:欠陥重大度分布 に関する記事に従い、  Drawクラスで折れ線グラフを描画するメソッドを追加します

データから、欠陥発見、修理、残存データ数の3つのデータがあることがわかります。つまり、横軸に日付、縦軸に数量をとって3本の破線を描く必要があります。


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

plt.rcParams ['font.sans-serif'] = ['simhei']#
通常は中国のラベルを表示するために使用されますplt.rcParams ['axes。 unicode_minus '] = False#通常は負の符号を表示するために使用されます


class Draw:
    "" " 
    Drawing 
    " "" 
    def __init __(self、reportpath):
        self.reportpath = reportpath 

    #1つ以上のタグのみを表示します
    def my_autopct(self、pct、limit = 1):
        return( '%。2f %%'%pct)if pct> limit else '' 

    def drawing_cake(self):
        "" "
        パイチャートの描画
        " "" 
        pass 
        

    def drawing_histogram(self):
        "" "
        ヒストグラム
        " ""
        pass 
        

    def drawing_linechart_more(self、project_name、title、x_lebal、* y_labels、** kw):
        "" "
        折れ線グラフの描画:複数の折れ線グラフをサポート
        " "" 
        fig、ax = plt.subplots(1、1)
        #設定x軸表示密度
        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()#凡例を有効にする
        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軸ラベル
        plt.ylabel( "Number")#Y轴PWM签
        plt.title(project_name + title)#¸
        题plt.savefig(self.reportpath + "/" + project_name + title + '。png')
        plt.show()
        plt。
        cla ()plt.close( "all")

 

3.統計とグラフ化

1.依存モジュールをインポートします

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

2.ポリラインデータをカウントするクラスを定義します

クラス行:
    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 = typesself 
        。週=週
        self.report_path = report_path 

    
    #折れ線グラフ-プロジェクト、修复、遗留電磁趋势図
    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'
            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 =マーカー、label = label 
            print( '包括的な欠陥傾向グラフ:最近の{}週に完了したデータ統計' .format(self.weeks))
        else:
            print( '包括的な欠陥グラフ:最近の{}週にデータがありません' .format (self.weeks))

3.統計手法を拡張する

上記は、プロジェクトの欠陥データの毎日の統計に基づいています。さらに、JQLクエリデータを直接実行することもできます。

たとえば、統計結果の数

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()))#タイムスタンプに変換:
        t1 = time.localtime(time_Stamp1)#時間の祖先に変換
        day = time.strftime( "%Y-%m-%d"、t1)#他に変換文字文字列形式:
        days.append(day)
    戻り日
DEFライン(自己):
    "" "
    绘制折线图:发现数量
    :PARAMのPROJECT_NAME: リターン""" 
    START_TIME = datetime.datetime.strptime(self.first_day + ' 〇時00分00秒'、「%Y-% m-%d%H:%M:%S ")
    #x轴
    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 ()#缺陷
        Plainusy_lebal.append(one_line)
    if sum(y_lebal)> 0:
        マーカー=( 'b-。')
        ラベル=( '検索')
        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 {}最近の{}欠陥発見傾向統計完了'.format(self.project_name、self.weeks))
    else:
        print('プロジェクト{}は最近{}週にBUGを送信しておらず、欠陥発見の傾向を分析できません'.format(self.project_name、self.weeks ))

 

4、実行統計

li = Line(project_name、test_jira、first_day、last_day、types、weeks、project_report_path)
#li.line()#(プロジェクト)ディスカバリー数量トレンド
li.line_lave()#(プロジェクト)包括的なトレンド分析:ディスカバリー、修復、残りの数量(トレンドは収束していますか?)

おすすめ

転載: blog.csdn.net/kk_gods/article/details/110821193