I have a txt
file that looks like this:
0.065998 81
0.319601 81
0.539613 81
0.768445 81
1.671893 81
1.785064 81
1.881242 954
1.921503 193
1.921605 188
1.943166 81
2.122283 63
2.127669 83
2.444705 81
The first column is the packet arrival and second packet size in bytes.
I need to get the average value of bytes in each second. For example in the first second I have only packets with value 81 so the average bitrate is 81*8= 648bit/s
. Then I should plot a graph x axis time in seconds, y axis average bitrate in each second.
So far I have only managed to upload my data as arrays:
import numpy as np
d = np.genfromtxt('data.txt')
x = (d[:,0])
y = (d[:,1 ])
print x
print(y*8)
I'm new to Python, so any help where to start would be much appreciated!
Here is the result script:
import matplotlib.pyplot as plt
import numpy as np
x, y = np.loadtxt('data.txt', unpack=True)
bins = np.arange(60+1)
totals, edges = np.histogram(x, weights=y, bins=bins)
counts, edges = np.histogram(x, bins=bins)
print counts
print totals*0.008/counts
plt.plot(totals*0.008/counts, 'r')
plt.xlabel('time, s')
plt.ylabel('kbit/s')
plt.grid(True)
plt.xlim(0.0, 60.0)
plt.show()
The script reads the .txt file which contains packet size(bytes) and arrival time, and plots the average bitrate/s during a time period. Used to monitor server incoming/outgoing traffic!