Merge branch 'master' of git://git.assembla.com/fpdb-sql
This commit is contained in:
commit
a5ac2dcf75
|
@ -409,7 +409,7 @@ class fpdb:
|
|||
return self.fdb_lock.get_global_lock()
|
||||
#end def obtain_global_lock
|
||||
|
||||
def quit(self, widget, data):
|
||||
def quit(self, widget, data=None):
|
||||
print "Quitting normally"
|
||||
#check if current settings differ from profile, if so offer to save or abort
|
||||
self.db.disconnect()
|
||||
|
|
|
@ -179,13 +179,28 @@ class fpdb_db:
|
|||
# For local domain-socket connections, only DB name is
|
||||
# needed, and everything else is in fact undefined and/or
|
||||
# flat out wrong
|
||||
# sqlcoder: This database only connect failed in my windows setup??
|
||||
# Modifed it to try the 4 parameter style if the first connect fails - does this work everywhere?
|
||||
connected = False
|
||||
if self.host == "localhost" or self.host == "127.0.0.1":
|
||||
self.db = psycopg2.connect(database = database)
|
||||
else:
|
||||
self.db = psycopg2.connect(host = host,
|
||||
user = user,
|
||||
password = password,
|
||||
database = database)
|
||||
try:
|
||||
self.db = psycopg2.connect(database = database)
|
||||
connected = True
|
||||
except:
|
||||
pass
|
||||
#msg = "PostgreSQL direct connection to database (%s) failed, trying with user ..." % (database,)
|
||||
#print msg
|
||||
#raise fpdb_simple.FpdbError(msg)
|
||||
if not connected:
|
||||
try:
|
||||
self.db = psycopg2.connect(host = host,
|
||||
user = user,
|
||||
password = password,
|
||||
database = database)
|
||||
except:
|
||||
msg = "PostgreSQL connection to database (%s) user (%s) failed." % (database, user)
|
||||
print msg
|
||||
raise fpdb_simple.FpdbError(msg)
|
||||
else:
|
||||
raise fpdb_simple.FpdbError("unrecognised database backend:"+backend)
|
||||
self.cursor=self.db.cursor()
|
||||
|
|
|
@ -165,9 +165,10 @@ class Importer:
|
|||
start = datetime.datetime.now()
|
||||
print "started at", start, "--", len(self.filelist), "files to import.", self.settings['dropIndexes']
|
||||
if self.settings['dropIndexes'] == 'auto':
|
||||
self.settings['dropIndexes'] = self.calculate_auto()
|
||||
self.settings['dropIndexes'] = self.calculate_auto2(10.0, 500.0)
|
||||
if self.settings['dropIndexes'] == 'drop':
|
||||
self.fdb.prepareBulkImport()
|
||||
#self.settings['updateHudCache'] = self.calculate_auto2(10.0, 500.0)
|
||||
totstored = 0
|
||||
totdups = 0
|
||||
totpartial = 0
|
||||
|
@ -202,6 +203,40 @@ class Importer:
|
|||
if self.settings['handsInDB'] > 50000: return "don't drop"
|
||||
return "drop"
|
||||
|
||||
def calculate_auto2(self, scale, increment):
|
||||
"""A second heuristic to determine a reasonable value of drop/don't drop
|
||||
This one adds up size of files to import to guess number of hands in them
|
||||
Example values of scale and increment params might be 10 and 500 meaning
|
||||
roughly: drop if importing more than 10% (100/scale) of hands in db or if
|
||||
less than 500 hands in db"""
|
||||
size_per_hand = 1300.0 # wag based on a PS 6-up FLHE file. Actual value not hugely important
|
||||
# as values of scale and increment compensate for it anyway.
|
||||
# decimal used to force float arithmetic
|
||||
|
||||
# get number of hands in db
|
||||
if 'handsInDB' not in self.settings:
|
||||
try:
|
||||
tmpcursor = self.fdb.db.cursor()
|
||||
tmpcursor.execute("Select count(1) from Hands;")
|
||||
self.settings['handsInDB'] = tmpcursor.fetchone()[0]
|
||||
except:
|
||||
pass # if this fails we're probably doomed anyway
|
||||
|
||||
# add up size of import files
|
||||
total_size = 0.0
|
||||
for file in self.filelist:
|
||||
if os.path.exists(file):
|
||||
stat_info = os.stat(file)
|
||||
total_size += stat_info.st_size
|
||||
|
||||
# if hands_in_db is zero or very low, we want to drop indexes, otherwise compare
|
||||
# import size with db size somehow:
|
||||
#print "auto2: handsindb =", self.settings['handsInDB'], "total_size =", total_size, "size_per_hand =", \
|
||||
# size_per_hand, "inc =", increment
|
||||
if self.settings['handsInDB'] < scale * (total_size/size_per_hand) + increment:
|
||||
return "drop"
|
||||
return "don't drop"
|
||||
|
||||
#Run import on updated files, then store latest update time.
|
||||
def runUpdated(self):
|
||||
#Check for new files in monitored directories
|
||||
|
@ -359,7 +394,7 @@ class Importer:
|
|||
self.hand=hand
|
||||
|
||||
try:
|
||||
handsId = fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db
|
||||
handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb.db
|
||||
,self.fdb.cursor, self.siteIds[site], category, hand, self.config)
|
||||
self.fdb.db.commit()
|
||||
|
||||
|
|
|
@ -34,11 +34,12 @@ saveActions = True # set this to False to avoid storing action data
|
|||
# variance not available on stats page
|
||||
# : No graphs
|
||||
#stores a stud/razz hand into the database
|
||||
def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time
|
||||
def ring_stud(config, settings, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time
|
||||
,names, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes
|
||||
,action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName
|
||||
,seatNos):
|
||||
|
||||
backend = settings['db-backend']
|
||||
import_options = config.get_import_parameters()
|
||||
|
||||
saveActions = False if import_options['saveActions'] == False else True
|
||||
|
@ -54,7 +55,8 @@ def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametyp
|
|||
,start_cashes, antes, card_values
|
||||
,card_suits, winnings, rakes, seatNos)
|
||||
|
||||
fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop':
|
||||
fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
|
||||
if saveActions:
|
||||
fpdb_simple.storeActions(cursor, hands_players_ids, action_types
|
||||
|
@ -62,12 +64,13 @@ def ring_stud(config, backend, db, cursor, base, category, site_hand_no, gametyp
|
|||
return hands_id
|
||||
#end def ring_stud
|
||||
|
||||
def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no, gametype_id
|
||||
def ring_holdem_omaha(config, settings, db, cursor, base, category, site_hand_no, gametype_id
|
||||
,hand_start_time, names, player_ids, start_cashes, positions, card_values
|
||||
,card_suits, board_values, board_suits, winnings, rakes, action_types, allIns
|
||||
,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos):
|
||||
"""stores a holdem/omaha hand into the database"""
|
||||
|
||||
backend = settings['db-backend']
|
||||
import_options = config.get_import_parameters()
|
||||
saveActions = False if import_options['saveActions'] == False else True
|
||||
fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False
|
||||
|
@ -89,10 +92,11 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no,
|
|||
, positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData)
|
||||
t4 = time()
|
||||
#print "ring holdem, backend=%d" % backend
|
||||
if fastStoreHudCache:
|
||||
fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
else:
|
||||
fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop':
|
||||
if fastStoreHudCache:
|
||||
fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
else:
|
||||
fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
t5 = time()
|
||||
fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits)
|
||||
t6 = time()
|
||||
|
@ -103,7 +107,7 @@ def ring_holdem_omaha(config, backend, db, cursor, base, category, site_hand_no,
|
|||
return hands_id
|
||||
#end def ring_holdem_omaha
|
||||
|
||||
def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout
|
||||
def tourney_holdem_omaha(config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout
|
||||
,entries, prizepool, tourney_start, payin_amounts, ranks, tourneyTypeId
|
||||
,siteId #end of tourney specific params
|
||||
,site_hand_no, gametype_id, hand_start_time, names, player_ids
|
||||
|
@ -112,6 +116,7 @@ def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourne
|
|||
,actionNos, hudImportData, maxSeats, tableName, seatNos):
|
||||
"""stores a tourney holdem/omaha hand into the database"""
|
||||
|
||||
backend = settings['db-backend']
|
||||
import_options = config.get_import_parameters()
|
||||
saveActions = True if import_options['saveActions'] == True else False
|
||||
fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False
|
||||
|
@ -130,10 +135,11 @@ def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourne
|
|||
, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids)
|
||||
|
||||
#print "tourney holdem, backend=%d" % backend
|
||||
if fastStoreHudCache:
|
||||
fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
else:
|
||||
fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop':
|
||||
if fastStoreHudCache:
|
||||
fpdb_simple.storeHudCache2(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
else:
|
||||
fpdb_simple.storeHudCache(backend, cursor, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
|
||||
fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits)
|
||||
|
||||
|
@ -142,13 +148,14 @@ def tourney_holdem_omaha(config, backend, db, cursor, base, category, siteTourne
|
|||
return hands_id
|
||||
#end def tourney_holdem_omaha
|
||||
|
||||
def tourney_stud(config, backend, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries
|
||||
def tourney_stud(config, settings, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries
|
||||
,prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteId
|
||||
,siteHandNo, gametypeId, handStartTime, names, playerIds, startCashes, antes
|
||||
,cardValues, cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts
|
||||
,actionNos, hudImportData, maxSeats, tableName, seatNos):
|
||||
#stores a tourney stud/razz hand into the database
|
||||
|
||||
backend = settings['db-backend']
|
||||
import_options = config.get_import_parameters()
|
||||
saveActions = True if import_options['saveActions'] == True else False
|
||||
fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False
|
||||
|
@ -165,7 +172,8 @@ def tourney_stud(config, backend, db, cursor, base, category, siteTourneyNo, buy
|
|||
, playerIds, startCashes, antes, cardValues, cardSuits
|
||||
, winnings, rakes, seatNos, tourneys_players_ids)
|
||||
|
||||
fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData)
|
||||
if 'updateHudCache' not in settings or settings['updateHudCache'] != 'drop':
|
||||
fpdb_simple.storeHudCache(backend, cursor, base, category, gametypeId, hand_start_time, playerIds, hudImportData)
|
||||
|
||||
if saveActions:
|
||||
fpdb_simple.storeActions(cursor, hands_players_ids, actionTypes, allIns, actionAmounts, actionNos)
|
||||
|
|
Loading…
Reference in New Issue
Block a user