#!/usr/bin/env python
import sys
import datetime
org_list=[] #存储某个订单在生命周期内所经过的所有站点
dict={}
subdict={}
subdict1={}
subdict2={}
subdict3={}
org_id=''
s_id=''
tag='0' #'0'表示到件未签收,‘1’表示到件已经签收
type='1' #‘1’表示24小时 ;‘2’表示48小时;‘3’表示72小时
last_org=''
time=sys.argv[1]
one_BeginTime=datetime.datetime.strptime(time+' 00:00:00',"%Y-%m-%d %H:%M:%S")
two_BeginTime=one_BeginTime + datetime.timedelta(-1)
three_BeginTime=one_BeginTime + datetime.timedelta(-2)
endTime=datetime.datetime.strptime(time+' 23:59:59',"%Y-%m-%d %H:%M:%S")
come='91a70eb4b12e49e99b08ce9d157cd297'
sign='9891cdfe1aed428b97d318d19a6999bd'
send='a4c2cdaeba6444739fda9d1778e74445'
disp='8d5a8e9d942b482a8a4d94baa36abb47'
str="%Y-%m-%d %H:%M:%S"
i=0
def judge():
i=len(org_list)-1
if i>=0:
last_org=org_list[i]#得到最后一个站点
if dict.has_key(last_org):
subdict=dict.get(last_org)#得到一个订单在最后一个站点的所有扫描状态
if subdict.has_key(sign):
if datetime.datetime.strptime(subdict.get(sign),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:#如果有签收扫描,且在时间窗内
if subdict.has_key(come):#有到件扫描
if datetime.datetime.strptime(subdict.get(come),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#到件扫描在时间窗内
type='1'
tag='1'
print '\t'.join([org_list[i],time,type,tag])
else:
if i>=1 and dict.has_key(org_list[i-1]):#无到件扫描(可能漏扫),找到上一个站点
subdict1=dict.get(org_list[i-1])
if subdict1.has_key(send) and datetime.datetime.strptime(subdict1.get(send),str)>one_BeginTime and datetime.datetime.strptime(subdict1.get(send),str)<endTime:#找到发件扫描记录,并且判断扫描时间是否在时间窗内
tag='1'
type='1'
print '\t'.join([org_list[i],time,type,tag])
if datetime.datetime.strptime(subdict.get(sign),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:
if subdict.has_key(come):#有到件扫描
if datetime.datetime.strptime(subdict.get(come),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#到件扫描在时间窗内
type='2'
tag='1'
print '\t'.join([org_list[i],time,type,tag])
else:
if i>=1 and dict.has_key(org_list[i-1]):#无到件扫描(可能漏扫),找到上一个站点
subdict2=dict.get(org_list[i-1])
if subdict2.has_key(send) and datetime.datetime.strptime(subdict2.get(send),str)>two_BeginTime and datetime.datetime.strptime(subdict2.get(send),str)<endTime:#找到发件扫描记录,并且判断扫描时间是否在时间窗内
tag='1'
type='2'
print '\t'.join([org_list[i],time,type,tag])
if datetime.datetime.strptime(subdict.get(sign),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:
if subdict.has_key(come):#有到件扫描
if datetime.datetime.strptime(subdict.get(come),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#到件扫描在时间窗内
type='3'
tag='1'
print '\t'.join([org_list[i],time,type,tag])
else:
if i>=1 and dict.has_key(org_list[i-1]):#无到件扫描(可能漏扫),找到上一个站点
subdict3=dict.get(org_list[i-1])
if subdict3.has_key(send) and datetime.datetime.strptime(subdict3.get(send),str)>three_BeginTime and datetime.datetime.strptime(subdict3.get(send),str)<endTime:#找到发件扫描记录,并且判断扫描时间是否在时间窗内
tag='1'
type='3'
print '\t'.join([org_list[i],time,type,tag])
elif not subdict.has_key(sign) and subdict.has_key(come):
if datetime.datetime.strptime(subdict.get(come),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#只有到件扫描,没有签收扫描
tag='0'
type='1'
print '\t'.join([org_list[i],time,type,tag])
if datetime.datetime.strptime(subdict.get(come),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#只有到件扫描,没有签收扫描
tag='0'
type='2'
print '\t'.join([org_list[i],time,type,tag])
if datetime.datetime.strptime(subdict.get(come),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#只有到件扫描,没有签收扫描
tag='0'
type='3'
print '\t'.join([org_list[i],time,type,tag])
if __name__=="__main__":
for line in sys.stdin:
sid,orgid,scandate,scantypeid,areaid=line.strip().split('\t')
if orgid !='null':
if len(org_list)==0: #初始org_list为空
org_id=orgid
s_id=sid
org_list.append(orgid) #站点放进org_list
subdict[scantypeid]=scandate
dict[orgid]=subdict.copy()
elif s_id==sid and org_id==orgid: #站点相同
subdict=dict.get(orgid)
if not subdict.has_key(scantypeid):
subdict[scantypeid]=scandate
dict[orgid]=subdict.copy()
elif s_id==sid and org_id!=orgid: #站点不同
org_id=orgid
org_list.append(orgid)
subdict.clear()
subdict[scantypeid]=scandate
dict[orgid]=subdict.copy()
elif s_id != sid: #订单号不同,开始判定是否输出
s_id=sid
org_id=orgid
judge()
org_list=[]
dict.clear()
subdict.clear()
org_list.append(orgid)
subdict[scantypeid]=scandate
dict[orgid]=subdict.copy()
if len(org_list)>1:
judge()
import sys
import datetime
org_list=[] #存储某个订单在生命周期内所经过的所有站点
dict={}
subdict={}
subdict1={}
subdict2={}
subdict3={}
org_id=''
s_id=''
tag='0' #'0'表示到件未签收,‘1’表示到件已经签收
type='1' #‘1’表示24小时 ;‘2’表示48小时;‘3’表示72小时
last_org=''
time=sys.argv[1]
one_BeginTime=datetime.datetime.strptime(time+' 00:00:00',"%Y-%m-%d %H:%M:%S")
two_BeginTime=one_BeginTime + datetime.timedelta(-1)
three_BeginTime=one_BeginTime + datetime.timedelta(-2)
endTime=datetime.datetime.strptime(time+' 23:59:59',"%Y-%m-%d %H:%M:%S")
come='91a70eb4b12e49e99b08ce9d157cd297'
sign='9891cdfe1aed428b97d318d19a6999bd'
send='a4c2cdaeba6444739fda9d1778e74445'
disp='8d5a8e9d942b482a8a4d94baa36abb47'
str="%Y-%m-%d %H:%M:%S"
i=0
def judge():
i=len(org_list)-1
if i>=0:
last_org=org_list[i]#得到最后一个站点
if dict.has_key(last_org):
subdict=dict.get(last_org)#得到一个订单在最后一个站点的所有扫描状态
if subdict.has_key(sign):
if datetime.datetime.strptime(subdict.get(sign),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:#如果有签收扫描,且在时间窗内
if subdict.has_key(come):#有到件扫描
if datetime.datetime.strptime(subdict.get(come),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#到件扫描在时间窗内
type='1'
tag='1'
print '\t'.join([org_list[i],time,type,tag])
else:
if i>=1 and dict.has_key(org_list[i-1]):#无到件扫描(可能漏扫),找到上一个站点
subdict1=dict.get(org_list[i-1])
if subdict1.has_key(send) and datetime.datetime.strptime(subdict1.get(send),str)>one_BeginTime and datetime.datetime.strptime(subdict1.get(send),str)<endTime:#找到发件扫描记录,并且判断扫描时间是否在时间窗内
tag='1'
type='1'
print '\t'.join([org_list[i],time,type,tag])
if datetime.datetime.strptime(subdict.get(sign),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:
if subdict.has_key(come):#有到件扫描
if datetime.datetime.strptime(subdict.get(come),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#到件扫描在时间窗内
type='2'
tag='1'
print '\t'.join([org_list[i],time,type,tag])
else:
if i>=1 and dict.has_key(org_list[i-1]):#无到件扫描(可能漏扫),找到上一个站点
subdict2=dict.get(org_list[i-1])
if subdict2.has_key(send) and datetime.datetime.strptime(subdict2.get(send),str)>two_BeginTime and datetime.datetime.strptime(subdict2.get(send),str)<endTime:#找到发件扫描记录,并且判断扫描时间是否在时间窗内
tag='1'
type='2'
print '\t'.join([org_list[i],time,type,tag])
if datetime.datetime.strptime(subdict.get(sign),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(sign),str)<endTime:
if subdict.has_key(come):#有到件扫描
if datetime.datetime.strptime(subdict.get(come),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#到件扫描在时间窗内
type='3'
tag='1'
print '\t'.join([org_list[i],time,type,tag])
else:
if i>=1 and dict.has_key(org_list[i-1]):#无到件扫描(可能漏扫),找到上一个站点
subdict3=dict.get(org_list[i-1])
if subdict3.has_key(send) and datetime.datetime.strptime(subdict3.get(send),str)>three_BeginTime and datetime.datetime.strptime(subdict3.get(send),str)<endTime:#找到发件扫描记录,并且判断扫描时间是否在时间窗内
tag='1'
type='3'
print '\t'.join([org_list[i],time,type,tag])
elif not subdict.has_key(sign) and subdict.has_key(come):
if datetime.datetime.strptime(subdict.get(come),str)>one_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#只有到件扫描,没有签收扫描
tag='0'
type='1'
print '\t'.join([org_list[i],time,type,tag])
if datetime.datetime.strptime(subdict.get(come),str)>two_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#只有到件扫描,没有签收扫描
tag='0'
type='2'
print '\t'.join([org_list[i],time,type,tag])
if datetime.datetime.strptime(subdict.get(come),str)>three_BeginTime and datetime.datetime.strptime(subdict.get(come),str)<endTime:#只有到件扫描,没有签收扫描
tag='0'
type='3'
print '\t'.join([org_list[i],time,type,tag])
if __name__=="__main__":
for line in sys.stdin:
sid,orgid,scandate,scantypeid,areaid=line.strip().split('\t')
if orgid !='null':
if len(org_list)==0: #初始org_list为空
org_id=orgid
s_id=sid
org_list.append(orgid) #站点放进org_list
subdict[scantypeid]=scandate
dict[orgid]=subdict.copy()
elif s_id==sid and org_id==orgid: #站点相同
subdict=dict.get(orgid)
if not subdict.has_key(scantypeid):
subdict[scantypeid]=scandate
dict[orgid]=subdict.copy()
elif s_id==sid and org_id!=orgid: #站点不同
org_id=orgid
org_list.append(orgid)
subdict.clear()
subdict[scantypeid]=scandate
dict[orgid]=subdict.copy()
elif s_id != sid: #订单号不同,开始判定是否输出
s_id=sid
org_id=orgid
judge()
org_list=[]
dict.clear()
subdict.clear()
org_list.append(orgid)
subdict[scantypeid]=scandate
dict[orgid]=subdict.copy()
if len(org_list)>1:
judge()