-
Notifications
You must be signed in to change notification settings - Fork 1
/
extractModel.py
executable file
·46 lines (44 loc) · 1.18 KB
/
extractModel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import sys
Version=0
Lengths=[]
IDs=[]#(length, ins count, del count)
if len(sys.argv)==1 or sys.argv[1]=="-":
f=sys.stdin
else:
f=open(sys.argv[1],"r")
Former=0
for line in f:
if len(line)==0:
continue
sl=line.split()
if len(sl)==3:
if sl[0]=="RL":
Length=int(sl[1])
Count=int(sl[2])
Lengths+=[(Length,Former)]*Count
Former=Length
elif len(sl)==4:
if sl[0]=="ID":
Length=int(sl[1])
InsCount=int(sl[2])
DelCount=int(sl[3])
IDs+=[(Length,InsCount,DelCount)]
if len(sys.argv)==1 or sys.argv[1]=="-":
f.close()
Ins=0
Del=0
for ID in IDs[:3]:
Ins+=ID[0]*ID[1]
Del+=ID[0]*ID[2]
Del/=Ins/100
Ins=100
Del=int(Del+0.5)
sys.stdout.buffer.write(Version.to_bytes(4,sys.byteorder))
sys.stdout.buffer.write(Ins.to_bytes(4,sys.byteorder))
sys.stdout.buffer.write(Del.to_bytes(4,sys.byteorder))
sys.stdout.buffer.write(len(Lengths).to_bytes(4,sys.byteorder))
for Length, Former in Lengths:
sys.stdout.buffer.write(Length.to_bytes(4,sys.byteorder))
for Length, Former in Lengths:
sys.stdout.buffer.write(Former.to_bytes(4,sys.byteorder))