Skip to content
Snippets Groups Projects
Commit a2813bf7 authored by am0ebe's avatar am0ebe
Browse files

add time since last detection col

parent cd17c17f
Branches new-data
No related tags found
No related merge requests found
...@@ -41,8 +41,8 @@ def squash(data): ...@@ -41,8 +41,8 @@ def squash(data):
for line in data: for line in data:
if line[0] == '#': if line[0] == '#':
if line.startswith("#timestamp"): if line.startswith("#timestamp"):
header="#begin, end, dur," + DELIM.join(line.split(',')[OMIT_COL_BEGIN:]) global header
filtered.append(header) header="#begin, end, dur, last detect, PXE," + DELIM.join(line.split(',')[OMIT_COL_BEGIN:])
continue continue
l = line.split(DELIM) l = line.split(DELIM)
...@@ -91,7 +91,7 @@ def squash(data): ...@@ -91,7 +91,7 @@ def squash(data):
r[1] = r[0] r[1] = r[0]
ncut += r[2] ncut += r[2]
r[2] = 0 r[2] = 0
filtered.append(DELIM.join(map(str,r))) filtered.append(DELIM.join(map(str,r)))
if cutOff: if cutOff:
...@@ -99,11 +99,42 @@ def squash(data): ...@@ -99,11 +99,42 @@ def squash(data):
return filtered return filtered
def add_lastDetect_and_PXE( data ):
"add 'time since last detection' and 'patch-Cross-Event'"
OUT_COL_END=1
OUT_COL_LASTDETECT=3
OUT_COL_PXE=4
known = {} #{tag: line}
for i,line in enumerate(data):
l = line.split(DELIM)
tag = l[ OUT_COL_TAG ]
if tag not in known:
l.insert(OUT_COL_LASTDETECT,"NA")
# l.insert(OUT_COL_PXE,"TODO")
else:
last_end = int(known[tag][OUT_COL_END])
this_start = int(l[OUT_COL_END])
l.insert(OUT_COL_LASTDETECT,this_start - last_end)
known[tag] = l
data[i] = DELIM.join(map(str,l))
return data
def write(outFile, data): def write(outFile, data):
print(f"writing to {outFile}") print(f"writing to {outFile}")
with open(outFile, "w") as f: with open(outFile, "w") as f:
f.writelines(header)
f.writelines(data) f.writelines(data)
# cmd_compress=f"tar -zcvf {outFile}.tgz {outFile}" # ">/dev/null 2>/dev/null" # cmd_compress=f"tar -zcvf {outFile}.tgz {outFile}" # ">/dev/null 2>/dev/null"
...@@ -115,8 +146,11 @@ def main(filename): ...@@ -115,8 +146,11 @@ def main(filename):
data = f.readlines() data = f.readlines()
data = squash( data ) data = squash( data )
write(filename + "-filtered-squashed", data)
data = add_lastDetect_and_PXE( data )
write(filename + "-filtered", data) write(filename + "-filtered-added", data)
if __name__ == "__main__" : if __name__ == "__main__" :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment