jason_original / wiki /2007 /sample_trace.py
1a1a11a's picture
Add files using upload-large-folder tool
8dc315b verified
raw
history blame contribute delete
784 Bytes
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)