Mercurial > code > home > repos > light9
comparison light8/updatefreq.py @ 126:57809e0ef359
more precision on output; fewer default sample count
author | drewp |
---|---|
date | Sat, 14 Jun 2003 14:47:34 +0000 |
parents | b75bfbcf5979 |
children |
comparison
equal
deleted
inserted
replaced
125:50001190b317 | 126:57809e0ef359 |
---|---|
7 and then float() or str() the object to learn the updates per second. | 7 and then float() or str() the object to learn the updates per second. |
8 | 8 |
9 the samples param to __init__ specifies how many past updates will | 9 the samples param to __init__ specifies how many past updates will |
10 be stored. """ | 10 be stored. """ |
11 | 11 |
12 def __init__(self,samples=40): | 12 def __init__(self,samples=20): |
13 self.times=[0] | 13 self.times=[0] |
14 self.samples=samples | 14 self.samples=samples |
15 | 15 |
16 def update(self): | 16 def update(self): |
17 | 17 |
22 def __float__(self): | 22 def __float__(self): |
23 | 23 |
24 """a cheap algorithm, for now, which looks at the first and | 24 """a cheap algorithm, for now, which looks at the first and |
25 last times only""" | 25 last times only""" |
26 | 26 |
27 hz=len(self.times)/(self.times[-1]-self.times[0]) | 27 try: |
28 hz=len(self.times)/(self.times[-1]-self.times[0]) | |
29 except ZeroDivisionError: | |
30 return 0 | |
28 return hz | 31 return hz |
29 def __str__(self): | 32 def __str__(self): |
30 return "%.1fHz"%float(self) | 33 return "%.2fHz"%float(self) |