diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 1b351f86..3c8b4246 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -49,12 +49,15 @@ import logging, logging.config logging.config.fileConfig(os.path.join(sys.path[0],"logging.conf")) log = logging.getLogger('db') + class Database: MYSQL_INNODB = 2 PGSQL = 3 SQLITE = 4 + hero_hudstart_def = '1999-12-31' # default for length of Hero's stats in HUD + # Data Structures for index and foreign key creation # drop_code is an int with possible values: 0 - don't drop for bulk import # 1 - drop during bulk import @@ -183,6 +186,7 @@ class Database: def __init__(self, c, sql = None): log.info("Creating Database instance, sql = %s" % sql) + self.config = c self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql self.fdb.do_connect(c) self.connection = self.fdb.db @@ -1098,13 +1102,28 @@ class Database: #end def fillDefaultData - def rebuild_hudcache(self): + def rebuild_hudcache(self, start=None): """clears hudcache and rebuilds from the individual handsplayers records""" try: stime = time() + # get hero's screen names and player ids + self.hero, self.hero_ids = {}, {} + if start == None: + start = self.hero_hudstart_def + for site in self.config.get_supported_sites(): + result = self.get_site_id(site) + if result: + site_id = result[0][0] + self.hero[site_id] = self.config.supported_sites[site].screen_name + self.hero_ids[site_id] = self.get_player_id(self.config, site, self.hero[site_id]) + + where = "where hp.playerId not in (-53, " + ", ".join(map(str, self.hero_ids.values())) \ + + ") or h.handStart > '" + start + "'" + rebuild_sql = self.sql.query['rebuildHudCache'].replace('', where) + self.get_cursor().execute(self.sql.query['clearHudCache']) - self.get_cursor().execute(self.sql.query['rebuildHudCache']) + self.get_cursor().execute(rebuild_sql) self.commit() print "Rebuild hudcache took %.1f seconds" % (time() - stime,) except: diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 71b697f5..d4350ad5 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -2511,6 +2511,7 @@ class Sql: ,sum(street4CheckCallRaiseDone) FROM HandsPlayers hp INNER JOIN Hands h ON (h.id = hp.handId) + GROUP BY h.gametypeId ,hp.playerId ,h.seats @@ -2659,6 +2660,7 @@ class Sql: ,sum(CAST(street4CheckCallRaiseDone as integer)) FROM HandsPlayers hp INNER JOIN Hands h ON (h.id = hp.handId) + GROUP BY h.gametypeId ,hp.playerId ,h.seats @@ -2807,6 +2809,7 @@ class Sql: ,sum(CAST(street4CheckCallRaiseDone as integer)) FROM HandsPlayers hp INNER JOIN Hands h ON (h.id = hp.handId) + GROUP BY h.gametypeId ,hp.playerId ,h.seats diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index fd2feca2..05121474 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -257,17 +257,65 @@ class fpdb: def dia_recreate_hudcache(self, widget, data=None): if self.obtain_global_lock(): - dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm recreating HUD cache") + self.dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm recreating HUD cache") diastring = "Please confirm that you want to re-create the HUD cache." - dia_confirm.format_secondary_text(diastring) - - response = dia_confirm.run() - dia_confirm.destroy() + self.dia_confirm.format_secondary_text(diastring) + + hb = gtk.HBox(True, 1) + self.start_date = gtk.Entry(max=12) + self.start_date.set_text(self.db.hero_hudstart_def) + lbl = gtk.Label(" Hero's cache starts: ") + btn = gtk.Button() + btn.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)) + btn.connect('clicked', self.__calendar_dialog, self.start_date) + + hb.pack_start(lbl, expand=True, padding=3) + hb.pack_start(self.start_date, expand=True, padding=2) + hb.pack_start(btn, expand=False, padding=3) + self.dia_confirm.vbox.add(hb) + hb.show_all() + + response = self.dia_confirm.run() + self.dia_confirm.destroy() if response == gtk.RESPONSE_YES: - self.db.rebuild_hudcache() - elif response == gtk.REPSONSE_NO: + self.db.rebuild_hudcache( self.start_date.get_text() ) + elif response == gtk.RESPONSE_NO: print 'User cancelled rebuilding hud cache' + self.release_global_lock() + + def __calendar_dialog(self, widget, entry): + self.dia_confirm.set_modal(False) + d = gtk.Window(gtk.WINDOW_TOPLEVEL) + d.set_title('Pick a date') + + vb = gtk.VBox() + cal = gtk.Calendar() + vb.pack_start(cal, expand=False, padding=0) + + btn = gtk.Button('Done') + btn.connect('clicked', self.__get_date, cal, entry, d) + + vb.pack_start(btn, expand=False, padding=4) + + d.add(vb) + d.set_position(gtk.WIN_POS_MOUSE) + d.show_all() + + def __get_dates(self): + t1 = self.start_date.get_text() + if t1 == '': + t1 = '1970-01-01' + return (t1) + + def __get_date(self, widget, calendar, entry, win): + # year and day are correct, month is 0..11 + (year, month, day) = calendar.get_date() + month += 1 + ds = '%04d-%02d-%02d' % (year, month, day) + entry.set_text(ds) + win.destroy() + self.dia_confirm.set_modal(True) def dia_regression_test(self, widget, data=None): self.warning_box("Unimplemented: Regression Test")