自動生成報表(改2)

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={'Y.X.ZUO':'左營喜','xuguo':'張旭國','xgzhang':'張旭國','xgzhang':'張旭國','zqli':'李振強','minwang':'王敏','mingwang':'王敏','lijibin':'李積斌','hlzhang':'張海龍','fjjin':'金鳳娟','yangli':'李陽','yasngli':'李陽','jxsun':'孫繼先','yxzhang':'張永興','pingyan':'顏萍','pinyan':'顏萍','bgju':'巨秉剛','kunyan':'顏昆','drlu':'逯登榮','syjin':'靳生玉','csluo':'羅春盛'}
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'青海觀測站13.7米望遠鏡運行狀況日報表')
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'望遠鏡名稱:13.7米毫米波射電望遠鏡'

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'觀測課題名稱:銀河畫卷'
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')

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章