import xlwings as xw
import numpy
app = xw.App(visible=True,add_book=False)
#打开lineDetial_20211213174707699表处理数据
lineDetial_20211213174707699 = app.books.open('lineDetial_20211213174707699.xlsx')
lineDetial_20211213174707699Sheet1 = lineDetial_20211213174707699.sheets['线路信息导出']
lineDetial_20211213174707699Sheet1GongDianJu = lineDetial_20211213174707699Sheet1.range('A2','A7009').value
lineDetial_20211213174707699Sheet1XianLuMingCheng = lineDetial_20211213174707699Sheet1.range('B2','B7009').value
lineDetial_20211213174707699Sheet1ZongChangDu = lineDetial_20211213174707699Sheet1.range('H2','H7009').value
lineDetial_20211213174707699Sheet1ZongChangDuArray = numpy.array(lineDetial_20211213174707699Sheet1ZongChangDu)
#print(lineDetial_20211213174707699Sheet1ZongChangDuArray)
for i in range(0,7008):tempLineDetial = numpy.array([lineDetial_20211213174707699Sheet1XianLuMingCheng[i],lineDetial_20211213174707699Sheet1ZongChangDu[i]])#print(tempLineDetial)
#print(lineDetial_20211213174707699Sheet1GongDianJu)
#print(lineDetial_20211213174707699Sheet1ZongChangDu)
#print(lineDetial_20211213174707699Sheet1XianLuMingCheng)
#打开2021_01_01-2021_12_13-任务统计表表处理数据
taskStatistics = app.books.open('2021_01_01-2021_12_13-任务统计表.xlsx')
taskStatisticsSheet1 = taskStatistics.sheets['统计报表']
taskStatisticsSheet2 = taskStatistics.sheets['缺陷数据1']
taskStatisticsSheet3 = taskStatistics.sheets['缺陷数据2']
taskStatisticsSheet3GongDianJu = taskStatisticsSheet3.range('A2','A8939').value
taskStatisticsSheet3XianLu = taskStatisticsSheet3.range('E2','E8939').valuevector = numpy.array(taskStatisticsSheet3GongDianJu)
vectorXianLu = numpy.array(taskStatisticsSheet3XianLu)
vectorLineXianLu = numpy.array(lineDetial_20211213174707699Sheet1XianLuMingCheng)
vectorLineXianluChangDuArray = numpy.array(lineDetial_20211213174707699Sheet1ZongChangDu)
#去掉数组中重复的元素,统计线路的种类个数
vectorXianLuUnique = numpy.unique(taskStatisticsSheet3XianLu)
#print(numpy.size(vectorXianLuUnique))
vectorXianLuUnique = numpy.array(vectorXianLuUnique)
#print(vectorXianLuUnique)
#计算各个线路的故障数
for i in vectorXianLuUnique:temp = numpy.where(vectorXianLu == i)tempL = numpy.where(vectorLineXianLu == i)tempU = numpy.where(vectorXianLuUnique == i)#print(tempU,'unique',i)#print(tempL,'Line')tempLong = vectorLineXianluChangDuArray[tempL[0]]resultVector = numpy.array([i,'故障数量',numpy.size(temp),'线路长度',tempLong,'故障率',numpy.size(temp)/tempLong])print(resultVector)
tempVector = numpy.zeros((427,2))
for i in range(0,427):temp = numpy.where(vectorXianLu == vectorXianLuUnique[i])tempVector[i][0] = itempVector[i][1] = numpy.size(temp)
#print(tempVector)
#for i in range(0, 7008):#tempXianLuMingCheng = lineDetial_20211213174707699Sheet1XianLuMingCheng[i]#tempLineDetial = lineDetial_20211213174707699Sheet1ZongChangDu[i]
#print(lineDetial_20211213174707699Sheet1XianLuMingCheng)
#print(numpy.size(lineDetial_20211213174707699Sheet1XianLuMingCheng))
tempGuZhangLv = numpy.zeros((7009,2))
for i in range(0,7008):tempGuZhangLv[i][0] = itempGuZhangLv[i][1] = lineDetial_20211213174707699Sheet1ZongChangDuArray[i]
#print(tempGuZhangLv)
for i in range(0,7008): #遍历lineDetial表中的数据t = lineDetial_20211213174707699Sheet1XianLuMingCheng[i]#print(t)for j in range(0,427):t2 = vectorXianLuUnique[j]
lineDetial_20211213174707699.save()
lineDetial_20211213174707699.close()
taskStatistics.save()
taskStatistics.close()
app.quit()