Mercurial > vixm
comparison vixm/stats.py @ 46:2d570448aba5 pure
Abstract out the stats code a little bit more
This is in preparation for moving the stats code completely out of player
code
author | Josef "Jeff" Sipek <jeffpc@josefsipek.net> |
---|---|
date | Mon, 06 Nov 2006 05:19:23 -0500 |
parents | bc6db55448e1 |
children |
comparison
equal
deleted
inserted
replaced
45:2bf81d95246a | 46:2d570448aba5 |
---|---|
7 self.__stats = eval(open(statsfile, "r").read()) | 7 self.__stats = eval(open(statsfile, "r").read()) |
8 except: | 8 except: |
9 self.__stats = {} | 9 self.__stats = {} |
10 self.__new_songs = 0 | 10 self.__new_songs = 0 |
11 | 11 |
12 self.current = None | 12 self.__current = None |
13 | 13 |
14 def __del__(self): | 14 def __del__(self): |
15 self.sync() | 15 self.sync() |
16 | 16 |
17 def sync(self): | 17 def sync(self): |
19 f.write(repr(self.__stats)) | 19 f.write(repr(self.__stats)) |
20 f.close() | 20 f.close() |
21 | 21 |
22 self.__new_songs = 0 | 22 self.__new_songs = 0 |
23 | 23 |
24 def playing(self, s): | |
25 self.__current = s | |
26 | |
24 def played(self): | 27 def played(self): |
25 s = str(self.current) | 28 s = str(self.__current) |
26 | 29 |
27 if not self.__stats.has_key(s): | 30 if not self.__stats.has_key(s): |
28 self.__stats[s] = 0 | 31 self.__stats[s] = 0 |
29 | 32 |
30 self.__stats[s] += 1 | 33 self.__stats[s] += 1 |
31 | 34 |
32 self.__new_songs += 1 | 35 self.__new_songs += 1 |
33 if self.__new_songs >= NEW_SONGS_SYNC: | 36 if self.__new_songs >= NEW_SONGS_SYNC: |
34 self.sync() | 37 self.sync() |
35 | 38 |