-
Notifications
You must be signed in to change notification settings - Fork 41
/
freq.py
executable file
·48 lines (44 loc) · 1.39 KB
/
freq.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
47
import numpy as np
import matplotlib.pyplot as plt
import sys
import argparse
parser = argparse.ArgumentParser(description="Generate time domain and frequency domain plots of the input data.")
parser.add_argument('-w','--window', default=60.0, type=float, dest="window", help="Define the time window for the time domain histogram and frequency analysis.")
parser.add_argument('-f', '--file', default=None, type=str, dest="output_filename", help="Output the graph to a file rather than to the screen.")
window = parser.parse_args().window
output_filename = parser.parse_args().output_filename
bin=0
startingTime = 0.0
endingTime = 0.0
binLimit=-1.0
samples = 0
timeDomain = []
for line in sys.stdin:
(timestamp, host)=line.split(" ")
ts = float(timestamp)
if(binLimit == -1.0):
startingTime = ts
binLimit = ts + window
samples = 1
timeDomain.append(0)
while(ts > binLimit):
timeDomain.append(0)
samples += 1
bin += 1
binLimit += window
if(ts <= binLimit):
timeDomain[bin] += 1
samples += 1
endingTime = ts
if bin % 2 == 1:
bin+=1
timeDomain.append(0)
seconds = [float(n) * window for n in range(0,len(timeDomain))]
plt.figure(figsize=(12,6))
plt.plot(seconds,timeDomain)
plt.title("Packets over time")
plt.xlabel("Seconds")
if(output_filename):
plt.savefig(output_filename, dpi=150, format='png')
else:
plt.show()