I'm currently trying to group messages that are sent out by 1 second time intervals. I'm currently calculating time latency with this:
def time_deltas(infile):
entries = (line.split() for line in open(INFILE, "r"))
ts = {}
for e in entries:
if " ".join(e[2:5]) == "T out: [O]":
ts[e[8]] = e[0]
elif " ".join(e[2:5]) == "T in: [A]":
in_ts, ref_id = e[0], e[7]
out_ts = ts.pop(ref_id, None)
yield (float(out_ts),ref_id[1:-1],(float(in_ts)*1000 - float(out_ts)*1000))
INFILE = 'C:/Users/klee/Documents/test.txt'
import csv
with open('test.csv', 'w') as f:
csv.writer(f).writerows(time_deltas(INFILE))
HOWEVER I want to calculate the number of "T in: [A]" messages per second that are sent out, and have been trying to work with this to do so:
import datetime
import bisect
import collections
data=[ (datetime.datetime(2010, 2, 26, 12, 8, 17), 5594813L),
(datetime.datetime(2010, 2, 26, 12, 7, 31), 5594810L),
(datetime.datetime(2010, 2, 26, 12, 6, 4) , 5594807L),
]
interval=datetime.timedelta(seconds=50)
start=datetime.datetime(2010, 2, 26, 12, 6, 4)
grid=[start+n*interval for n in range(10)]
bins=collections.defaultdict(list)
for date,num in data:
idx=bisect.bisect(grid,date)
bins[idx].append(num)
for idx,nums in bins.iteritems():
print('{0} --- {1}'.format(grid[idx],len(nums)))
which can be found here: Python: group results by time intervals
(I realize the units would be off for what I want, but I'm just looking into the general idea...)
I've been mostly unsuccessful thus far and would appreciate any help.
Also,
The data appears as:
082438.577652 - T in: [A] accepted. ordID [F25Q6] timestamp [082438.575880] RefNumber [6018786] State [L]
See Question&Answers more detail:
os