annotate light8/updatefreq.py @ 167:79bc84310e80

changes from tonight's rehearsal: changes from tonight's rehearsal: - CueFader is closer to actually running the show, computes DMX levels to send. - KeyboardComposer is not a dummy. Use DMXDUMMY=1 to disable it. - Submaster: subs can now be "temporary" -- i.e. they shouldn't be saved or loaded. to save a temporary sub, make a copy of it with a proper name since the computed name will be ugly. Also, get_normalized_copy() and crossfade() methods added. linear_fade helper (shouldn't be in Submaster, probably) added too. - dmxchanedit: longer labels - cuelist1 now has some bogus data in it and some crap removed - dmxclient: now listens to the $DMXHOST and $DMXDUMMY env variables. - patchdata: now up to date with this year's show - danshow subs song{01..19}: removed. maybe we'll re-add them in an archive directory.
author dmcc
date Tue, 08 Jul 2003 16:19:55 +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)