python数据统计之禅道bug统计
背景
通过定期输出 每条产品的 BUG 情况,以此来反馈开发解决问题、测试跟进问题的情况;钉钉群推送提醒开发及时解决
以此我这边开始着手准备编写一个小工具,最终达到目的:自动定期发送统计报告,报告维度(数据 + html展示)。
技术选型
python + markdown + pymysql + html + jenkins + 钉钉机器人
实现思路
python主要用到sshtunnel,pysql库跳板机连接mysql数据库,loguru库日志记录,yaml记录项目参数,request调取钉钉接口
- 读取禅道数据库数据及状态,封装sql类,把各维度统计数据通过dic格式返回
- 禅道bug汇总数据进行进行拼接,生成模板写入markdown文件。(钉钉会支持简单markdown格式,表格等等不支持)
- 禅道bug明细数据,生成html页面(没找到合适的三方库只能手动撸)
- 调取钉钉自定义接口,进行数据请求。
- jenkins实现定期推送+html页面展示
主要代码
1、禅道sql封装
ps.公司服务国外的所以时区+8H
from datetime import datetime
from middleware.config_handler import db_connect
"""针对产品返回所有bug信息"""
def sql_pakeage(productid):
"""
BUG状态统计SQL封装
:param productid:
:return:
"""
bug_sql = "select count(*) from zt_bug where product in %s and deleted='0'"% (
productid)
resolved_bug_sql = "select count(*) from zt_bug where product in %s and deleted = '0' and `status` = 'resolved' and resolution <> 'postponed' " % (
productid)
not_resolved_bug_sql = "select count(*) from zt_bug where product in %s and deleted = '0' and `status` = 'active' " % (
productid)
postponed_bug_sql = "select count(*) from zt_bug where product in %s and deleted = '0' and `status` <> 'closed' and resolution = 'postponed' " % (
productid)
closed_bug_sql = "select count(*) from zt_bug where product in %s and deleted = '0' and `status` = 'closed' " % (
productid)
return bug_sql,resolved_bug_sql,not_resolved_bug_sql,postponed_bug_sql,closed_bug_sql
def test_product_bug(productid):
"""
产品BUG情况统计
:param productid:
:return:
"""
#总bug数
all_bug=db_connect.query_sql_df(sql_pakeage(productid)[0])
#已解决bug数
resolved_bug = db_connect.query_sql_df(sql_pakeage(productid)[1])
# 未解决BUG数(当前显示BUG状态为未解决的。包含当前还没被解决的、之前遗留的未解决、以及reopen的BUG(累计数据))
not_resolved_bug = db_connect.query_sql_df(sql_pakeage(productid)[2])
# 延期BUG数
postponed_bug= db_connect.query_sql_df( sql_pakeage(productid)[3])
# 已关闭BUG数
closed_bug = db_connect.query_sql_df(sql_pakeage(productid)[4])
statistics_bug = { "总BUG数":all_bug[0],"已解决BUG": resolved_bug[0], "未解决BUG": not_resolved_bug[0], "已关闭BUG": closed_bug[0],
"延期解决BUG": postponed_bug[0]}
print(statistics_bug)
return statistics_bug
def test_product_bug_near(day, product):
"""
最近总的BUG情况统计统计
:param: day 根据输入天数
:return:
"""
now = (datetime.datetime.now() + datetime.timedelta(hours=8)).strftime('%Y-%m-%d %H:%M:%S') #服务器时区要 + 8h
recent_sevenday = (datetime.datetime.now() - datetime.timedelta(days=day)).strftime("%Y-%m-%d %H:%M:%S")
new_near_bug = db_connect.query_sql_df("""SELECT count(*) from zt_bug b where b.product in %s and openedDate between "%s" and "%s";"""%(product, recent_sevenday, now))
open_bug = db_connect.query_sql_df("""SELECT count(*) from zt_bug b where b.product in %s and b.STATUS = "active" and openedDate between "%s" and "%s";"""%(product, recent_sevenday, now))
close_bug = db_connect.query_sql_df("""SELECT count(*) from zt_bug b where b.product in %s and b.STATUS = "closed" and openedDate between "%s" and "%s";"""%(product, recent_sevenday, now))
close_unbug = db_connect.query_sql_df("""SELECT count(*) from zt_bug b where b.product in %s and b.STATUS = "resolved" and openedDate between "%s" and "%s";"""%(product, recent_sevenday, now))
statistics_bug = { "本周新增BUG数":new_near_bug[0], "本周未解决BUG数":open_bug[0],"本周已解决BUG数":close_bug[0],"本周已解决待验证BUG数":close_unbug[0]}
return statistics_bug
def bug_count(day, product):
"""
最近总的BUG情况统计明细数据
:param: day 根据输入天数
:return:
"""
now = (datetime.datetime.now() + datetime.timedelta(hours=8)).strftime('%Y-%m-%d %H:%M:%S') #服务器时区要 + 8h
now_day = datetime.datetime.now().strftime('%Y-%m-%d')
recent_sevenday = (datetime.datetime.now()-datetime.timedelta(days=day)).strftime("%Y-%m-%d %H:%M:%S")
bug_sql = """
SELECT p.name,b.title,b.assignedTo,b.severity,b.type,b.status,b.openedBy, CAST(openedDate AS CHAR) AS openedDate from zt_bug b left join zt_product p on b.product = p.id
where b.STATUS <> 'closed' and b.product in %s and openedDate between "%s" and "%s";"""%(product, recent_sevenday, now)
print(bug_sql)
recent_sevenday_bug = db_connect.query_sql_df(bug_sql)
return recent_sevenday_bug
2、钉钉接口推送
import json
import urllib.request
from config.path_config import data_file
from handler.loguru_handler import logger
def send_bug(url, data_file):
# url = r"https://oapi.dingtalk.com/robot/send?access_token=XXXXXXX"
logger.info("构建钉钉机器人的webhook")
header = {"Content-Type": "application/json","Charset": "UTF-8"}
with open(data_file, "r", encoding="utf-8") as f:
conntent = f.read()
data = {
"msgtype": "markdown",
"markdown": {
"title": "测试bug统计",
"text": conntent
},
"at": {
"isAtAll": False #@全体成员(在此可设置@特定某人)
}
}
logger.info(f"构建请求内容:{data}")
sendData = json.dumps(data)
sendData = sendData.encode("utf-8")
request = urllib.request.Request(url=url, data=sendData, headers=header)
logger.info("发送请求")
opener = urllib.request.urlopen(request)
logger.info("请求求发回的数据构建成为文件格式")
res = opener.read()
logger.info(f"返回结果为:{res}")
3、bug明细转html文件
def bug_html(lis ,html_file):
"""
对查询bug明细转html文件
:param lis
:param html_file
"""
conten_title = []
for key in lis[0]:
conten_title.append(key)
a = "</th><th>".join(conten_title)
con_title = "<tr><th>" + a + "</th></tr>"
conten_val = []
con = ""
for i in range(0, len(lis)):
for index, v in enumerate(lis[i]):
if index ==0:
lis[i][v] ="<tr><td>" + lis[i][v]
con = con + str(lis[i][v]) + "</td><td>"
con = con[0:-2] +"r>"
con = con + "\n"
head = """<meta charset="utf-8">
<style type="text/css">
table.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #9dcc7a;border-collapse: collapse;}
table.tftable th {font-size:12px;background-color:#abd28e;border-width: 1px;padding: 8px;border-style: solid;border-color: #9dcc7a;text-align:left;}
table.tftable tr {background-color:#ffffff;}
table.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #9dcc7a;}
</style>\n<table id="tfhover" class="tftable" border="1">\n"""
last = "</table>"
htm = head + con_title + con + last
with open(html_file, "w", encoding="utf-8") as f:
f.write(htm)
另外功能基类以及调用发送代码比较简单就不展示了。
业务统计
按周统计(月份统计同理):
新增,新增日期为本周内的(包括本周内被解决或关闭的 BUG)
已解决,解决日期为本周内的。被开发设定为已解决的。其中可能有部分是上周遗留下来的,体现了开发在本周的变化情况(包括设计如此、重复 BUG、外部原因、无法重现、不予解决、转为需求),不包含延期处理
已关闭,关闭日期为本周内的。是测试验证过,确实已经解决的,包括其中有的是上周遗留下来的
未解决,当前显示 BUG 状态为未解决的。包含当前还没被解决的、之前遗留的未解决、以及 reopen 的 BUG(累计数据)
延期解决,当前显示 BUG 状态为 延期处理的。BUG 状态中新增一个延期解决 (累计数据)
应用截图
钉钉通知

明细数据展示

python数据统计之禅道bug统计的更多相关文章
- 用python实现自动化登录禅道系统 设置定时器自动执行脚本
由于各种原因,我想试下用python实现自动登录禅道系统,并且每天定时执行.(本人第一次接触自动化,在大佬眼中门槛都没摸到的类型) 首先缕清思路: 1.实现自动登录禅道系统,用selenium实现2. ...
- python tornado 实现类禅道系统
最近楼主加班 喽, 好久没有更新我的博客了,哎,一言难尽,废话我就不说了,来开始上精华. 背景:目前市面上有很多bug管理工具,但是各有各的特点,最著名,最流行的就是禅道,一个偶然的机会接触到了pyt ...
- 禅道---Bug管理模块
禅道官网:http://www.cnezsoft.com/ 简介: 开源免费的项目管理软件.集产品管理.项目管理.测试管理一体以及事物管理组织管理的功能 使用原因: 开源 方便跟踪管理Bug 使用简单 ...
- 禅道Bug管理工具环境搭建
下载地址:http://sourceforge.net/projects/zentao/files/8.2/ZenTaoPMS.8.2.stable.exe/download 1.解压ZenTaoPM ...
- centos 7 禅道bug管理软件部署
2018-10-26 部署前置条件 关闭防火墙或者添加防火墙规则,使禅道端口可以通过防火墙 关闭防火墙与selinux 临时关闭防火墙 systemctl stop firewalld 永久防火墙开机 ...
- CentOS下搭建禅道Bug反馈系统
禅道 下载集成版本(apache\php\mysql) wget http://sourceforge.net/projects/zentao/files/8.2.5/ZenTaoPMS.8.2.5. ...
- 禅道Bug等级划分标准
一.严重程序 P1:致命(该问题在测试中较少出现,一旦出现应立即中止当前版本测试) 阻碍开发或测试工作的问题:造成系统崩溃.死机.死循环,导致数据库数据丢失, 与数据库连接错误,主要功能丧失,基本模块 ...
- 测试软件—禅道BUG管理工具
入禅 目录 入禅 1.禅道的基本使用 1.禅道的基本使用 admin(管理员) 部门:创建部门(需求部门,开发部门,测试部门,项目部门,产品部门) 组织:创建用户(产品经理,项目经理,开发人员,测试人 ...
- 禅道bug安装报错
[root@lnmp src]# grep "session.save" /etc/php.ini ; http://php.net/session.save-handler se ...
随机推荐
- Exponentiation java大数
Exponentiation 大数a的n次幂,直到读到EOF(文件结尾)为止,其中忽略小数后面的0 1 import java.util.*; 2 import java.math.*; 3 impo ...
- 尝试用面向对象思维理解Vue组件
什么是组件 用面向对象的思维去理解Vue组件,可以将所有的事物都抽象为对象,而类或者说是组件,都具有属性和操作. 如抽取人类为组件,其基本的属性有姓名.年龄.国籍:基本的方法有吃饭.睡觉.跑步等. & ...
- .NET Core 对象池的使用
昨天在『.NET 大牛之路』技术群和大家聊到了对象池的话题,今天展开详细讲讲这个知识点. 池这个概念大家都很熟悉,比如我们经常听到数据库连接池和线程池.它是一种基于使用预先分配资源集合的性能优化思想. ...
- kafka错误集锦
javax.management.InstanceAlreadyExistsException: kafka.consumer:type=FetchRequestAndResponseMetrics, ...
- XCTF(MISC) 图片隐写
题目描述:菜猫给了菜狗一张图,说图下面什么都没有 1.给了个pdf,打开是这玩意 2.盲猜flag是图片后面,右键直接删除图片试试. 答案出来了.
- git配置多个ssh key
随着工作的深入,我们通常都会有多个git账户.比如公司gitlab一个账户,github或gitee有一个账户.而平时我们又回通过 配置ssh公私钥认证的方式省去繁琐的登录远程仓库的操作,不同的git ...
- Spring 的循环依赖问题
什么是循环依赖 什么是循环依赖呢?可以把它拆分成循环和依赖两个部分来看,循环是指计算机领域中的循环,执行流程形成闭合回路:依赖就是完成这个动作的前提准备条件,和我们平常说的依赖大体上含义一致.放到 S ...
- 「AGC035C」 Skolem XOR Tree
「AGC035C」 Skolem XOR Tree 感觉有那么一点点上道了? 首先对于一个 \(n\),若 \(n\equiv 3 \pmod 4\),我们很快能够构造出一个合法解如 \(n,n-1, ...
- [源码解析] 深度学习分布式训练框架 horovod (16) --- 弹性训练之Worker生命周期
[源码解析] 深度学习分布式训练框架 horovod (16) --- 弹性训练之Worker生命周期 目录 [源码解析] 深度学习分布式训练框架 horovod (16) --- 弹性训练之Work ...
- centos7下安装mycat中间件 笔记
1. 下载 # wget http://dl.mycat.org.cn/1.6.7.4/Mycat-server-1.6.7.4-release/Mycat-server-1.6.7.4-releas ...