import struct
binf=file("A new-3g-qq.bin","rb")
binf.seek(0x7c)
binf2=file("A OLD-3g-QQ.bin","rb")
fileheader=binf2.read(0x7c)
binf2.seek(0x7c)
checkpos=5
threhold=0.01
avergelen=5
def tocomb():
binfc=file("comb.bin","wb+")
binfc.write(fileheader)
cnt=0
rec=0
v=0
while 1:
buf=binf.read(20)
if len(buf)==20:
dat=struct.unpack("fffii", buf)
cnt+=1
v+=dat[0]
if cnt>=checkpos:
v = v/cnt
if rec<checkpos:
if v> threhold:
rec+=1
else:
rec=0
if rec>=checkpos:
break
v=0
cnt=0
else:
break
cnt=0
rec=0
v=0
while 1:
buf=binf2.read(20)
if len(buf)==20:
dat=struct.unpack("fffii", buf)
cnt+=1
v+=dat[0]
if cnt>=checkpos:
v = v/cnt
if rec<checkpos:
if v> threhold:
rec+=1
else:
rec=0
if rec>=checkpos:
break
v=0
cnt=0
else:
break
val0=0
val1=0
delv=0
totalcnt=0
while 1:
buf=binf.read(20)
buf2=binf2.read(20)
cnt+=1
totalcnt=totalcnt+1.0
if len(buf)==20 and len(buf2)==20:
val0+=struct.unpack("f", buf[:4])[0]
val1+=struct.unpack("f", buf2[:4])[0]
if(cnt>=avergelen):
delv+=val0-val1
val0=val0/cnt
val1=val1/cnt
dat=struct.pack("fff", val0,val1,delv/totalcnt)
dat+='\0'*8
binfc.write(dat)
val0 = 0
val1 = 0
cnt = 0
else:
break
binfc.close()
def toaverage():
cnt=0
rec=0
v=0
while 1:
buf=binf.read(20)
if len(buf)==20:
dat=struct.unpack("fffii", buf)
cnt+=1
v+=dat[0]
if cnt>=10:
v = v/cnt
if rec<checkpos:
if v > threhold:
rec+=1
else:
rec=0
if rec>=checkpos:
print v
v=0
cnt=0
else:
break
tocomb()