File size: 784 Bytes
8dc315b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import os, sys

def sample_trace(ifilepath, ofilepath, sample_ratio_inv): 
    ifile = open(ifilepath, "r")
    ofile = open(ofilepath, "w")

    for line in ifile:
        try:
            timestamp, obj_id = line.strip("\n").split(",")
        except Exception as e:
            print(e, line)
            continue

        if int(obj_id) % sample_ratio_inv == 0:
            ofile.write("{},{},{}\n".format(timestamp, obj_id, 1))

    ifile.close()
    ofile.close()

if __name__ == "__main__":
    if len(sys.argv) != 4:
        print("Usage: python3 sample_trace.py ifilepath ofilepath sample_ratio_inv")
        exit(0)

    ifilepath = sys.argv[1]
    ofilepath = sys.argv[2]
    sample_ratio_inv = int(sys.argv[3])

    sample_trace(ifilepath, ofilepath, sample_ratio_inv)