从BUG工具redmine上获取数据后借助python模块pycha 画出BUG分析类报表,利用xlsxwriter

Posted 虫子宴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从BUG工具redmine上获取数据后借助python模块pycha 画出BUG分析类报表,利用xlsxwriter相关的知识,希望对你有一定的参考价值。

#__author__ = ‘xu.duan‘
# -*- coding: utf-8 -*-
#######################################################################
#
import xlsxwriter,time,datetime
from redmine import Redmine
from functools import reduce
import sys
import os
import os.path
import getopt
import csv

reload(sys)
sys.setdefaultencoding(gb18030)

#set redmine
def Set_Redmine():
    REDMINE_URL = http://100.69.177.149:3000
    REDMINE_KEY = b549cac9132fb3ef8b2d3ed898dfb1f6e641b2f3
    redmine = Redmine(REDMINE_URL,key=REDMINE_KEY)
    return redmine

#获取所有issues方法,可以用*arg定义
def Get_Issues(project_name,status_id=*,tracker_id=None):
    issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id))
    return issues

#获取问题严重程度
def Get_Priority(project_name,status_id=*,tracker_id=None,priority_id=None,date=None,cf_26=None,cf_37=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),priority_id={0}.format(priority_id),created_on=><{0}.format(date),cf_26={0}.format(cf_26),cf_37={0}.format(cf_37))
    return priority_issues

def Get_Viewer_Priority(project_name,status_id=*,tracker_id=None,priority_id=None,date=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),priority_id={0}.format(priority_id),created_on=><{0}.format(date))
    return priority_issues


#按周获取问题
def Get_Week_Issues(project_name,status_id=*,tracker_id=None,date=None,cf_26=None,cf_37=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),created_on=><{0}.format(date),cf_26={0}.format(cf_26),cf_37={0}.format(cf_37))
    return priority_issues

def Get_Week_Issues_closed(project_name,status_id=*,tracker_id=None,date=None,cf_26=None,cf_37=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),closed_on=><{0}.format(date),cf_26={0}.format(cf_26),cf_37={0}.format(cf_37))
    return priority_issues

def Get_Viewer_Week_Issues(project_name,status_id=*,tracker_id=None,date=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),created_on=><{0}.format(date))
    return priority_issues

def Get_Viewer_Week_Issues_closed(project_name,status_id=*,tracker_id=None,date=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),closed_on=><{0}.format(date))
    return priority_issues
#按国家获取
def Get_Ancs_Issues(project_name,status_id=None,tracker_id=None,cf_26=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),cf_26={0}.format(cf_26))
    return priority_issues
#cf_26List=[‘Taiwan‘,‘Japan‘,‘Korea‘,‘German‘,‘Thailand‘]
#for i in cf_26List:
    #print len(Get_Ancs_Issues(‘nds-2-3-2‘,20,1,cf_26=‘%s‘%i))

    

def Get_Issues_category(project_name,status_id=*,tracker_id=None,cf_26=None,category_id=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),cf_26={0}.format(cf_26),category_id={0}.format(category_id))
    return priority_issues


#Ninjia=========================================================
def Get_Priority_Category(project_name,status_id=*,tracker_id=None,priority_id=None,category_id=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),priority_id={0}.format(priority_id),category_id={0}.format(category_id))
    return priority_issues

def Get_Category(project_name,status_id=*,tracker_id=None,category_id=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),category_id={0}.format(category_id))
    return priority_issues

def Get_CF37(project_name,status_id=*,tracker_id=None,cf_37=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),cf_37={0}.format(cf_37))
    return priority_issues

def Get_Ninja_Week_BUG(project_name,status_id=*,tracker_id=None,date=None):
    priority_issues = Set_Redmine().issue.filter(project_id ={0}.format(project_name),status_id={0}.format(status_id),tracker_id={0}.format(tracker_id),created_on=><{0}.format(date))
    return priority_issues

#aa = Get_Ninja_Week_BUG(‘redmine-test‘,‘*‘,11,‘2015-01-01|2015-12-31‘)
#print len(aa)

‘‘‘
w= Get_Issues_category(‘nds-2-3-2‘,‘*‘,1,category_id=40) 

print len(w)


created_on=‘><2012-03-01|2012-03-07‘
redmine = Set_Redmine()
i= Get_Issues(‘nds-2-3-2‘,‘*‘,tracker_id=1) 
c= Get_Issues(‘nds-2-3-2‘,‘closed‘,tracker_id=1) 
o= Get_Issues(‘nds-2-3-2‘,‘open‘,tracker_id=1) 
p= Get_Priority(‘nds-2-3-2‘,‘open‘,1,2) 
w= Get_Week_Issues(‘nds-2-3-2‘,‘*‘,1) 
print len(w)#len(i),len(o),len(c),len(p)

w= Get_Week_Issues(‘nds-2-3-2‘,‘closed‘,1,Week_Get(22)) #上上周
print Week_Get(-20)
‘‘‘
#定义开始时间和最后一天,定义是全局变量
current = datetime.datetime.now()  
start = datetime.date(current.year,1,1)  
laststart = datetime.date(current.year-1,1,1) 
laststart1 = datetime.date(current.year-2,1,1)   
last_day = datetime.date(current.year,12,31)  
isfirst = start.weekday()  
last_week = last_day.strftime(%W)  

  
  
weeks={}  
if isfirst !=0:  
    end = datetime.timedelta(7-start.weekday()-1)  
    weeks[0]=[start,start+end]  
start += datetime.timedelta(7 - start.weekday())  
def Print_Data(i):  
    days = datetime.timedelta(weeks=i)  
    end = start + days       
    if  i+1 == int(last_week):  
        weeks[i+1] = [end,last_day]  
    else:  
        weeks[i+1] = [end,end + datetime.timedelta(6)]  
  
def AllWeeks():  
    for i in range(0, int(last_week)):  
        Print_Data(i)  
    return weeks    
          
def WeekMain():  
  
    AllWeeks()  
    daylist= []
    weeklist = []
    daylist.append(u"%s年"%(current.year-2))
    daylist.append(u"%s年"%(current.year-1))
    weeklist.append(|.join([str(laststart1),str(laststart)]))
    weeklist.append(|.join([str(laststart),str(start)]))
    for (k,week) in weeks.items():  
        num = k+1<=9 and str(k+1) or str(k+1)
        if int(num) <= int(time.strftime("%W")):
            daylist.append(u"第%s周" %(num))
            weeklist.append(|.join([str(week[0]),str(week[1])]))
    return daylist,weeklist

#GetThisweek
def Week_Get():
    d = datetime.date.today()
    dayto = datetime.date.today() - datetime.timedelta(days=((d.isoweekday())))
    sixdays = datetime.timedelta(days=6)
    dayfrom = dayto - sixdays
    return |.join([str(dayfrom), str(dayto)])
print Week_Get()

#获取周BUG总量,这个可以自己自定义
def Get_total_Week_Bug_closed(project_name,status_id=*,tracker_id=None,cf_26=None,cf_37=None):
    d,w=WeekMain()
    weeklist =[]
    xlist = []
    sum = 0
    #ThisWeekBug = Get_Week_Issues(project_name,status_id,tracker_id,Week_Get())
    for i in w:
        w = Get_Week_Issues_closed(project_name,status_id,tracker_id,i,cf_26,cf_37)
        weeklist.append(len(w))
    for x in weeklist:
        sum +=x
        xlist.append(sum)
    return xlist,weeklist

#ANCSWeekClosedBug,ThisWeekCloseBug=Get_total_Week_Bug_closed(‘nds-2-3-2‘,‘closed‘,1,cf_26=‘Japan‘)


def Get_total_Week_Bug(project_name,status_id=*,tracker_id=None,cf_26=None,cf_37=None):
    d,w=WeekMain()
    weeklist =[]
    xlist = []
    sum = 0
    #ThisWeekBug = Get_Week_Issues(project_name,status_id,tracker_id,Week_Get())
    for i in w:
        w = Get_Week_Issues(project_name,status_id,tracker_id,i,cf_26,cf_37)
        weeklist.append(len(w))
    for x in weeklist:
        sum +=x
        xlist.append(sum)
    return xlist,weeklist

def Get_NDSViewer_Week_Bug_closed(project_name,status_id=*,tracker_id=None):
    d,w=WeekMain()
    weeklist =[]
    xlist = []
    sum = 0
    #ThisWeekBug = Get_Week_Issues(project_name,status_id,tracker_id,Week_Get())
    for i in w:
        w = Get_Viewer_Week_Issues_closed(project_name,status_id,tracker_id,i)
        weeklist.append(len(w))
    for x in weeklist:
        sum +=x
        xlist.append(sum)
    return xlist,weeklist

def Get_NDSViewer_Week_Bug(project_name,status_id=*,tracker_id=None):
    d,w=WeekMain()
    weeklist =[]
    xlist = []
    sum = 0
    #ThisWeekBug = Get_Week_Issues(project_name,status_id,tracker_id,Week_Get())
    for i in w:
        w = Get_Viewer_Week_Issues(project_name,status_id,tracker_id,i)
        weeklist.append(len(w))
    for x in weeklist:
        sum +=x
        xlist.append(sum)
    return xlist,weeklist

#Get_Priority(project_name,status_id=‘*‘,tracker_id=None,priority_id=None,date=None):
def Get_Week_Priority_Bug(project_name,status_id=*,tracker_id=None,priority_id=None,cf_26=None,cf_37=None):
    d,w=WeekMain()
    weeklist =[]
    for i in w:
        w = Get_Priority(project_name,status_id,tracker_id,priority_id,i,cf_26,cf_37)
        weeklist.append(len(w))
    return weeklist



def Get_NDSViewer_Priority_Bug(project_name,status_id=*,tracker_id=None,priority_id=None):
    d,w=WeekMain()
    weeklist =[]
    for i in w:
        w = Get_Viewer_Priority(project_name,status_id,tracker_id,priority_id,i)
        weeklist.append(len(w))
    return weeklist
#ningja BUG    
def Ninja_Week_BUG(project_name,status_id=*,tracker_id=None):
    d,w=WeekMain()
    weeklist =[]
    xlist=[]
    sum = 0
    for i in w:
        w = Get_Ninja_Week_BUG(project_name,status_id,tracker_id,i)
        weeklist.append(len(w))
    for x in weeklist:
        sum +=x
        xlist.append(sum)
    return xlist
    

if __name__ == __main__:
    #编写上周日期,用于测试报告name
    LastWeek = float(time.strftime("%W"+.5))-1
    _data =time.strftime("%Y_%m_%d", time.localtime())

    def ANCS():
        workbook = xlsxwriter.Workbook(rANCS Project Bug Statistical Analysis Report_CW%s_%s.xlsx%(LastWeek,_data))
        #worksheet = workbook.add_worksheet()
        #ANCSsheet
        worksheet = workbook.add_worksheet(AUDICHN)#创建ANCS中国区域BUG
        format = workbook.add_format()
        format.set_border(1) 
        format_title=workbook.add_format({bold: 1})    #定义format_title格式对象
        format_title.set_border(1)   #定义format_title对象单元格边框加粗(1像素)的格式
        format_title.set_bg_color(#A6FFFF)
        # ANCS‘DATA========================================================================================
        headings = [u, u日期,Immediate,Urgent,High,Normal,Low,u本周发现,u本周关闭,u累计关闭,u累计发现]
        CATEGORY_headings = [u所属模块, u累计关闭,u累计BUG数]
        
        CATEGORY= [3D,AXF,BMD,DTM,FTS,HAD,IPC,JV,Metadate,NAME,NAC,OTHER,POI,Routing,Shared,SLI,TMC,SPEECH]
        #Get china BUG on week
        ANCSDay,ANCSWeek=WeekMain()
        ANCSWeekClosedBug,ThisWeekCloseBug=Get_total_Week_Bug_closed(nds-2-3-2,closed,1,cf_26=China)
        ANCSWeekALLBug,ThisWeekALLBug=Get_total_Week_Bug(nds-2-3-2,*,1,cf_26=China)
        ANCSWeekLowBug=Get_Week_Priority_Bug(nds-2-3-2,*,1,1,cf_26=China)
        ANCSWeekNormalBug=Get_Week_Priority_Bug(nds-2-3-2,*,1,2,cf_26=China)
        ANCSWeekHighBug=Get_Week_Priority_Bug(nds-2-3-2,*,1,3,cf_26=China)
        ANCSWeekUrgentBug=Get_Week_Priority_Bug(nds-2-3-2,*,1,4,cf_26=China)
        ANCSWeekImmdDiateBug=Get_Week_Priority_Bug(nds-2-3-2,*,1,5,cf_26=China)
        ANCSChinaBug_ALL=Get_Ancs_Issues(nds-2-3-2,*,1,cf_26=China)
        ANCSChinaBug_CLOSE=Get_Ancs_Issues(nds-2-3-2,colsed,1,cf_26=China)
        #挂起BUG
        #ANCSChinaBug_20=Get_Ancs_Issues(‘nds-2-3-2‘,20,1,cf_26=‘China‘)
        ANCScategory3D=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=40)
        ANCScategoryAXF=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=116)
        ANCScategoryBMD=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=5)
        ANCScategoryDTM=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=257)
        ANCScategoryFTS=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=83)
        ANCScategoryHAD=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=260)
        ANCScategoryIPC=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=7)
        ANCScategoryJV=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=71)
        ANCScategoryMetadate=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=69)
        ANCScategoryNAME=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=3)
        ANCScategoryNAC=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=10)
        ANCScategoryOTHER=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=302)
        ANCScategoryPOI=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=4)
        ANCScategoryRouting=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=2)
        ANCScategoryShared=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=236)
        ANCScategorySLI=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=8)
        ANCScategoryTMC=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=9)
        ANCScategorySPEECH=Get_Issues_category(nds-2-3-2,colsed,1,cf_26=China,category_id=183)
        #==============================================================================================
        ANCScategory3D_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=40)
        ANCScategoryAXF_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=116)
        ANCScategoryBMD_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=5)
        ANCScategoryDTM_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=257)
        ANCScategoryFTS_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=83)
        ANCScategoryHAD_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=260)
        ANCScategoryIPC_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=7)
        ANCScategoryJV_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=71)
        ANCScategoryMetadate_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=69)
        ANCScategoryNAME_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=3)
        ANCScategoryNAC_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=10)
        ANCScategoryOTHER_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=302)
        ANCScategoryPOI_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=4)
        ANCScategoryRouting_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=2)
        ANCScategoryShared_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=236)
        ANCScategorySLI_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=8)
        ANCScategoryTMC_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=9)
        ANCScategorySPEECH_ALL=Get_Issues_category(nds-2-3-2,*,1,cf_26=China,category_id=183)
              
        data = [
        ANCSDay,ANCSWeek,ANCSWeekImmdDiateBug,ANCSWeekUrgentBug,ANCSWeekHighBug,ANCSWeekNormalBug,ANCSWeekLowBug,ThisWeekALLBug,ThisWeekCloseBug,ANCSWeekClosedBug,ANCSWeekALLBug
        
        ]
        category_data_closed=map(len,[
        ANCScategory3D,ANCScategoryAXF,ANCScategoryBMD,ANCScategoryDTM,ANCScategoryFTS,ANCScategoryHAD,ANCScategoryIPC,ANCScategoryJV,ANCScategoryMetadate,ANCScategoryNAME,ANCScategoryNAC,ANCScategoryOTHER,ANCScategoryPOI,ANCScategoryRouting,ANCScategoryShared,ANCScategorySLI,ANCScategoryTMC,ANCScategorySPEECH
        ])
        category_data_ALL=map(len,[
        ANCScategory3D_ALL,ANCScategoryAXF_ALL,ANCScategoryBMD_ALL,ANCScategoryDTM_ALL,ANCScategoryFTS_ALL,ANCScategoryHAD_ALL,ANCScategoryIPC_ALL,ANCScategoryJV_ALL,ANCScategoryMetadate_ALL,ANCScategoryNAME_ALL,ANCScategoryNAC_ALL,ANCScategoryOTHER_ALL,ANCScategoryPOI_ALL,ANCScategoryRouting_ALL,ANCScategoryShared_ALL,ANCScategorySLI_ALL,ANCScategoryTMC_ALL,ANCScategorySPEECH_ALL
        ])
        
        worksheet.write_row(A1, headings, format_title)
        worksheet.write_column(A2, data[0],format)
        worksheet.write_column(B2, data[1],format)
        worksheet.write_column(C2, data[2],format)
        worksheet.write_column(D2, data[3],format)
        worksheet.write_column(E2, data[4],format)
        worksheet.write_column(F2, data[5],format)
        worksheet.write_column(G2, data[6],format)
        worksheet.write_column(H2, data[7],format)
        worksheet.write_column(I2, data[8],format)
        worksheet.write_column(J2, data[9],format)
        worksheet.write_column(K2, data[10],format)
        worksheet.write_row(B%d%(len(ANCSDay)+2),[u合计],format)
        #写入sum函数
        worksheet.write_formula(C%d%(len(ANCSDay)+2), 以上是关于从BUG工具redmine上获取数据后借助python模块pycha 画出BUG分析类报表,利用xlsxwriter的主要内容,如果未能解决你的问题,请参考以下文章

移动应用开发必备工具盘点

testlink关联redmine设置

Ticket管理工具 Redmine

项目管理工具redmine的改善问题

我装的redmine版本是0.8.4的,现在的问题是,提交了bug之后就没有办法修改了,页面没有修改或编辑按钮,

一个bug在redmine中的诞生到终结