Move functions from fpdb_save_to_db into Database.py
Doesn't actually do much cleanup. Intend on moving all db functions into Database.py and fpdb_db.py and providing and API, the functionality of fpdb_simple et all to shift into the HHC
This commit is contained in:
parent
fdf4b65136
commit
f1921bebde
|
@ -33,6 +33,7 @@ import string
|
||||||
|
|
||||||
# FreePokerTools modules
|
# FreePokerTools modules
|
||||||
import fpdb_db
|
import fpdb_db
|
||||||
|
import fpdb_simple
|
||||||
import Configuration
|
import Configuration
|
||||||
import SQL
|
import SQL
|
||||||
import Card
|
import Card
|
||||||
|
@ -77,6 +78,9 @@ class Database:
|
||||||
#cur.execute(self.sql.query['get_table_name'], (hand_id, ))
|
#cur.execute(self.sql.query['get_table_name'], (hand_id, ))
|
||||||
#row = cur.fetchone()
|
#row = cur.fetchone()
|
||||||
|
|
||||||
|
def commit(self):
|
||||||
|
self.fdb.db.commit()
|
||||||
|
|
||||||
def close_connection(self):
|
def close_connection(self):
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
|
||||||
|
@ -264,6 +268,169 @@ class Database:
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
#import fpdb_simple
|
||||||
|
#
|
||||||
|
#MYSQL_INNODB = 2
|
||||||
|
#PGSQL = 3
|
||||||
|
#SQLITE = 4
|
||||||
|
#
|
||||||
|
#fastStoreHudCache = False # set this to True to test the new storeHudCache routine
|
||||||
|
#
|
||||||
|
#saveActions = True # set this to False to avoid storing action data
|
||||||
|
# # Pros: speeds up imports
|
||||||
|
# # Cons: no action data is saved, so you need to keep the hand histories
|
||||||
|
# # variance not available on stats page
|
||||||
|
# # : No graphs
|
||||||
|
|
||||||
|
|
||||||
|
#stores a stud/razz hand into the database
|
||||||
|
def ring_stud(self, 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
|
||||||
|
fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False
|
||||||
|
|
||||||
|
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
||||||
|
|
||||||
|
hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
||||||
|
,hand_start_time, names, tableName, maxSeats, hudImportData)
|
||||||
|
|
||||||
|
#print "before calling store_hands_players_stud, antes:", antes
|
||||||
|
hands_players_ids = fpdb_simple.store_hands_players_stud(backend, db, cursor, hands_id, player_ids
|
||||||
|
,start_cashes, antes, card_values
|
||||||
|
,card_suits, winnings, rakes, seatNos)
|
||||||
|
|
||||||
|
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
|
||||||
|
,allIns, action_amounts, actionNos)
|
||||||
|
return hands_id
|
||||||
|
#end def ring_stud
|
||||||
|
|
||||||
|
def ring_holdem_omaha(self, 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
|
||||||
|
|
||||||
|
# print "DEBUG: saveActions = '%s' fastStoreHudCache = '%s'"%(saveActions, fastStoreHudCache)
|
||||||
|
# print "DEBUG: import_options = ", import_options
|
||||||
|
|
||||||
|
t0 = time()
|
||||||
|
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
||||||
|
t1 = time()
|
||||||
|
fpdb_simple.fill_board_cards(board_values, board_suits)
|
||||||
|
t2 = time()
|
||||||
|
|
||||||
|
hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
||||||
|
,hand_start_time, names, tableName, maxSeats,
|
||||||
|
hudImportData, board_values, board_suits)
|
||||||
|
t3 = time()
|
||||||
|
hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha(
|
||||||
|
backend, db, cursor, category, hands_id, player_ids, start_cashes
|
||||||
|
, positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData)
|
||||||
|
t4 = time()
|
||||||
|
#print "ring holdem, backend=%d" % backend
|
||||||
|
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()
|
||||||
|
if saveActions:
|
||||||
|
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
||||||
|
t7 = time()
|
||||||
|
#print "fills=(%4.3f) saves=(%4.3f,%4.3f,%4.3f,%4.3f)" % (t2-t0, t3-t2, t4-t3, t5-t4, t6-t5)
|
||||||
|
return hands_id
|
||||||
|
#end def ring_holdem_omaha
|
||||||
|
|
||||||
|
def tourney_holdem_omaha(self, 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
|
||||||
|
,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 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
|
||||||
|
|
||||||
|
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
||||||
|
fpdb_simple.fill_board_cards(board_values, board_suits)
|
||||||
|
|
||||||
|
tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourney_start)
|
||||||
|
tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, player_ids, payin_amounts, ranks, winnings)
|
||||||
|
|
||||||
|
hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
||||||
|
,hand_start_time, names, tableName, maxSeats)
|
||||||
|
|
||||||
|
hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha_tourney(
|
||||||
|
backend, db, cursor, category, hands_id, player_ids, start_cashes, positions
|
||||||
|
, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids)
|
||||||
|
|
||||||
|
#print "tourney holdem, backend=%d" % backend
|
||||||
|
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)
|
||||||
|
|
||||||
|
if saveActions:
|
||||||
|
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
||||||
|
return hands_id
|
||||||
|
#end def tourney_holdem_omaha
|
||||||
|
|
||||||
|
def tourney_stud(self, 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
|
||||||
|
|
||||||
|
fpdb_simple.fillCardArrays(len(names), base, category, cardValues, cardSuits)
|
||||||
|
|
||||||
|
tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourneyStartTime)
|
||||||
|
|
||||||
|
tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, playerIds, payin_amounts, ranks, winnings)
|
||||||
|
|
||||||
|
hands_id = fpdb_simple.storeHands(backend, db, cursor, siteHandNo, gametypeId, handStartTime, names, tableName, maxSeats)
|
||||||
|
|
||||||
|
hands_players_ids = fpdb_simple.store_hands_players_stud_tourney(backend, db, cursor, hands_id
|
||||||
|
, playerIds, startCashes, antes, cardValues, cardSuits
|
||||||
|
, winnings, rakes, seatNos, tourneys_players_ids)
|
||||||
|
|
||||||
|
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)
|
||||||
|
return hands_id
|
||||||
|
#end def tourney_stud
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
c = Configuration.Config()
|
c = Configuration.Config()
|
||||||
|
|
||||||
|
|
|
@ -394,8 +394,8 @@ class Importer:
|
||||||
self.hand=hand
|
self.hand=hand
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb.db
|
handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb
|
||||||
,self.fdb.cursor, self.siteIds[site], category, hand, self.config)
|
, self.siteIds[site], category, hand, self.config)
|
||||||
self.fdb.db.commit()
|
self.fdb.db.commit()
|
||||||
|
|
||||||
stored += 1
|
stored += 1
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
#methods that are specific to holdem but not trivial
|
#methods that are specific to holdem but not trivial
|
||||||
|
|
||||||
import fpdb_simple
|
import fpdb_simple
|
||||||
import fpdb_save_to_db
|
import Database
|
||||||
|
|
||||||
#parses a holdem hand
|
#parses a holdem hand
|
||||||
def mainParser(settings, db, cursor, siteID, category, hand, config):
|
def mainParser(settings, fdb, siteID, category, hand, config):
|
||||||
backend = settings['db-backend']
|
backend = settings['db-backend']
|
||||||
|
#This is redundant - hopefully fdb will be a Database object in an interation soon
|
||||||
|
db = Database.Database(config, 'fpdb', '')
|
||||||
category = fpdb_simple.recogniseCategory(hand[0])
|
category = fpdb_simple.recogniseCategory(hand[0])
|
||||||
|
|
||||||
base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"
|
base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"
|
||||||
|
@ -47,7 +49,7 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
|
||||||
break
|
break
|
||||||
#print "small blind line:",smallBlindLine
|
#print "small blind line:",smallBlindLine
|
||||||
|
|
||||||
gametypeID = fpdb_simple.recogniseGametypeID(backend, db, cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
gametypeID = fpdb_simple.recogniseGametypeID(backend, fdb.db, fdb.cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
||||||
if isTourney:
|
if isTourney:
|
||||||
siteTourneyNo = fpdb_simple.parseTourneyNo(hand[0])
|
siteTourneyNo = fpdb_simple.parseTourneyNo(hand[0])
|
||||||
buyin = fpdb_simple.parseBuyin(hand[0])
|
buyin = fpdb_simple.parseBuyin(hand[0])
|
||||||
|
@ -58,9 +60,9 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
|
||||||
tourneyStartTime= handStartTime #todo: read tourney start time
|
tourneyStartTime= handStartTime #todo: read tourney start time
|
||||||
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
|
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
|
||||||
|
|
||||||
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(cursor, siteID, buyin, fee, knockout, rebuyOrAddon)
|
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(fdb.cursor, siteID, buyin, fee, knockout, rebuyOrAddon)
|
||||||
|
|
||||||
fpdb_simple.isAlreadyInDB(cursor, gametypeID, siteHandNo)
|
fpdb_simple.isAlreadyInDB(fdb.cursor, gametypeID, siteHandNo)
|
||||||
|
|
||||||
hand = fpdb_simple.filterCrap(hand, isTourney)
|
hand = fpdb_simple.filterCrap(hand, isTourney)
|
||||||
|
|
||||||
|
@ -74,7 +76,7 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
|
||||||
seatLines.append(line)
|
seatLines.append(line)
|
||||||
|
|
||||||
names = fpdb_simple.parseNames(seatLines)
|
names = fpdb_simple.parseNames(seatLines)
|
||||||
playerIDs = fpdb_simple.recognisePlayerIDs(cursor, names, siteID)
|
playerIDs = fpdb_simple.recognisePlayerIDs(fdb.cursor, names, siteID)
|
||||||
tmp = fpdb_simple.parseCashesAndSeatNos(seatLines)
|
tmp = fpdb_simple.parseCashesAndSeatNos(seatLines)
|
||||||
startCashes = tmp['startCashes']
|
startCashes = tmp['startCashes']
|
||||||
seatNos = tmp['seatNos']
|
seatNos = tmp['seatNos']
|
||||||
|
@ -113,7 +115,7 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
|
||||||
tableName = tableResult['tableName']
|
tableName = tableResult['tableName']
|
||||||
#print "before part5, antes:", antes
|
#print "before part5, antes:", antes
|
||||||
|
|
||||||
#part 5: final preparations, then call fpdb_save_to_db.* with
|
#part 5: final preparations, then call Database.* with
|
||||||
# the arrays as they are - that file will fill them.
|
# the arrays as they are - that file will fill them.
|
||||||
fpdb_simple.convertCardValues(cardValues)
|
fpdb_simple.convertCardValues(cardValues)
|
||||||
if base == "hold":
|
if base == "hold":
|
||||||
|
@ -121,8 +123,8 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
|
||||||
fpdb_simple.convertBlindBet(actionTypes, actionAmounts)
|
fpdb_simple.convertBlindBet(actionTypes, actionAmounts)
|
||||||
fpdb_simple.checkPositions(positions)
|
fpdb_simple.checkPositions(positions)
|
||||||
|
|
||||||
cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, ))
|
fdb.cursor.execute("SELECT limitType FROM Gametypes WHERE id=%s",(gametypeID, ))
|
||||||
limit_type = cursor.fetchone()[0]
|
limit_type = fdb.cursor.fetchone()[0]
|
||||||
fpdb_simple.convert3B4B(category, limit_type, actionTypes, actionAmounts)
|
fpdb_simple.convert3B4B(category, limit_type, actionTypes, actionAmounts)
|
||||||
|
|
||||||
totalWinnings = sum(winnings)
|
totalWinnings = sum(winnings)
|
||||||
|
@ -143,8 +145,8 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
|
||||||
payin_amounts = fpdb_simple.calcPayin(len(names), buyin, fee)
|
payin_amounts = fpdb_simple.calcPayin(len(names), buyin, fee)
|
||||||
|
|
||||||
if base == "hold":
|
if base == "hold":
|
||||||
result = fpdb_save_to_db.tourney_holdem_omaha(
|
result = db.tourney_holdem_omaha(
|
||||||
config, settings, db, cursor, base, category, siteTourneyNo, buyin
|
config, settings, fdb.db, fdb.cursor, base, category, siteTourneyNo, buyin
|
||||||
, fee, knockout, entries, prizepool, tourneyStartTime
|
, fee, knockout, entries, prizepool, tourneyStartTime
|
||||||
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
|
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
|
||||||
, gametypeID, handStartTime, names, playerIDs, startCashes
|
, gametypeID, handStartTime, names, playerIDs, startCashes
|
||||||
|
@ -152,8 +154,8 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
|
||||||
, winnings, rakes, actionTypes, allIns, actionAmounts
|
, winnings, rakes, actionTypes, allIns, actionAmounts
|
||||||
, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
||||||
elif base == "stud":
|
elif base == "stud":
|
||||||
result = fpdb_save_to_db.tourney_stud(
|
result = db.tourney_stud(
|
||||||
config, settings, db, cursor, base, category, siteTourneyNo
|
config, settings, fdb.db, fdb.cursor, base, category, siteTourneyNo
|
||||||
, buyin, fee, knockout, entries, prizepool, tourneyStartTime
|
, buyin, fee, knockout, entries, prizepool, tourneyStartTime
|
||||||
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
|
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
|
||||||
, gametypeID, handStartTime, names, playerIDs, startCashes
|
, gametypeID, handStartTime, names, playerIDs, startCashes
|
||||||
|
@ -164,23 +166,23 @@ def mainParser(settings, db, cursor, siteID, category, hand, config):
|
||||||
raise fpdb_simple.FpdbError("unrecognised category")
|
raise fpdb_simple.FpdbError("unrecognised category")
|
||||||
else:
|
else:
|
||||||
if base == "hold":
|
if base == "hold":
|
||||||
result = fpdb_save_to_db.ring_holdem_omaha(
|
result = db.ring_holdem_omaha(
|
||||||
config, settings, db, cursor, base, category, siteHandNo
|
config, settings, fdb.db, fdb.cursor, base, category, siteHandNo
|
||||||
, gametypeID, handStartTime, names, playerIDs
|
, gametypeID, handStartTime, names, playerIDs
|
||||||
, startCashes, positions, cardValues, cardSuits
|
, startCashes, positions, cardValues, cardSuits
|
||||||
, boardValues, boardSuits, winnings, rakes
|
, boardValues, boardSuits, winnings, rakes
|
||||||
, actionTypes, allIns, actionAmounts, actionNos
|
, actionTypes, allIns, actionAmounts, actionNos
|
||||||
, hudImportData, maxSeats, tableName, seatNos)
|
, hudImportData, maxSeats, tableName, seatNos)
|
||||||
elif base == "stud":
|
elif base == "stud":
|
||||||
result = fpdb_save_to_db.ring_stud(
|
result = db.ring_stud(
|
||||||
config, settings, db, cursor, base, category, siteHandNo, gametypeID
|
config, settings, fdb.db, fdb.cursor, base, category, siteHandNo, gametypeID
|
||||||
, handStartTime, names, playerIDs, startCashes, antes
|
, handStartTime, names, playerIDs, startCashes, antes
|
||||||
, cardValues, cardSuits, winnings, rakes, actionTypes, allIns
|
, cardValues, cardSuits, winnings, rakes, actionTypes, allIns
|
||||||
, actionAmounts, actionNos, hudImportData, maxSeats, tableName
|
, actionAmounts, actionNos, hudImportData, maxSeats, tableName
|
||||||
, seatNos)
|
, seatNos)
|
||||||
else:
|
else:
|
||||||
raise fpdb_simple.FpdbError ("unrecognised category")
|
raise fpdb_simple.FpdbError ("unrecognised category")
|
||||||
db.commit()
|
fdb.db.commit()
|
||||||
return result
|
return result
|
||||||
#end def mainParser
|
#end def mainParser
|
||||||
|
|
||||||
|
|
|
@ -1,182 +0,0 @@
|
||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
#Copyright 2008 Steffen Jobbagy-Felso
|
|
||||||
#This program is free software: you can redistribute it and/or modify
|
|
||||||
#it under the terms of the GNU Affero General Public License as published by
|
|
||||||
#the Free Software Foundation, version 3 of the License.
|
|
||||||
#
|
|
||||||
#This program is distributed in the hope that it will be useful,
|
|
||||||
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
#GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
#You should have received a copy of the GNU Affero General Public License
|
|
||||||
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#In the "official" distribution you can find the license in
|
|
||||||
#agpl-3.0.txt in the docs folder of the package.
|
|
||||||
|
|
||||||
#This file contains methods to store hands into the db. decides to move this
|
|
||||||
#into a seperate file since its ugly, fairly long and just generally in the way.
|
|
||||||
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
import fpdb_simple
|
|
||||||
|
|
||||||
MYSQL_INNODB = 2
|
|
||||||
PGSQL = 3
|
|
||||||
SQLITE = 4
|
|
||||||
|
|
||||||
fastStoreHudCache = False # set this to True to test the new storeHudCache routine
|
|
||||||
|
|
||||||
saveActions = True # set this to False to avoid storing action data
|
|
||||||
# Pros: speeds up imports
|
|
||||||
# Cons: no action data is saved, so you need to keep the hand histories
|
|
||||||
# variance not available on stats page
|
|
||||||
# : No graphs
|
|
||||||
#stores a stud/razz hand into the database
|
|
||||||
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
|
|
||||||
fastStoreHudCache = True if import_options['fastStoreHudCache'] == True else False
|
|
||||||
|
|
||||||
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
|
||||||
|
|
||||||
hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
|
||||||
,hand_start_time, names, tableName, maxSeats, hudImportData)
|
|
||||||
|
|
||||||
#print "before calling store_hands_players_stud, antes:", antes
|
|
||||||
hands_players_ids = fpdb_simple.store_hands_players_stud(backend, db, cursor, hands_id, player_ids
|
|
||||||
,start_cashes, antes, card_values
|
|
||||||
,card_suits, winnings, rakes, seatNos)
|
|
||||||
|
|
||||||
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
|
|
||||||
,allIns, action_amounts, actionNos)
|
|
||||||
return hands_id
|
|
||||||
#end def ring_stud
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
# print "DEBUG: saveActions = '%s' fastStoreHudCache = '%s'"%(saveActions, fastStoreHudCache)
|
|
||||||
# print "DEBUG: import_options = ", import_options
|
|
||||||
|
|
||||||
t0 = time()
|
|
||||||
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
|
||||||
t1 = time()
|
|
||||||
fpdb_simple.fill_board_cards(board_values, board_suits)
|
|
||||||
t2 = time()
|
|
||||||
|
|
||||||
hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
|
||||||
,hand_start_time, names, tableName, maxSeats,
|
|
||||||
hudImportData, board_values, board_suits)
|
|
||||||
t3 = time()
|
|
||||||
hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha(
|
|
||||||
backend, db, cursor, category, hands_id, player_ids, start_cashes
|
|
||||||
, positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData)
|
|
||||||
t4 = time()
|
|
||||||
#print "ring holdem, backend=%d" % backend
|
|
||||||
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()
|
|
||||||
if saveActions:
|
|
||||||
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
|
||||||
t7 = time()
|
|
||||||
#print "fills=(%4.3f) saves=(%4.3f,%4.3f,%4.3f,%4.3f)" % (t2-t0, t3-t2, t4-t3, t5-t4, t6-t5)
|
|
||||||
return hands_id
|
|
||||||
#end def ring_holdem_omaha
|
|
||||||
|
|
||||||
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
|
|
||||||
,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 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
|
|
||||||
|
|
||||||
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
|
||||||
fpdb_simple.fill_board_cards(board_values, board_suits)
|
|
||||||
|
|
||||||
tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourney_start)
|
|
||||||
tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, player_ids, payin_amounts, ranks, winnings)
|
|
||||||
|
|
||||||
hands_id = fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
|
||||||
,hand_start_time, names, tableName, maxSeats)
|
|
||||||
|
|
||||||
hands_players_ids = fpdb_simple.store_hands_players_holdem_omaha_tourney(
|
|
||||||
backend, db, cursor, category, hands_id, player_ids, start_cashes, positions
|
|
||||||
, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids)
|
|
||||||
|
|
||||||
#print "tourney holdem, backend=%d" % backend
|
|
||||||
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)
|
|
||||||
|
|
||||||
if saveActions:
|
|
||||||
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
|
||||||
return hands_id
|
|
||||||
#end def tourney_holdem_omaha
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
fpdb_simple.fillCardArrays(len(names), base, category, cardValues, cardSuits)
|
|
||||||
|
|
||||||
tourney_id = fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourneyStartTime)
|
|
||||||
|
|
||||||
tourneys_players_ids = fpdb_simple.store_tourneys_players(cursor, tourney_id, playerIds, payin_amounts, ranks, winnings)
|
|
||||||
|
|
||||||
hands_id = fpdb_simple.storeHands(backend, db, cursor, siteHandNo, gametypeId, handStartTime, names, tableName, maxSeats)
|
|
||||||
|
|
||||||
hands_players_ids = fpdb_simple.store_hands_players_stud_tourney(backend, db, cursor, hands_id
|
|
||||||
, playerIds, startCashes, antes, cardValues, cardSuits
|
|
||||||
, winnings, rakes, seatNos, tourneys_players_ids)
|
|
||||||
|
|
||||||
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)
|
|
||||||
return hands_id
|
|
||||||
#end def tourney_stud
|
|
Loading…
Reference in New Issue
Block a user