# visualize Sputnik tracking import fileinput import sys import string import datetime from Tkinter import * import PIL import Image import ImageFont import ImageDraw import ImageTk locations = \ {'10.254.4.6': (903,363,'A'), '10.254.2.3': (450,897,'A'), '10.254.2.12': (153,1164,'A'), '10.254.2.10': (486,1281,'A'), '10.254.1.7': (906,1023,'A'), '10.254.3.13': (594,1578,'A'), '10.254.3.6': (414,1416,'A'), '10.254.3.9': (1076,588,'B'), '10.254.2.5': (1256,386,'B'), '10.254.1.5': (1252,690,'B'), '10.254.1.22': (1254,1134,'B'), '10.254.3.21': (874,948,'B'), '10.254.0.7': (82,722,'B'), '10.254.4.12': (840,274,'B'), '10.254.1.6': (544,654,'B'), '10.254.1.12': (544,486,'B'), '10.254.0.254': (204,958,'B'), '10.254.5.2': (202,276,'B'), '10.254.8.1': (514,25,'C'), '10.254.8.14': (25,217,'C'), '10.254.5.21': (232,592,'C'), '10.254.4.11': (537,592,'C'), '10.254.7.14': (768,379,'C')} def map_location_to_image(loc): global locations if not locations.has_key(loc): return None l = locations[loc] if l[2] == 'A': return (l[0]/2, l[1]/2) elif l[2] == 'B': return (l[0]/2 + 624, l[1]/2 + 104) elif l[2] == 'C': return (l[0]/2 + 1276, l[1]/2 + 221) else: return None def get_timestamp(ts_sorted): for ts_str in ts_sorted: yield (ts_str, timestamp_dict[ts_str]) old_loc_series = [[]] last_ts = 0 def update_frame(iter, frame=0): global root global font global photo # must not be dropped by garbage collector global im global canvas global old_loc_series global last_ts print 'frame %d' % (frame) ts_str, data = iter.next() ts, count, locs = data print ts_str, count, locs im2 = im.copy() draw = ImageDraw.Draw(im2) draw.text((10, 10), ts_str + ' frame %d' % (frame), font=font, fill=0) if ts > (last_ts + 10): old_loc_series = [[]] draw.rectangle([(20, 30), (20 + 3*min(100, ts - last_ts), 40)], fill=0) last_ts = ts fill = 150 size = 1 for serie in old_loc_series: for x, y in serie: draw.rectangle([(x-size, y-size), (x+size, y+size)], fill=fill) fill -= 20 size += 1 if len(old_loc_series) >= 5: del old_loc_series[0] old_loc_series.append([]) for loc in locs: x, y = map_location_to_image(loc) old_loc_series[-1].append((x,y)) draw.rectangle([(x-5, y-5), (x+5, y+5)], fill=0) photo = ImageTk.PhotoImage(im2) item = canvas.create_image(0, 0, anchor=NW, image=photo) im2.resize((886, 420), Image.BILINEAR).save('frame-%08d.png' % (frame)) root.after(100, update_frame, iter, frame + 1) timestamp_dict = {} fi = fileinput.input(sys.argv[1:]) for line in fi: reset, ts, ip, seq = line.split() timestamp = datetime.datetime.fromtimestamp(long(ts, 16)) timestamp_str = '%d-%02d-%02d %02d:%02d:%02d' % (timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second) if timestamp_dict.has_key(timestamp_str): t = timestamp_dict[timestamp_str] if ip in t[2]: timestamp_dict[timestamp_str] = (long(ts, 16), t[1]+1, t[2]) else: timestamp_dict[timestamp_str] = (long(ts, 16), t[1]+1, t[2]+[ip]) else: timestamp_dict[timestamp_str] = (long(ts, 16), 1, [ip]) ts_sorted = timestamp_dict.keys() ts_sorted.sort() root = Tk() font = ImageFont.truetype("arial.ttf", 18) im = Image.open('background.png') canvas = Canvas(root, height=im.size[1], width=im.size[0]) canvas.pack(side=LEFT, fill=BOTH, expand=1) update_frame(get_timestamp(ts_sorted)) mainloop()