excel 练习玩具统计项目组excel日报
import xlrd
import xlwt
import os,time
import json
from xlrd import xldate_as_tuple
from datetime import datetime
from toydir.logutil import logger
logger = logger("root", rootstdout=True, handlerList=['I','E'])
# from matplotlib import font_manager
# my_font = font_manager.FontProperties(fname="C:/Windows/Fonts/simsun.ttc") class ExcelUnit(object):
def __init__(self,excel_path):
self.excelObject=xlrd.open_workbook(excel_path)
self.sheetObject=self.excelObject.sheet_by_index(0)
self.sheet_name=self.sheetObject.name
self.rows=self.sheetObject.nrows
self.cols=self.sheetObject.ncols def getSpecialCell(self,x,y):
return self.sheetObject.cell(x,y).value def read_excel(self):
list=[]
for row in range(1,self.rows):
lists=self.sheetObject.row_values(row)[:self.cols] cell=self.sheetObject.cell_value(row,1)
try:
global d
d= datetime(*xldate_as_tuple(cell, 0))
except Exception as e:
pass
cells= d.strftime('%Y/%m/%d')
lists[1]=cells
list.append(tuple(lists))
return list def getAllExcellContent(Mode):
"""Mode =0 ->week ,Mode=1->month"""
absxslFileList = []
xslList=[]
excelDir=None
if Mode==0:
excelDir=os.getcwd()+"\\sourcexsldir"
elif Mode==1:
excelDir=os.getcwd()+"\\months_sourcexsl"
if os.path.isdir(excelDir):
for o in os.listdir(excelDir):
absxslfile=excelDir+'\\'+o
if o.split('.')[-1]=="xlsx" and os.path.isfile(absxslfile):
absxslFileList.append(absxslfile)
for xsl in absxslFileList:
excelInst=ExcelUnit(xsl)
xslList.append(excelInst.read_excel())
return xslList def Dataset(get_excels):
error_sum=[]
news=[]
contents=[]
work_attr=["用例编写", "测试准备", "功能用例执行", "其它测试执行", "bug验证", "测试结果整理", "其它", "运维开发"]
for excel in get_excels: for row in excel:
# print(row)
if row[0] and row[1] and row[2]and row[3]:
if row[1].count("/")==2 and row[4] in work_attr:
# logger.info(row)
contents.append(row)
else: logger.error("发现异常数据,见异常数据汇总sheet")
logger.error("++++++++++++++++++++")
logger.error(row)
error_sum.append(row)
#raise ValueError("DATE FORMAT or Work Nature NOT CORRECT,Check please!")
else:
print("======出现格式异常数据==========")
logger.error(row)
#order by user
newdt=sorted(contents, key=lambda x: x[0])
users_set=list(set([i[0] for i in newdt]))
#user groupby
for u in users_set:
per_list=list(filter(lambda x:x[0]==u,newdt))
news.extend(per_list)
new_d=[]
for r in error_sum:
j=list(r)
j[1],j[5]=j[5],j[1]
k=tuple(j)
new_d.append(k)
return news,users_set,new_d def splitdate(mode):
datas,users,err=Dataset(getAllExcellContent(Mode=mode))
all_dts=[]
for user in users:
my_list = list(filter(lambda o: o[0]== user, datas))
# print(my_list)
my_program=my_list[0][3]
my_date_list=sorted(list(set([i[1] for i in my_list])))
for index,day in enumerate(my_date_list):
lk = []
work_times = []
useable_times=[]
casewriteNumbers = []
case_excuteNum = []
bug_submitNum = []
bug_regNum = []
for dt in my_list:
if dt[1]==day:
if dt[4]!="其它":
useable_time=float(dt[5]) if dt[5] else 0
useable_times.append(useable_time) wh=float(dt[5]) if str(dt[5]).strip() else 0
cw=int(dt[6]) if str(dt[6]).strip() else 0
ce=int(dt[7]) if str(dt[7]).strip() else 0
bug_sub=float(dt[8]) if str(dt[8]).strip() else 0
bug_reg=float(dt[9]) if str(dt[9]).strip() else 0 casewriteNumbers.append(cw)
case_excuteNum.append(ce)
bug_submitNum.append(int(bug_sub))
bug_regNum.append(int(bug_reg))
work_times.append(float(wh))
work_saturation =float('%.3f' % (sum(useable_times)/7))
lk.insert(0,user)
lk.insert(1,work_saturation)
lk.insert(2,day)
lk.insert(3, my_program)
lk.insert(4,sum(work_times))
lk.insert(5,sum(useable_times)) all_dts.append(tuple(lk))
# for i in all_dts:
# logger.debug(i)
return all_dts def week_sum(daily_dt): persons=list(set([j[0] for j in daily_dt ]))
allperson_week=[]
for p in persons:
# my_weekdts = list(filter(lambda o: o[0] == p, daily_dt))
weekTime=[]
useable_weekTime=[]
prog=[]
man=p
pg_list = []
oneperson_oneweek=[]
for dt in daily_dt:
oneday_hour=float(dt[4]) if str(dt[4]).strip() else 0
oneday_usebaletime=float(dt[5]) if str(dt[5]).strip() else 0
if dt[0]==p:
weekTime.append(oneday_hour)
useable_weekTime.append(oneday_usebaletime)
pg_list.append(dt[3])
prog.append(pg_list)
if len(weekTime) ==5:
week_saturation = float('%.3f' % (sum(useable_weekTime) / 5/7))
else:
week_saturation=float('%.3f' %(sum(useable_weekTime)/len(weekTime)/7))
# for pg in list(set(prog)):
oneperson_oneweek.insert(0,man)
oneperson_oneweek.insert(1,week_saturation)
oneperson_oneweek.insert(2,sum(weekTime))
allperson_week.append(tuple(oneperson_oneweek))
orderProgramWeek=sorted(allperson_week,key=lambda x:x[1],reverse=True)
orderProgramWeek.insert(0,("姓名","周日人均和度","周生产时长"))
return orderProgramWeek def sara_bypro():
#get init data contain ot work
datas,users,err=Dataset(getAllExcellContent(Mode=0))
# set program
pro=list(set([i[3] for i in datas]))
allpg_list=[]
for pg in pro :
pg_user=[]
onepro=[]
useable_list = []
work_time = []
for dt in datas: if dt[3]==pg:
pg_user.append(dt[0])
one_dayhour=float(dt[5]) if dt[5] else 0
if dt[4]!="其它":
useable_time=one_dayhour
useable_list.append(useable_time)
work_time.append(one_dayhour)
#user set this pro
real_user=list(set(pg_user))
# program
onepro.append(pg)
#program week sara
onepro.append(float('%.3f' % (sum(useable_list)/35/len(real_user))))
# week_pro有效时长
onepro.append(float('%.3f' % (sum(useable_list))))
#week pro worktimes
onepro.append(float('%.3f' % (sum(work_time))))
#汇总each program week sara
allpg_list.append(tuple(onepro))
allpg_list=sorted(allpg_list,key=lambda oneRow:oneRow[1])
return allpg_list def create_sheet():
pro_tbheader=["项目","项目人均人力饱和度","生产时长","工作时长"]
#err_tbheader=["姓名","工作时长", "工作内容", "所属项目组", "工作性质", "日期", "用例编写量", "用例执行量", "bug提交量", "bug验证量"]
headers_summary = ["姓名","工作时长", "工作内容", "所属项目组", "工作性质", "日期", "用例编写量", "用例执行量", "bug提交量", "bug验证量"]
xlsx = xlwt.Workbook()
person_saraday=week_sum(splitdate(0))
daily_list,user,err=Dataset(getAllExcellContent(Mode=0))
pro_saralist=sara_bypro()
pro_saralist.insert(0,tuple(pro_tbheader))
#add errtb header
err.insert(0,tuple(headers_summary))
error_sheet=xlsx.add_sheet("异常数据汇总")
summaryContainOt=xlsx.add_sheet("日报汇总")
cur_sheet = xlsx.add_sheet('项目人力投入')
day_sheet=xlsx.add_sheet("日饱和度")
pro_sheet=xlsx.add_sheet("项目周饱和度")
mon_program=xlsx.add_sheet("月项目饱和度")
mon_day_sheet=xlsx.add_sheet("月度日饱和")
group_sheet_week=xlsx.add_sheet("自由组合")
month_init_data=xlsx.add_sheet("月度原始数据")
#grep_sheet=xlsx.add_sheet("过滤汇总")
#summaryContainOt=xlsx.add_sheet("日报汇总")
new_d=[]
for r in daily_list:
j=list(r)
j[1],j[5]=j[5],j[1]
k=tuple(j)
new_d.append(k) # input summary contain ot
call_new_d=new_d
#插入是个动作
call_new_d.insert(0, tuple(headers_summary))
for e_index,one_err in enumerate(call_new_d):
for e_col in range(len(headers_summary)):
summaryContainOt.write(e_index,e_col,one_err[e_col])
# action add tb header
new_s = list(filter(lambda x: x[4] != "其它", new_d))
# new_s.insert(0,tuple(headers_summary))
#input data_summary
for e_index,one_err in enumerate(new_s):
for e_col in range(len(headers_summary)):
cur_sheet.write(e_index,e_col,one_err[e_col])
# input person_sara
for e_index,one_err in enumerate(person_saraday):
for e_col in range(3):
day_sheet.write(e_index,e_col,one_err[e_col])
# input program_sara
for e_index,one_err in enumerate(pro_saralist):
for e_col in range(4):
pro_sheet.write(e_index,e_col,one_err[e_col])
# input err sheet
for e_index,one_err in enumerate(err):
for e_col in range(len(headers_summary)):
error_sheet.write(e_index,e_col,one_err[e_col])
#get month data
program_month,month_daily=sum_month()
logger.debug(program_month)
logger.debug(month_daily)
reload_mon_pro=[]
for i in program_month:
i[1].insert(0,(i[0],'','',''))
i[1].insert(1,("项目组","月饱和","工时","有效时长"))
reload_mon_pro.extend(i[1])
logger.info(reload_mon_pro)
for index,row in enumerate(reload_mon_pro):
for col in range(4):
mon_program.write(index,col,row[col])
#input month day sheet
reload_mon_data=[]
for i in month_daily:
i[1].insert(0,(i[0],'',''))
reload_mon_data.extend(i[1])
for index,row in enumerate(reload_mon_data):
for col in range(3):
mon_day_sheet.write(index, col, row[col])
# input month init data
for index ,row in enumerate(sum_mutiMonth()):
for col in range(10):
month_init_data.write(index,col,row[col])
#input grep config
for index,row in enumerate(filter_config_program(Mode=0)):
for col in range(2):
group_sheet_week.write(index,col,row[col])
strf = time.strftime("%Y%m%d_%H_%M", time.localtime())
xlsx.save(os.getcwd()+"\\result_summarydir\\summary_{}.xls".format(strf)) def sum_month():
daily_dt=splitdate(mode=1)
month_list=[str(i) for i in range(1,13)]
excel_month=list(set([str(int(it[2].split('/')[1])) for it in daily_dt]))
intersect_month=list(set(month_list).intersection(set(excel_month)))
logger.info("交集月份如下:%s" % intersect_month)
month_data=[(str(m)+"月份日饱和度汇总",list(filter(lambda x:str(int(x[2].split('/')[1]))==m,daily_dt))) for m in intersect_month]
logger.info("all月份汇总: %s" % month_data)
# for meta in month_data:
# print(meta)
month_daily=[(it[0],reduce_month(it[1])) for it in iter(month_data)]
program_month=reduce_program_month(intersect_month)
print(program_month)
return program_month,month_daily def reduce_month(daily_dt):
persons=list(set([j[0] for j in daily_dt ]))
allperson_month=[]
for p in persons:
monthTime=[]
useable_monthTime=[]
prog=[]
man=p
pg_list = []
oneperson_onemonth=[]
for dt in daily_dt:
oneday_hour=float(dt[4]) if str(dt[4]).strip() else 0
oneday_usebaletime=float(dt[5]) if str(dt[5]).strip() else 0
if dt[0]==p:
monthTime.append(oneday_hour)
useable_monthTime.append(oneday_usebaletime)
pg_list.append(dt[3])
prog.append(pg_list)
mon_saturation=float('%.3f' % (sum(useable_monthTime) / len(monthTime)/7))
oneperson_onemonth.insert(0,man)
oneperson_onemonth.insert(1,mon_saturation)
oneperson_onemonth.insert(2,sum(monthTime))
allperson_month.append(tuple(oneperson_onemonth))
orderMonths=sorted(allperson_month,key=lambda x:x[1],reverse=True)
orderMonths.insert(0,("姓名","月人均饱和度","月生产时长"))
return orderMonths
def reduce_program_month(intersect_months):
# get init data contain ot work
datas, users, err = Dataset(getAllExcellContent(Mode=1))
Mons_progarm=[]
for m in intersect_months:
mondatas=list(filter(lambda x:str(int(x[1].split('/')[1]))==m,datas))
counter_workdate=list(set([i[1] for i in mondatas]))
logger.debug("%s月 项目工作日天数: %s" % (m,len(counter_workdate)))
logger.debug(" %s月过滤数据: %s" %(m,mondatas))
# set program
pro = list(set([i[3] for i in mondatas]))
allpg_list = []
for pg in pro:
pg_user = []
onepro = []
useable_list = []
work_time = []
for dt in datas:
if dt[3] == pg:
pg_user.append(dt[0])
one_dayhour = float(dt[5]) if str(dt[5]).strip() else 0
if dt[4] != "其它":
useable_time = one_dayhour
useable_list.append(useable_time)
work_time.append(one_dayhour)
real_user = list(set(pg_user))
onepro.append(pg)
onepro.append(float('%.3f' % (sum(useable_list) /len(counter_workdate)/7/ len(real_user))))
onepro.append(float('%.3f' % (sum(useable_list))))
onepro.append(float('%.3f' % (sum(work_time))))
allpg_list.append(tuple(onepro))
Mon_allpg_list = sorted(allpg_list, key=lambda oneRow: oneRow[1])
Mons_progarm.append((m+"月项目饱和度",Mon_allpg_list))
return Mons_progarm def init_json(): # if os.path.exists(os.getcwd()+'./config.json'):
# pass
# else:
# datas={"磨刀小分队1": ["陈权","王大伟"],"磨刀分队2":["易铭"]}
# with open(os.getcwd()+'./config.json','w+',encoding="utf-8")as f:
# json.dump(datas,f,ensure_ascii=False,indent=3)
with open(os.getcwd()+"./config.json",'r+',encoding="utf-8")as e:
init_data=json.load(e)
datas=[(k,v) for k,v in init_data.items()]
return datas
def filter_config_program(Mode):
if int(Mode)==1:
data=splitdate(Mode)
else:
data=splitdate(0)
def iter_res():
summarys=[]
for gp ,user in init_json():
get_coinfig_data=list(filter(lambda x:x[0] in user,data))
# print(get_coinfig_data)
gp_sara=sum([i[-1] for i in get_coinfig_data])/len(list(set([j[2] for j in get_coinfig_data])))/7/len(user)
summarys.append((gp,gp_sara))
return summarys
data=iter_res()
data.insert(0,("组名","组饱和度"))
return data
def sum_mutiMonth():
headers=["姓名","日期", "工作内容", "所属项目组", "工作性质", "工作时长", "用例编写量", "用例执行量", "bug提交量", "bug验证量"]
data,user,err=Dataset(getAllExcellContent(1))
data.insert(0,tuple(headers))
return data if __name__ == '__main__': create_sheet()
# sum_month()
# a=filter_config_program(0)
# print("分组结果:%s" %a)
# print(sum_mutiMonth())
excel 练习玩具统计项目组excel日报的更多相关文章
- Excel如何快速统计一列中相同数值出现的个数--数据透视表
excel如何快速统计一列中相同数值出现的个数_百度经验 --这里介绍了两种解决方式,用第一种https://jingyan.baidu.com/article/9113f81b2c16822b321 ...
- excel中使用统计列中的值在其他列出现的次数
excel中使用统计一列的中值在其他列出现的次数 =COUNTIFS($J$:$J$,K2) 解释下 $J$2 J列中的第二行到 $J$373 J列的373行 范围内 查找 k列的第二行的值 出现的 ...
- vb 导出excel生成图表统计
Private Sub btnExprot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnE ...
- [从产品角度学EXCEL 00]-为什么要关注EXCEL的本质
前言 Hello 大家好,我是尾巴,从今天开始,在这里连载<从产品角度学EXCEL>的系列文章.本文不接受无授权转载,如需转载,请先联系我,非常感谢. 与世面上的大部分EXCEL教程不同的 ...
- C#实现Excel模板导出和从Excel导入数据
午休时间写了一个Demo关于Excel导入导出的简单练习 1.窗体 2.引用office命名空间 添加引用-程序集-扩展-Microsoft.Office.Interop.Excel 3.封装的Exc ...
- c#.net对excel的操作——创建一个excel报表两个sheet就是2个表分别添加内容
添加引用:Microsoft.Office.Interop.Excel //创建excel对象,就是实例化一个excel对象 Application excel=new Appl ...
- NPOI操作excel之写入数据到excel表
在上一篇<NPOI操作excel之读取excel数据>我们把excel数据写入了datatable中,本篇就讲如何把datatable数据写入excel中. using System; u ...
- .Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) 通过MVC控制器导出导入Excel文件(可用于java SSH架构)
.Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) [原文地址] 通过MVC控制器导出导入Excel文件(可用于java SSH架构) public cl ...
- Java POI 导出EXCEL经典实现 Java导出Excel
转自http://blog.csdn.net/evangel_z/article/details/7332535 在web开发中,有一个经典的功能,就是数据的导入导出.特别是数据的导出,在生产管理或者 ...
随机推荐
- STL-C - 稳定排序
C - 稳定排序 大家都知道,快速排序是不稳定的排序方法.如果对于数组中出现的任意a[i],a[j](i<j),其中a[i]==a[j],在进行排序以后a[i]一定出现在a[j]之前,则认为该排 ...
- crowdfunding项目01——感人的错误
四十搭环境,半个小时下载jar包,网速感人,一个半小时找bug真是感动 首先SSM项目,主要功能进行增删改查 建立父工程和子工程,产生依赖关系 父工程:pom 子工程:jar.war(web工程) 错 ...
- 转载一篇棒棒的AWK教程
处理文件经常要用到awk,老是找同事帮忙,次数多了难免被吐槽orz,其实之前也有找过awk的教程,表示一直看不太懂 最近翻到了这篇教程,表示笔者真的太棒了,反正我是看一遍就懂了哈哈 剩下的只是熟悉度的 ...
- C++-POJ3321-Apple Tree[数据结构][树状数组]
树上的单点修改+子树查询 用dfn[u]和num[u]可以把任意子树表示成一段连续区间,此时结合树状数组就好了 #include <set> #include <map> #i ...
- 哥廷根: Heroes in My Heart
哥廷根: Heroes in My Heart (本篇的文字部分均出自北大未名BBS的连载 Heroes in my heart 中哥廷根的部分,作者 ukim. 话说,有任何人能够联系上 ukim ...
- IntelliJ IDEA 2017.3尚硅谷-----如何创建模块
- DP_1d1d诗人小G
显然:f[i]=min{f[j]+(s[i]-s[j]+i-j-1-l)^p} 此题可以基于决策单调优化 证明,反正我现在不打算学 实际上就是双向队列 不停弹出队头的元素,直到当前位置在队头元素最优的 ...
- java 子线程异常处理
如何在父线程中捕获来自子线程的异常呢 方法一:子线程中try... catch... 方法二:为线程设置异常处理器UncaughtExceptionHandler (异常处理也是在子线程中执行,相当于 ...
- Bugku-CTF加密篇之来自宇宙的信号(银河战队出击)
来自宇宙的信号 银河战队出击 flag格式 flag{字母小写}
- linx下跑多个tomcat
1.修改server.xml文件 <Server port="8005" shutdown="SHUTDOWN"> <Connector po ...