2003-08-12 06:33:13 +00:00
|
|
|
import array
|
2003-08-13 22:42:52 +00:00
|
|
|
import sys
|
2003-08-12 06:33:13 +00:00
|
|
|
|
|
|
|
black = ( 0, 0, 0)
|
|
|
|
blue = ( 0, 0,255)
|
|
|
|
green = ( 0,255, 0)
|
|
|
|
cyan = ( 0,255,255)
|
|
|
|
red = (255, 0, 0)
|
|
|
|
magenta = (255, 0,255)
|
|
|
|
yellow = (255,255, 0)
|
2003-08-12 16:04:00 +00:00
|
|
|
white = (255,255,255)
|
2003-08-12 22:18:51 +00:00
|
|
|
grey = (128,128,128)
|
2003-08-12 06:33:13 +00:00
|
|
|
|
2003-08-12 22:18:51 +00:00
|
|
|
def div10 (x):
|
|
|
|
return x / 5
|
|
|
|
|
|
|
|
def plot (x, y, color, blend = 0):
|
|
|
|
def lim (x):
|
|
|
|
if x > 255:
|
|
|
|
x = 255
|
|
|
|
return x
|
2003-08-12 06:33:13 +00:00
|
|
|
y = height - 1 - y
|
|
|
|
p = (y * width + x) * 3
|
2003-08-12 22:18:51 +00:00
|
|
|
r, g, b = color
|
|
|
|
if blend:
|
|
|
|
r += a[p + 0]
|
|
|
|
g += a[p + 1]
|
|
|
|
b += a[p + 2]
|
|
|
|
a[p + 0], a[p + 1], a[p + 2] = lim (r), lim (g), lim (b)
|
2003-08-12 06:33:13 +00:00
|
|
|
|
2003-08-12 22:18:51 +00:00
|
|
|
def vline (x, y1, y2, color, blend = 0):
|
2003-08-12 06:33:13 +00:00
|
|
|
if y1 == y2:
|
2003-08-12 22:18:51 +00:00
|
|
|
plot (x, y1, color, blend)
|
2003-08-12 06:33:13 +00:00
|
|
|
elif y1 < y2:
|
|
|
|
for y in range (y1, y2 + 1):
|
2003-08-12 22:18:51 +00:00
|
|
|
plot (x, y, color, blend)
|
2003-08-12 06:33:13 +00:00
|
|
|
else:
|
|
|
|
for y in range (y2, y1 + 1):
|
2003-08-12 22:18:51 +00:00
|
|
|
plot (x, y, color, blend)
|
2003-08-12 06:33:13 +00:00
|
|
|
|
2003-08-12 22:18:51 +00:00
|
|
|
def hline (x1, x2, y, color, blend = 0):
|
2003-08-12 06:33:13 +00:00
|
|
|
if x1 == x2:
|
2003-08-12 22:18:51 +00:00
|
|
|
plot (x1, y, color, blend)
|
2003-08-12 06:33:13 +00:00
|
|
|
elif x1 < x2:
|
|
|
|
for x in range (x1, x2 + 1):
|
2003-08-12 22:18:51 +00:00
|
|
|
plot (x, y, color, blend)
|
2003-08-12 06:33:13 +00:00
|
|
|
else:
|
|
|
|
for x in range (x2, x1 + 1):
|
2003-08-12 22:18:51 +00:00
|
|
|
plot (x, y, color, blend)
|
2003-08-12 06:33:13 +00:00
|
|
|
|
2003-08-12 22:18:51 +00:00
|
|
|
class Frames:
|
|
|
|
class iterator:
|
|
|
|
def __init__ (self, obj):
|
|
|
|
self.obj = obj
|
|
|
|
self.cur = 0
|
|
|
|
self.max = len (obj)
|
|
|
|
def __iter__ (self):
|
|
|
|
return self
|
|
|
|
def next (self):
|
|
|
|
if self.cur == self.max:
|
|
|
|
raise StopIteration
|
|
|
|
obj = self.obj.times[self.cur]
|
|
|
|
self.cur += 1
|
|
|
|
return obj
|
|
|
|
def __init__ (self, data):
|
2003-08-13 22:42:52 +00:00
|
|
|
self.times = map (lambda x: int(x), data)
|
2003-08-12 22:18:51 +00:00
|
|
|
min = max = self.times[0]
|
|
|
|
sum = 0
|
|
|
|
for t in self.times:
|
|
|
|
if min > t:
|
|
|
|
min = t
|
|
|
|
if max < t:
|
|
|
|
max = t
|
|
|
|
sum = sum + t
|
|
|
|
self.min = min
|
|
|
|
self.max = max
|
|
|
|
self.avg = sum / float (len (self.times))
|
|
|
|
def __len__ (self):
|
|
|
|
return len (self.times)
|
|
|
|
def __getitem__ (self, key):
|
|
|
|
if type (key) == type (1):
|
|
|
|
return self.times[key]
|
|
|
|
else:
|
|
|
|
if key.step:
|
|
|
|
return self.times[key.start:key.stop:key.step]
|
|
|
|
else:
|
|
|
|
return self.times[key.start:key.stop]
|
|
|
|
def __iter__ (self):
|
|
|
|
return Frames.iterator (self)
|
2003-08-12 06:33:13 +00:00
|
|
|
|
2003-08-12 22:18:51 +00:00
|
|
|
frames = []
|
2003-08-13 22:42:52 +00:00
|
|
|
for fname in sys.argv[1:]:
|
|
|
|
f = open (fname, "rt")
|
2003-08-12 22:18:51 +00:00
|
|
|
lines = f.readlines ()
|
|
|
|
f.close ()
|
|
|
|
frames.append (Frames (lines))
|
2003-08-13 22:42:52 +00:00
|
|
|
print frames[-1].min/1000.0, frames[-1].max/1000.0, frames[-1].avg/1000.0
|
2003-08-12 06:33:13 +00:00
|
|
|
|
2003-08-12 22:18:51 +00:00
|
|
|
width = len (frames[0])
|
2003-08-13 22:42:52 +00:00
|
|
|
max = frames[0].max
|
2003-08-12 22:18:51 +00:00
|
|
|
for f in frames:
|
|
|
|
if width < len (f):
|
|
|
|
width = len (f)
|
2003-08-13 22:42:52 +00:00
|
|
|
if max < f.max:
|
|
|
|
max = f.max
|
|
|
|
|
|
|
|
tick_mult = 10
|
|
|
|
if max < 1000:
|
|
|
|
scale = 1.0
|
|
|
|
ticks = 10
|
|
|
|
elif max < 2000:
|
|
|
|
scale = 0.5
|
|
|
|
ticks = 5
|
|
|
|
elif max < 4000:
|
|
|
|
scale = 0.25
|
|
|
|
ticks = 5
|
|
|
|
tick_mult = 5
|
|
|
|
elif max < 5000:
|
|
|
|
scale = 0.2
|
|
|
|
ticks = 2
|
|
|
|
elif max < 10000:
|
|
|
|
scale = 0.1
|
|
|
|
ticks = 10
|
|
|
|
elif max < 20000:
|
|
|
|
scale = 0.05
|
|
|
|
ticks = 5
|
|
|
|
elif max < 40000:
|
|
|
|
scale = 0.025
|
|
|
|
ticks = 5
|
|
|
|
tick_mult = 5
|
|
|
|
elif max < 50000:
|
|
|
|
scale = 0.02
|
|
|
|
ticks = 2
|
|
|
|
elif max < 100000:
|
|
|
|
scale = 0.01
|
|
|
|
ticks = 10
|
|
|
|
elif max < 200000:
|
|
|
|
scale = 0.005
|
|
|
|
ticks = 5
|
|
|
|
elif max < 400000:
|
|
|
|
scale = 0.0025
|
|
|
|
ticks = 5
|
|
|
|
tick_mult = 5
|
|
|
|
elif max < 500000:
|
|
|
|
scale = 0.002
|
|
|
|
ticks = 2
|
|
|
|
elif max < 1000000:
|
|
|
|
scale = 0.001
|
|
|
|
ticks = 10
|
|
|
|
elif max < 2000000:
|
|
|
|
scale = 0.0005
|
|
|
|
ticks = 5
|
|
|
|
elif max < 4000000:
|
|
|
|
scale = 0.00025
|
|
|
|
ticks = 5
|
|
|
|
tick_mult = 5
|
|
|
|
elif max < 5000000:
|
|
|
|
scale = 0.0002
|
|
|
|
ticks = 2
|
|
|
|
else:
|
|
|
|
scale = 0.0001
|
|
|
|
ticks = 10
|
|
|
|
|
|
|
|
height = int (max * scale + 0.5) + 1
|
2003-08-12 06:33:13 +00:00
|
|
|
|
|
|
|
a = array.array ('B', '\0' * height * width * 3)
|
|
|
|
|
2003-08-12 22:18:51 +00:00
|
|
|
hline (0, width - 1, 0, grey)
|
|
|
|
vline (0, 0, height - 1, grey)
|
2003-08-13 22:42:52 +00:00
|
|
|
for y in range (0, height - 1, ticks):
|
2003-08-12 22:18:51 +00:00
|
|
|
hline (0, 5, y, grey)
|
2003-08-13 22:42:52 +00:00
|
|
|
for y in range (0, height - 1, ticks * tick_mult):
|
2003-08-12 22:18:51 +00:00
|
|
|
hline (0, 10, y, grey)
|
2003-08-13 22:42:52 +00:00
|
|
|
for x in range (0, width - 1, 100):
|
2003-08-12 22:18:51 +00:00
|
|
|
vline (x, 0, 5, grey)
|
2003-08-12 16:24:50 +00:00
|
|
|
|
2003-08-13 22:42:52 +00:00
|
|
|
b1 = 0.8
|
|
|
|
a1 = 1 - b1
|
|
|
|
|
2003-08-12 22:18:51 +00:00
|
|
|
for f in frames:
|
2003-08-13 22:42:52 +00:00
|
|
|
ravg = 0
|
2003-08-12 22:18:51 +00:00
|
|
|
for x in range (len (f)):
|
2003-08-13 22:42:52 +00:00
|
|
|
y1 = int (f[x] * scale + 0.5)
|
2003-08-12 22:18:51 +00:00
|
|
|
if x < len (f) - 1:
|
2003-08-13 22:42:52 +00:00
|
|
|
y2 = int (f[x + 1] * scale + 0.5)
|
|
|
|
vline (x, y1, y2, map (div10, yellow), 1)
|
|
|
|
plot (x, y1, red)
|
|
|
|
ravg = a1 * f[x] + b1 * ravg
|
|
|
|
plot (x, int (ravg * scale + 0.5), map (div10, cyan), 1)
|
|
|
|
hline (0, len (f) - 1, int (f.avg * scale + 0.5), map (div10, blue), 1)
|
2003-08-12 06:33:13 +00:00
|
|
|
|
|
|
|
f = open ("timeframes.ppm", "wb")
|
|
|
|
f.write ("P6\n")
|
|
|
|
f.write ("#File written by timeframes.py\n")
|
|
|
|
f.write (`width` + " " + `height` + "\n")
|
|
|
|
f.write ("255\n")
|
|
|
|
f.write (a.tostring ())
|
|
|
|
f.close ()
|