自动生成报表(20181120)

d1.py

#-*-coding:utf-8-*-
import time
import datetime

filename='record20180910.txt'
x1,x2,x3,x4,x5,x6=[],[],[],[],[],[]
with open(filename,'r') as f:
	lines=f.readlines()
	for line in lines:
		value=line.strip().split()
		x1.append(value[0])  #data
		x2.append(value[1])  
		x3.append(value[3])  #source
		x4.append(value[4])  #engneer
		x5.append(value[5])
		x6.append(value[23])
date=x1[0]
x33=x3[0]
x55=x4[0]
x66=x4[0]

#print name
n1=x6[1]
n2=[n1]
for i in x6:
	if i==n1:
		continue
	else:
		n1=i
		n2.append(i)
n22=[]
n222=[]
for i in n2:
	j=i.split('&')
	n22.append(j)
for i in range(len(n22)):
	for j in n22[i]:
		n222.append(j)
name={'L,M':'李明','xu':'旭'}
n=[]
for i in range(len(n222)):
	tmp=name.get(n222[i])
	n.append(tmp)

#find time of BZY
TT1=[]
a,b='L134','W51D'
for i in range(len(x3)):
	if x3[i]==a:
		TT1.append(x2[i])
TT2=[]
for i in range(len(x3)):
	if x3[i]==b:
		TT2.append(x2[i])
		c=x3[i]
	else:
		d='c' in dir()
		if d==True:
			break
		else:
			continue
TT=TT1+TT2
if TT:
	Ta=TT[0]
	Tb=TT[len(TT)-1]
	timeStruct=time.strptime(Ta,"%H:%M:%S")
	strtime1 = time.strftime("%H:%M", timeStruct)
	timeStruct=time.strptime(Tb,"%H:%M:%S")
	strtime2 = time.strftime("%H:%M", timeStruct)
	strtime=strtime1+'-'+strtime2
else:
	strtime='STOP'
 
#find time of STOP
s1=x3[0]
tr1=x2[0]
s2=[s1]
tr2=[tr1]
tr22=[]
for i in range(len(x3)):
	if x3[i]==s1:
		continue
	else:
		s1=x3[i]
		s2.append(x3[i])
		tr2.append(x2[i])
		tr22.append(x2[i])
 
s0='STOP'
Trr=[]
for i in range(len(s2)):
	if s2[i]==s0:
		start=tr2[i]
		try:
			end=tr22[i]
		except:
			end=x2[-1]
		strTime1=datetime.datetime.strptime(start,"%H:%M:%S")
		strTime2=datetime.datetime.strptime(end,"%H:%M:%S")
		strTime=(strTime2-strTime1).seconds
		if strTime>=600:
			timeStruct1=time.strptime(start,"%H:%M:%S")
			timeStruct2=time.strptime(end,"%H:%M:%S")
			strTime1=time.strftime("%H:%M", timeStruct1)
			strTime2=time.strftime("%H:%M", timeStruct2)
			trr=strTime1+'-'+strTime2
			Trr.append(trr)
	else:
		continue
 
#yin he hua juan
sta1=x2[0]
try:
	end1=strtime1
	sta2=strtime2
except:
	end1='17:00:00'
	sta2='18:00:00'
end2=x2[-1]
timeStruct=time.strptime(sta1,"%H:%M:%S")
sta1=time.strftime("%H:%M", timeStruct)
timeStruct=time.strptime(end2,"%H:%M:%S")
end2=time.strftime("%H:%M", timeStruct)
Tyh1=sta1+'-'+end1
Tyh2=sta2+'-'+end2
Tyh=[Tyh1,Tyh2]

##################################################################################################

filename='slrecord20180910.asc'
x11,x13=[],[]
with open(filename,'r') as f:
	lines=f.readlines()
	for line in lines:
		value=line.strip().split()
		x11.append(value[0])
		x13.append(value[2])
 
#delete chong fu data
k1=x13[0]
t1=x11[0]
k2=[k1]
t2=[t1]
for i in range(len(x13)):
	if x13[i]==k1:
		continue
	else:
		k1=x13[i]
		aa=x11[i]
		timeStruct=time.strptime(aa,"%H:%M:%S")
		strTime=time.strftime("%H:%M", timeStruct)
		k2.append(x13[i])
		t2.append(strTime)
 
#time lian jie
T1=t2
T2=[]
for i in range(len(t2)):
	if i==0:
		continue
	else:
		T2.append(t2[i])
T2.append(' ')
T3=[]
for i in range(len(T1)):
		TT=T1[i]+'-'+T2[i]
		T3.append(TT)

#find time of bei ji qu
tt=[]
for i in range(len(k2)):
	if k2[i]=='G120+20':
		tt.append(T3[i])
if tt:
	pass
else:
	tt=['STOP']
 
#ke ti time and name
kk=[]
tk=[]
for i in range(len(k2)):
	if k2[i].startswith('18')==True:
		tk.append(T3[i])
		kk.append(k2[i])
	else:
		continue 
if tk:
	if len(tk[0])>8:
		pass
	else:
		a=tk[0]+strTime1
		tk[0]=a
	if len(tk[(len(tk))-1])>8:
		pass
	else:
		timeStruct=time.strptime(x11[-1],"%H:%M:%S")
		zz=time.strftime("%H:%M", timeStruct)
		b=tk[(len(tk))-1]+zz
		tk[(len(tk))-1]=b
else:
	tk=['NO']

22.py

#-*-coding:utf-8-*-
import sys
import docx
from docx.enum.text import WD_ALIGN_PARAGRAPH
import d1
reload(sys)
sys.setdefaultencoding('utf-8')

doc=docx.Document()
paragraph=doc.add_paragraph(u'状况')
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER

table1=doc.add_table(rows=2,cols=1,style='Table Grid')
v1=d1.date
v1=str(v1)
hdr_cells=table1.rows[0].cells
hdr_cells[0].text=u'时间:'+v1
hdr_cells=table1.rows[1].cells
hdr_cells[0].text=u'名称:1 meter'

table2=doc.add_table(rows=2,cols=2,style='Table Grid')  #tian jia table
hdr_cells=table2.rows[0].cells
hdr_cells[0].text=u'总值班:李明'
hdr_cells[1].text=u'助手:张三 李四'
hdr_cells=table2.rows[1].cells
hdr_cells[0].text=u'开机时间:00:00-24:00'
hdr_cells[1].text=u'关机时间:00:00-00:00'

table3=doc.add_table(rows=7,cols=1,style='Table Grid')
v3=d1.n
v3=', '.join(v3)
hdr_cells=table3.rows[0].cells
#hdr_cells[0].text=u'人员:'+v31+'  '+v32+'  '+v33+'  '+v34+'  '+v35+'  '+v36
hdr_cells[0].text=u'人员:'+v3
hdr_cells=table3.rows[1].cells
hdr_cells[0].text=u'天气状况:'
hdr_cells=table3.rows[2].cells
hdr_cells[0].text=u'运行环境状况:正常'
hdr_cells=table3.rows[3].cells
hdr_cells[0].text=u'设备运行状况:正常'
hdr_cells=table3.rows[4].cells
hdr_cells[0].text=u'观测课题名称:sources'
hdr_cells=table3.rows[5].cells
hdr_cells[0].text=u'课题负责人:李明'
hdr_cells=table3.rows[6].cells
hdr_cells[0].text=u'有效观测时间:'

table4=doc.add_table(rows=5,cols=6,style='Table Grid')  
v41=d1.x33
v42=d1.x55
v43=d1.x66
v41=str(v41)
v42=str(v42)
v43=str(v43)
hdr_cells=table4.rows[0].cells  #huo qu line 0 suo you dan yuan ge
hdr_cells[0].text='Source'
hdr_cells[1].text='R.A.'
hdr_cells[2].text='Dec.'
hdr_cells[3].text='Source'
hdr_cells[4].text='R.A.'
hdr_cells[5].text='Dec.'
hdr_cells=table4.rows[1].cells
hdr_cells[0].text=v41
hdr_cells[1].text=v42
hdr_cells[2].text=v43

table5=doc.add_table(rows=1,cols=1,style='Table Grid')
hdr_cells=table5.rows[0].cells
hdr_cells[0].text=u'获取资料质量评估:'

table6=doc.add_table(rows=2,cols=3,style='Table Grid')
hdr_cells=table6.rows[0].cells
hdr_cells[0].text='R.M.S'
hdr_cells[1].text='TA'
hdr_cells[2].text='VEL'
hdr_cells=table6.rows[1].cells
hdr_cells[0].text=u'差'
hdr_cells[1].text=u'优'
hdr_cells[2].text=u'优'

table7=doc.add_table(rows=5,cols=1,style='Table Grid')
v71=d1.Tyh
v711=v71[0]
v712=v71[1]

v721=d1.tk
v721=', '.join(v721)
v722=d1.kk
v722=', '.join(v722)
v73=d1.tt
v73=v73[0]
v74=d1.strtime
v75=d1.Trr
v75=', '.join(v75)
hdr_cells=table7.rows[0].cells
hdr_cells[0].text=u'故障描述:'
hdr_cells=table7.rows[1].cells
hdr_cells[0].text=u'故障发生时间:'
hdr_cells=table7.rows[2].cells
hdr_cells[0].text=u'故障排除措施:'
hdr_cells=table7.rows[3].cells
hdr_cells[0].text=u'维修人员:'
hdr_cells=table7.rows[4].cells
hdr_cells[0].text=u'开展的主要工作:'+\
'\n(1)'+v711+','+v712+u',计划;'+\
'\n(2)'+v721+u',进行课题观测,'+u'课题编号为:'+v722+'—— ***'+';'+\
'\n(3)'+v73+u',北极区观测;'+\
'\n(4)'+v74+u',BZY测试;'+\
'\n(5)'+v75+u',天气差,暂停观测;'

doc.save('2.docx')

 

你可能感兴趣的:(python)