annotate light8/updatefreq.py @ 161:0803fb42109d

we now have TkCueList, which is really cool. it doesn't provide editing we now have TkCueList, which is really cool. it doesn't provide editing yet, but you could almost nearly probably maybe run a show with it. heck, i hope so. some of the shifting/drawing problems were probably fixed. cuelist1 got more bogus data to help populate the TkCueList.
author dmcc
date Mon, 07 Jul 2003 17:18:26 +0000
parents 57809e0ef359
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1 """calculates your updates-per-second"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
2
45b12307c695 Initial revision
drewp
parents:
diff changeset
3 import time
45b12307c695 Initial revision
drewp
parents:
diff changeset
4
45b12307c695 Initial revision
drewp
parents:
diff changeset
5 class Updatefreq:
45b12307c695 Initial revision
drewp
parents:
diff changeset
6 """make one of these, call update() on it as much as you want,
45b12307c695 Initial revision
drewp
parents:
diff changeset
7 and then float() or str() the object to learn the updates per second.
45b12307c695 Initial revision
drewp
parents:
diff changeset
8
45b12307c695 Initial revision
drewp
parents:
diff changeset
9 the samples param to __init__ specifies how many past updates will
45b12307c695 Initial revision
drewp
parents:
diff changeset
10 be stored. """
45b12307c695 Initial revision
drewp
parents:
diff changeset
11
126
57809e0ef359 more precision on output; fewer default sample count
drewp
parents: 120
diff changeset
12 def __init__(self,samples=20):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
13 self.times=[0]
45b12307c695 Initial revision
drewp
parents:
diff changeset
14 self.samples=samples
45b12307c695 Initial revision
drewp
parents:
diff changeset
15
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 def update(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
17
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 """call this every time you do an update"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
19 self.times=self.times[-self.samples:]
45b12307c695 Initial revision
drewp
parents:
diff changeset
20 self.times.append(time.time())
45b12307c695 Initial revision
drewp
parents:
diff changeset
21
45b12307c695 Initial revision
drewp
parents:
diff changeset
22 def __float__(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
23
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 """a cheap algorithm, for now, which looks at the first and
45b12307c695 Initial revision
drewp
parents:
diff changeset
25 last times only"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
26
126
57809e0ef359 more precision on output; fewer default sample count
drewp
parents: 120
diff changeset
27 try:
57809e0ef359 more precision on output; fewer default sample count
drewp
parents: 120
diff changeset
28 hz=len(self.times)/(self.times[-1]-self.times[0])
57809e0ef359 more precision on output; fewer default sample count
drewp
parents: 120
diff changeset
29 except ZeroDivisionError:
57809e0ef359 more precision on output; fewer default sample count
drewp
parents: 120
diff changeset
30 return 0
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
31 return hz
45b12307c695 Initial revision
drewp
parents:
diff changeset
32 def __str__(self):
126
57809e0ef359 more precision on output; fewer default sample count
drewp
parents: 120
diff changeset
33 return "%.2fHz"%float(self)