Merge branch 'master' of git://git.assembla.com/fpdb-sql.git

Conflicts:
	pyfpdb/Database.py
This commit is contained in:
Eric Blade 2009-12-01 08:03:25 -05:00
commit abf132c719
2 changed files with 197 additions and 153 deletions

19
pyfpdb/Database.py Executable file → Normal file
View File

@ -58,7 +58,8 @@ class Database:
PGSQL = 3 PGSQL = 3
SQLITE = 4 SQLITE = 4
hero_hudstart_def = '1999-12-31' # default for length of Hero's stats in HUD hero_hudstart_def = '1999-12-31' # default for length of Hero's stats in HUD
villain_hudstart_def = '1999-12-31' # default for length of Villain's stats in HUD
# Data Structures for index and foreign key creation # Data Structures for index and foreign key creation
# drop_code is an int with possible values: 0 - don't drop for bulk import # drop_code is an int with possible values: 0 - don't drop for bulk import
@ -760,7 +761,7 @@ class Database:
if 'dropHudCache' not in settings or settings['dropHudCache'] != 'drop': if 'dropHudCache' not in settings or settings['dropHudCache'] != 'drop':
self.storeHudCache(self.backend, base, category, gametype_id, hand_start_time, player_ids, hudImportData) self.storeHudCache(self.backend, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
t5 = time() t5 = time()
print "fills=(%4.3f) saves=(%4.3f,%4.3f,%4.3f)" % (t2-t0, t3-t2, t4-t3, t5-t4) #print "fills=(%4.3f) saves=(%4.3f,%4.3f,%4.3f)" % (t2-t0, t3-t2, t4-t3, t5-t4)
return hands_id return hands_id
#end def ring_holdem_omaha #end def ring_holdem_omaha
@ -1324,7 +1325,7 @@ class Database:
self.dropAllForeignKeys() self.dropAllForeignKeys()
self.createAllForeignKeys() self.createAllForeignKeys()
def rebuild_hudcache(self, start=None): def rebuild_hudcache(self, h_start=None, v_start=None):
"""clears hudcache and rebuilds from the individual handsplayers records""" """clears hudcache and rebuilds from the individual handsplayers records"""
try: try:
@ -1344,13 +1345,17 @@ class Database:
if p_id: if p_id:
self.hero_ids[site_id] = int(p_id) self.hero_ids[site_id] = int(p_id)
if start is None: if h_start is None:
start = self.hero_hudstart_def h_start = self.hero_hudstart_def
if v_start is None:
v_start = self.villain_hudstart_def
if self.hero_ids == {}: if self.hero_ids == {}:
where = "" where = ""
else: else:
where = "where hp.playerId not in " + str(tuple(self.hero_ids.values())) \ where = "where ( hp.playerId not in " + str(tuple(self.hero_ids.values())) \
+ " or h.handStart > '" + start + "'" + " and h.handStart > '" + v_start + "')" \
+ " or ( hp.playerId in " + str(tuple(self.hero_ids.values())) \
+ " and h.handStart > '" + h_start + "')"
rebuild_sql = self.sql.query['rebuildHudCache'].replace('<where_clause>', where) rebuild_sql = self.sql.query['rebuildHudCache'].replace('<where_clause>', where)
self.get_cursor().execute(self.sql.query['clearHudCache']) self.get_cursor().execute(self.sql.query['clearHudCache'])

View File

@ -334,27 +334,48 @@ class fpdb:
diastring = "Please confirm that you want to re-create the HUD cache." diastring = "Please confirm that you want to re-create the HUD cache."
self.dia_confirm.format_secondary_text(diastring) self.dia_confirm.format_secondary_text(diastring)
hb = gtk.HBox(True, 1) hb1 = gtk.HBox(True, 1)
self.h_start_date = gtk.Entry(max=12)
self.h_start_date.set_text( self.db.get_hero_hudcache_start() )
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.h_start_date)
hb1.pack_start(lbl, expand=True, padding=3)
hb1.pack_start(self.h_start_date, expand=True, padding=2)
hb1.pack_start(btn, expand=False, padding=3)
self.dia_confirm.vbox.add(hb1)
hb1.show_all()
hb2 = gtk.HBox(True, 1)
self.start_date = gtk.Entry(max=12) self.start_date = gtk.Entry(max=12)
self.start_date.set_text( self.db.get_hero_hudcache_start() ) self.start_date.set_text( self.db.get_hero_hudcache_start() )
lbl = gtk.Label(" Hero's cache starts: ") lbl = gtk.Label(" Villains' cache starts: ")
btn = gtk.Button() btn = gtk.Button()
btn.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_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) btn.connect('clicked', self.__calendar_dialog, self.start_date)
hb.pack_start(lbl, expand=True, padding=3) hb2.pack_start(lbl, expand=True, padding=3)
hb.pack_start(self.start_date, expand=True, padding=2) hb2.pack_start(self.start_date, expand=True, padding=2)
hb.pack_start(btn, expand=False, padding=3) hb2.pack_start(btn, expand=False, padding=3)
self.dia_confirm.vbox.add(hb) self.dia_confirm.vbox.add(hb2)
hb.show_all() hb2.show_all()
response = self.dia_confirm.run() response = self.dia_confirm.run()
self.dia_confirm.destroy()
if response == gtk.RESPONSE_YES: if response == gtk.RESPONSE_YES:
self.db.rebuild_hudcache( self.start_date.get_text() ) lbl = gtk.Label(" Rebuilding HUD Cache ... ")
self.dia_confirm.vbox.add(lbl)
lbl.show()
while gtk.events_pending():
gtk.main_iteration_do(False)
self.db.rebuild_hudcache( self.h_start_date.get_text(), self.start_date.get_text() )
elif response == gtk.RESPONSE_NO: elif response == gtk.RESPONSE_NO:
print 'User cancelled rebuilding hud cache' print 'User cancelled rebuilding hud cache'
self.dia_confirm.destroy()
self.release_global_lock() self.release_global_lock()
def dia_rebuild_indexes(self, widget, data=None): def dia_rebuild_indexes(self, widget, data=None):
@ -368,14 +389,28 @@ class fpdb:
self.dia_confirm.format_secondary_text(diastring) self.dia_confirm.format_secondary_text(diastring)
response = self.dia_confirm.run() response = self.dia_confirm.run()
self.dia_confirm.destroy()
if response == gtk.RESPONSE_YES: if response == gtk.RESPONSE_YES:
lbl = gtk.Label(" Rebuilding Indexes ... ")
self.dia_confirm.vbox.add(lbl)
lbl.show()
while gtk.events_pending():
gtk.main_iteration_do(False)
self.db.rebuild_indexes() self.db.rebuild_indexes()
lbl.set_text(" Cleaning Database ... ")
while gtk.events_pending():
gtk.main_iteration_do(False)
self.db.vacuumDB() self.db.vacuumDB()
lbl.set_text(" Analyzing Database ... ")
while gtk.events_pending():
gtk.main_iteration_do(False)
self.db.analyzeDB() self.db.analyzeDB()
elif response == gtk.RESPONSE_NO: elif response == gtk.RESPONSE_NO:
print 'User cancelled rebuilding db indexes' print 'User cancelled rebuilding db indexes'
self.dia_confirm.destroy()
self.release_global_lock() self.release_global_lock()
def __calendar_dialog(self, widget, entry): def __calendar_dialog(self, widget, entry):
@ -397,10 +432,13 @@ class fpdb:
d.show_all() d.show_all()
def __get_dates(self): def __get_dates(self):
t1 = self.start_date.get_text() t1 = self.h_start_date.get_text()
if t1 == '': if t1 == '':
t1 = '1970-01-01' t1 = '1970-01-01'
return (t1) t2 = self.start_date.get_text()
if t2 == '':
t2 = '1970-01-01'
return (t1, t2)
def __get_date(self, widget, calendar, entry, win): def __get_date(self, widget, calendar, entry, win):
# year and day are correct, month is 0..11 # year and day are correct, month is 0..11
@ -834,6 +872,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
gtk.main() gtk.main()
return 0 return 0
if __name__ == "__main__": if __name__ == "__main__":
me = fpdb() me = fpdb()
me.main() me.main()