From 4c00ef19cce6eaa1c75970a7b24d9c5ee32202df Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sat, 10 Jul 2010 02:07:47 +0200 Subject: [PATCH] implement simple DB stats - Hand and tourney count --- pyfpdb/Database.py | 12 ++++++++++++ pyfpdb/SQL.py | 3 +++ pyfpdb/fpdb.pyw | 5 +++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 2a12ed11..0c1cf85c 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -553,6 +553,18 @@ class Database: c.execute(self.sql.query['get_hand_info'], new_hand_id) return c.fetchall() + def getHandCount(self): + c = self.connection.cursor() + c.execute(self.sql.query['getHandCount']) + return c.fetchone()[0] + #end def getHandCount + + def getTourneyCount(self): + c = self.connection.cursor() + c.execute(self.sql.query['getTourneyCount']) + return c.fetchone()[0] + #end def getTourneyCount + def get_actual_seat(self, hand_id, name): c = self.connection.cursor() c.execute(self.sql.query['get_actual_seat'], (hand_id, name)) diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 9ad9f321..48fb9260 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -3834,6 +3834,9 @@ class Sql: %s )""" + self.query['getHandCount'] = "SELECT COUNT(id) FROM Hands" + self.query['getTourneyCount'] = "SELECT COUNT(id) FROM Tourneys" + if db_server == 'mysql': self.query['placeholder'] = u'%s' elif db_server == 'postgresql': diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index 87910d98..f7ed8f24 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -323,7 +323,8 @@ class fpdb: + "other windows have been opened. Re-start fpdb to use this option.") def dia_database_stats(self, widget, data=None): - self.warning_box("Unimplemented: Database Stats") + self.warning_box(str="Number of hands: "+str(self.db.getHandCount())+"\nNumber of tourneys: "+str(self.db.getTourneyCount()), diatitle="Database Statistics") + #end def dia_database_stats # def dia_get_db_root_credentials(self): # """obtains db root credentials from user""" @@ -685,7 +686,7 @@ class fpdb: ('createtabs', None, 'Create or Recreate _Tables', None, 'Create or Recreate Tables ', self.dia_recreate_tables), ('rebuildhudcache', None, 'Rebuild HUD Cache', None, 'Rebuild HUD Cache', self.dia_recreate_hudcache), ('rebuildindexes', None, 'Rebuild DB Indexes', None, 'Rebuild DB Indexes', self.dia_rebuild_indexes), - ('stats', None, '_Statistics (todo)', None, 'View Database Statistics', self.dia_database_stats), + ('stats', None, '_Statistics', None, 'View Database Statistics', self.dia_database_stats), ('help', None, '_Help'), ('Logs', None, '_Log Messages', None, 'Log and Debug Messages', self.dia_logs), ('About', None, 'A_bout', None, 'About the program', self.dia_about),