統計觀測數據時間段(20180926)

d26.py

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

filename='record20180919.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])  #date
        x2.append(value[1])  #time
        x3.append(value[3])  #source
        x4.append(value[4])  #RA
        x5.append(value[5])  #DEC
        x6.append(value[23]) #engneer
date=x1[0]
x33=x3[0]
x44=x4[0]
x55=x5[0]

filename='slrecord20180919.asc'
y2,y3=[],[]
with open(filename,'r') as f:
    lines=f.readlines()
    for line in lines:
        value=line.strip().split()
        y2.append(value[2])
        y3.append(value[3])
 
#match ke ti hao
x=[]
y=[]
for i in range(len(y3)):
    if not y3[i] in y:
        x.append(y2[i])
        y.append(y3[i])
 
k=[]
for i in x3:
    if (i=='STOP' or i not in y):
        k.append('STOP')
    for j in range(len(y)):
        if i==y[j]:
            k.append(x[j])
#print k

#qu dao minute
tx=[]
for i in x2:
    timeStruct=time.strptime(i,"%H:%M:%S")
    strTime=time.strftime("%H:%M", timeStruct)
    tx.append(strTime)
 
#########################################################

#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={'Ming Li':'李明','xu':'旭'。。。}
n=[]
for i in range(len(n222)):
    tmp=name.get(n222[i])
    n.append(tmp)
 
#find time of STOP
s1=k[0]
tr1=tx[0]
s2=[s1]
tr2=[tr1]
tr22=[]
for i in range(len(k)):
    if k[i]==s1:
        continue
    else:
        s1=k[i]
        s2.append(k[i])
        tr2.append(tx[i])
        tr22.append(tx[i])
s0='STOP'
Ts=[]
Tstop=[]
for i in range(len(s2)):
    if s2[i]==s0:
        start=tr2[i]
        try:
            end=tr22[i]
        except:
            end=x2[-1]
            timeStruct=time.strptime(end,"%H:%M:%S")
            end=time.strftime("%H:%M", timeStruct)
        strTime1=datetime.datetime.strptime(start,"%H:%M")
        strTime2=datetime.datetime.strptime(end,"%H:%M")
        strTime=(strTime2-strTime1).seconds
        if strTime>1200:
            trr=start+'-'+end
            Ts.append(start)
#            Ts.append(end)
            Tstop.append(trr)
    else:
        continue
#print Ts,Tstop
 
#find time of BZY
start='16:30'
end='18:30'
m='0:00'
strTime1=datetime.datetime.strptime(start,"%H:%M")
strTime2=datetime.datetime.strptime(end,"%H:%M")
strTime3=datetime.datetime.strptime(m,"%H:%M")
Time1=(strTime1-strTime3).seconds
Time2=(strTime2-strTime3).seconds
TT=[]
for i in range(len(tx)):
    strTime=datetime.datetime.strptime(tx[i],"%H:%M")
    Time=(strTime-strTime3).seconds
    if (Time>Time1 and Time<Time2):
        a,b='BZY','SKYDIP'
        if k[i]==a or k[i]==b:
            TT.append(tx[i])
if TT:
    A=[TT[0]]
    for i in range(len(TT)):
        for j in Ts:
            if j==TT[i]:
                aa=TT[i-1]
                bb=TT[i]
                A.append(a)
                A.append(b)
    A.append(TT[-1])
 
#print A
    c=[A[i:i+2] for i in range(0,len(A),2)]
    B=[]
    for i in c:
        b=i[0]+'-'+i[-1]
        B.append(b)
else:
    B=['none']
#print B

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

#find time of bei ji qu
tb=[]
for i in range(len(k)):
    if (k[i]=='G120+20' or k[i]=='F120+20'):
        tb.append(tx[i])
 
#cuo kai shi jian
tb1=tb[0:len(tb)-1]
tb2=[]
for i in range(len(tb)):
    if i==0:
        continue
    else:
        tb2.append(tb[i])
 
#caculate time above 3min
if tb2:
    taa=[tb1[0]]
    for i in range(len(tb2)):
        sg=tb1[i]
        eg=tb2[i]
        sg=datetime.datetime.strptime(sg,"%H:%M")
        eg=datetime.datetime.strptime(eg,"%H:%M")
        delta=(eg-sg).seconds
        if delta>900:
            taa.append(tb1[i])
            taa.append(tb2[i])
    taa.append(tb2[-1])
    c=[taa[i:i+2] for i in range(0,len(taa),2)]
    tbb=[]
    for i in c:
        b=i[0]+'-'+i[-1]
        tbb.append(b)
else:
    tbb=['none']
#print tbb

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

#find ke ti of time and name
tk=[]
kk=[]
for i in range(len(k)):
    if k[i].startswith('18')==True or k[i].startswith('17')==True:
        tk.append(tx[i])
        kk.append(k[i])
if kk:
    k0=kk[0]
    kt=[k0]
    for i in kk:
        if i==k0:
            continue
        else:
            k0=i
            kt.append(i)
else:
    kt=['none']
#print kt
 
#cuo kai shi jian
tk1=tk[0:len(tk)-1]
tk2=[]
for i in range(len(tk)):
    if i==0:
        continue
    else:
        tk2.append(tk[i])
 
#caculate time above 3min
if tk1:
    tkk=[tk1[0]]
else:
    pass
for i in range(len(tk2)):
    sg=tk1[i]
    eg=tk2[i]
    sg=datetime.datetime.strptime(sg,"%H:%M")
    eg=datetime.datetime.strptime(eg,"%H:%M")
    delta=(eg-sg).seconds
    if delta>1800:
        tkk.append(tk1[i])
        tkk.append(tk2[i])
if tk2:
    tkk.append(tk2[-1])
else:
    tkk=[]
if tkk:
    c=[tkk[i:i+2] for i in range(0,len(tkk),2)]
    Tk=[]
    for i in c:
        b=i[0]+'-'+i[-1]
        Tk.append(b)
else:
    Tk=['none']
#print Tk
 
#############################################
 
#find time of galactic survey
ty=[]
tyyy=[]
for i in range(len(k)):
    if (k[i].startswith('G')==True or k[i].startswith('F')==True) and (k[i]!='G120+20' and k[i]!='F120+20') or (k[i].startswith('N')==True or k[i].startswith('W')==True or k[i].startswith('I')==True or k[i].startswith('L')==True or k[i].startswith('W')==True or k[i].startswith('s')==True):
        ty.append(tx[i])
 
#cuo kai shi jian
ty1=ty[0:len(ty)-1]
ty2=[]
for i in range(len(ty)):
    if i==0:
        continue
    else:
        ty2.append(ty[i])
 
#caculate time above 10min
tyy=[ty1[0]]
for i in range(len(ty2)):
    sg=ty1[i]
    eg=ty2[i]
    sg=datetime.datetime.strptime(sg,"%H:%M")
    eg=datetime.datetime.strptime(eg,"%H:%M")
    delta=(eg-sg).seconds
    if delta>600:
        tyy.append(ty1[i])
        tyy.append(ty2[i])
tyy.append(ty2[-1])
try:
    for i in A:
        if i in tyy:
            tyy.remove(i)
except:
    pass
c=[tyy[i:i+2] for i in range(0,len(tyy),2)]
Ty=[]
for i in c:
    b=i[0]+'-'+i[-1]
    Ty.append(b)
#print Ty

_____________________________________________________________________________________________________

26.py

#-*-coding:utf-8-*-
import sys
import docx
from docx.enum.text import WD_ALIGN_PARAGRAPH
import d26
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=d26.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 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=d26.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=d26.x33
v42=d26.x44
v43=d26.x55
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=d26.Ty
v71=', '.join(v71)
v721=d26.Tk
v721=', '.join(v721)
v722=d26.kt
v722=', '.join(v722)
v73=d26.tbb
v73=', '.join(v73)
v74=d26.B
v74=', '.join(v74)
v75=d26.Tstop
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)'+v71+u',計劃;'+\
'\n(2)'+v721+u',進行課題觀測,'+u'課題編號爲:'+v722+'--***'+';'+\
'\n(3)'+v73+u',北極區觀測;'+\
'\n(4)'+v74+u',BZY測試;'+\
'\n(5)'+v75+u',天氣差,暫停觀測;'

doc.save('26.docx')
 

 

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