[NEWIMPORT] Remove legacy code.
This commit is contained in:
parent
262eb5200d
commit
1b82f20411
|
@ -1,66 +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.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import fpdb_simple
|
||||
from optparse import OptionParser
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
except:
|
||||
diaSQLLibMissing = gtk.Dialog(title="Fatal Error - SQL interface library missing", parent=None, flags=0, buttons=(gtk.STOCK_QUIT,gtk.RESPONSE_OK))
|
||||
|
||||
print "Please note that the CLI importer only works with MySQL, if you use PostgreSQL this error is expected."
|
||||
|
||||
import fpdb_import
|
||||
import fpdb_db
|
||||
|
||||
if __name__ == "__main__":
|
||||
#process CLI parameters
|
||||
parser = OptionParser()
|
||||
parser.add_option("-c", "--handCount", default="0", type="int",
|
||||
help="Number of hands to import (default 0 means unlimited)")
|
||||
parser.add_option("-d", "--database", default="fpdb", help="The MySQL database to use (default fpdb)")
|
||||
parser.add_option("-e", "--errorFile", default="failed.txt",
|
||||
help="File to store failed hands into. (default: failed.txt) Not implemented.")
|
||||
parser.add_option("-f", "--inputFile", "--file", "--inputfile", default="stdin",
|
||||
help="The file you want to import (remember to use quotes if necessary)")
|
||||
parser.add_option("-m", "--minPrint", "--status", default="50", type="int",
|
||||
help="How often to print a one-line status report (0 means never, default is 50)")
|
||||
parser.add_option("-p", "--password", help="The password for the MySQL user")
|
||||
parser.add_option("-q", "--quiet", action="store_true",
|
||||
help="If this is passed it doesn't print a total at the end nor the opening line. Note that this purposely does NOT change --minPrint")
|
||||
parser.add_option("-s", "--server", default="localhost",
|
||||
help="Hostname/IP of the MySQL server (default localhost)")
|
||||
parser.add_option("-u", "--user", default="fpdb", help="The MySQL username (default fpdb)")
|
||||
parser.add_option("-x", "--failOnError", action="store_true",
|
||||
help="If this option is passed it quits when it encounters any error")
|
||||
|
||||
(options, argv) = parser.parse_args()
|
||||
|
||||
settings={'callFpdbHud':False, 'db-backend':2}
|
||||
settings['db-host']=options.server
|
||||
settings['db-user']=options.user
|
||||
settings['db-password']=options.password
|
||||
settings['db-databaseName']=options.database
|
||||
settings['handCount']=options.handCount
|
||||
settings['failOnError']=options.failOnError
|
||||
|
||||
importer = fpdb_import.Importer(options, settings)
|
||||
importer.addImportFile(options.inputFile)
|
||||
importer.runImport()
|
|
@ -43,7 +43,6 @@ import Queue
|
|||
|
||||
# FreePokerTools modules
|
||||
import fpdb_db
|
||||
import fpdb_simple
|
||||
import Configuration
|
||||
import SQL
|
||||
import Card
|
||||
|
@ -724,120 +723,6 @@ class Database:
|
|||
return ret
|
||||
|
||||
|
||||
#stores a stud/razz hand into the database
|
||||
def ring_stud(self, config, settings, 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):
|
||||
|
||||
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
||||
|
||||
hands_id = self.storeHands(self.backend, site_hand_no, gametype_id
|
||||
,hand_start_time, names, tableName, maxSeats, hudImportData
|
||||
,(None, None, None, None, None), (None, None, None, None, None))
|
||||
|
||||
#print "before calling store_hands_players_stud, antes:", antes
|
||||
hands_players_ids = self.store_hands_players_stud(self.backend, hands_id, player_ids
|
||||
,start_cashes, antes, card_values
|
||||
,card_suits, winnings, rakes, seatNos)
|
||||
|
||||
if 'dropHudCache' not in settings or settings['dropHudCache'] != 'drop':
|
||||
self.storeHudCache(self.backend, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
|
||||
return hands_id
|
||||
#end def ring_stud
|
||||
|
||||
def ring_holdem_omaha(self, config, settings, 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"""
|
||||
|
||||
t0 = time()
|
||||
#print "in ring_holdem_omaha"
|
||||
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 = self.storeHands(self.backend, site_hand_no, gametype_id
|
||||
,hand_start_time, names, tableName, maxSeats
|
||||
,hudImportData, board_values, board_suits)
|
||||
#TEMPORARY CALL! - Just until all functions are migrated
|
||||
t3 = time()
|
||||
hands_players_ids = self.store_hands_players_holdem_omaha(
|
||||
self.backend, category, hands_id, player_ids, start_cashes
|
||||
, positions, card_values, card_suits, winnings, rakes, seatNos, hudImportData)
|
||||
t4 = time()
|
||||
if 'dropHudCache' not in settings or settings['dropHudCache'] != 'drop':
|
||||
self.storeHudCache(self.backend, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
t5 = time()
|
||||
#print "fills=(%4.3f) saves=(%4.3f,%4.3f,%4.3f)" % (t2-t0, t3-t2, t4-t3, t5-t4)
|
||||
return hands_id
|
||||
#end def ring_holdem_omaha
|
||||
|
||||
def tourney_holdem_omaha(self, config, settings, 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"""
|
||||
|
||||
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
||||
fpdb_simple.fill_board_cards(board_values, board_suits)
|
||||
|
||||
tourney_id = self.store_tourneys(tourneyTypeId, siteTourneyNo, entries, prizepool, tourney_start)
|
||||
tourneys_players_ids = self.store_tourneys_players(tourney_id, player_ids, payin_amounts, ranks, winnings)
|
||||
|
||||
hands_id = self.storeHands(self.backend, site_hand_no, gametype_id
|
||||
,hand_start_time, names, tableName, maxSeats
|
||||
,hudImportData, board_values, board_suits)
|
||||
|
||||
hands_players_ids = self.store_hands_players_holdem_omaha_tourney(
|
||||
self.backend, category, hands_id, player_ids, start_cashes, positions
|
||||
, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids
|
||||
, hudImportData, tourneyTypeId)
|
||||
|
||||
#print "tourney holdem, backend=%d" % backend
|
||||
if 'dropHudCache' not in settings or settings['dropHudCache'] != 'drop':
|
||||
self.storeHudCache(self.backend, base, category, gametype_id, hand_start_time, player_ids, hudImportData)
|
||||
|
||||
return hands_id
|
||||
#end def tourney_holdem_omaha
|
||||
|
||||
def tourney_stud(self, config, settings, 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
|
||||
|
||||
fpdb_simple.fillCardArrays(len(names), base, category, cardValues, cardSuits)
|
||||
|
||||
tourney_id = self.store_tourneys(tourneyTypeId, siteTourneyNo, entries, prizepool, tourneyStartTime)
|
||||
|
||||
tourneys_players_ids = self.store_tourneys_players(tourney_id, playerIds, payin_amounts, ranks, winnings)
|
||||
|
||||
hands_id = self.storeHands( self.backend, siteHandNo, gametypeId
|
||||
, handStartTime, names, tableName, maxSeats
|
||||
, hudImportData, (None, None, None, None, None), (None, None, None, None, None) )
|
||||
# changed board_values and board_suits to arrays of None, just like the
|
||||
# cash game version of this function does - i don't believe this to be
|
||||
# the correct thing to do (tell me if i'm wrong) but it should keep the
|
||||
# importer from crashing
|
||||
|
||||
hands_players_ids = self.store_hands_players_stud_tourney(self.backend, hands_id
|
||||
, playerIds, startCashes, antes, cardValues, cardSuits
|
||||
, winnings, rakes, seatNos, tourneys_players_ids, tourneyTypeId)
|
||||
|
||||
if 'dropHudCache' not in settings or settings['dropHudCache'] != 'drop':
|
||||
self.storeHudCache(self.backend, base, category, gametypeId, handStartTime, playerIds, hudImportData)
|
||||
|
||||
return hands_id
|
||||
#end def tourney_stud
|
||||
|
||||
def prepareBulkImport(self):
|
||||
"""Drop some indexes/foreign keys to prepare for bulk import.
|
||||
Currently keeping the standalone indexes as needed to import quickly"""
|
||||
|
@ -1465,64 +1350,6 @@ class Database:
|
|||
print "Error during fdb.lock_for_insert:", str(sys.exc_value)
|
||||
#end def lock_for_insert
|
||||
|
||||
def store_the_hand(self, h):
|
||||
"""Take a HandToWrite object and store it in the db"""
|
||||
|
||||
# Following code writes hands to database and commits (or rolls back if there is an error)
|
||||
try:
|
||||
result = None
|
||||
if h.isTourney:
|
||||
ranks = map(lambda x: 0, h.names) # create an array of 0's equal to the length of names
|
||||
payin_amounts = fpdb_simple.calcPayin(len(h.names), h.buyin, h.fee)
|
||||
|
||||
if h.base == "hold":
|
||||
result = self.tourney_holdem_omaha(
|
||||
h.config, h.settings, h.base, h.category, h.siteTourneyNo, h.buyin
|
||||
, h.fee, h.knockout, h.entries, h.prizepool, h.tourneyStartTime
|
||||
, payin_amounts, ranks, h.tourneyTypeId, h.siteID, h.siteHandNo
|
||||
, h.gametypeID, h.handStartTime, h.names, h.playerIDs, h.startCashes
|
||||
, h.positions, h.cardValues, h.cardSuits, h.boardValues, h.boardSuits
|
||||
, h.winnings, h.rakes, h.actionTypes, h.allIns, h.actionAmounts
|
||||
, h.actionNos, h.hudImportData, h.maxSeats, h.tableName, h.seatNos)
|
||||
elif h.base == "stud":
|
||||
result = self.tourney_stud(
|
||||
h.config, h.settings, h.base, h.category, h.siteTourneyNo
|
||||
, h.buyin, h.fee, h.knockout, h.entries, h.prizepool, h.tourneyStartTime
|
||||
, payin_amounts, ranks, h.tourneyTypeId, h.siteID, h.siteHandNo
|
||||
, h.gametypeID, h.handStartTime, h.names, h.playerIDs, h.startCashes
|
||||
, h.antes, h.cardValues, h.cardSuits, h.winnings, h.rakes, h.actionTypes
|
||||
, h.allIns, h.actionAmounts, h.actionNos, h.hudImportData, h.maxSeats
|
||||
, h.tableName, h.seatNos)
|
||||
else:
|
||||
raise FpdbError("unrecognised category")
|
||||
else:
|
||||
if h.base == "hold":
|
||||
result = self.ring_holdem_omaha(
|
||||
h.config, h.settings, h.base, h.category, h.siteHandNo
|
||||
, h.gametypeID, h.handStartTime, h.names, h.playerIDs
|
||||
, h.startCashes, h.positions, h.cardValues, h.cardSuits
|
||||
, h.boardValues, h.boardSuits, h.winnings, h.rakes
|
||||
, h.actionTypes, h.allIns, h.actionAmounts, h.actionNos
|
||||
, h.hudImportData, h.maxSeats, h.tableName, h.seatNos)
|
||||
elif h.base == "stud":
|
||||
result = self.ring_stud(
|
||||
h.config, h.settings, h.base, h.category, h.siteHandNo, h.gametypeID
|
||||
, h.handStartTime, h.names, h.playerIDs, h.startCashes, h.antes
|
||||
, h.cardValues, h.cardSuits, h.winnings, h.rakes, h.actionTypes, h.allIns
|
||||
, h.actionAmounts, h.actionNos, h.hudImportData, h.maxSeats, h.tableName
|
||||
, h.seatNos)
|
||||
else:
|
||||
raise FpdbError("unrecognised category")
|
||||
except:
|
||||
print "Error storing hand: " + str(sys.exc_value)
|
||||
self.rollback()
|
||||
# re-raise the exception so that the calling routine can decide what to do:
|
||||
# (e.g. a write thread might try again)
|
||||
raise
|
||||
|
||||
return result
|
||||
#end def store_the_hand
|
||||
|
||||
###########################
|
||||
# NEWIMPORT CODE
|
||||
###########################
|
||||
|
@ -2583,183 +2410,6 @@ class Database:
|
|||
#end def tRecogniseTourneyType
|
||||
|
||||
|
||||
def tRecognizeTourney(self, tourney, dbTourneyTypeId):
|
||||
logging.debug("Database.tRecognizeTourney")
|
||||
tourneyID = 1
|
||||
# Check if tourney exists in db (based on tourney.siteId and tourney.tourNo)
|
||||
# If so retrieve all data to check for consistency
|
||||
cursor = self.get_cursor()
|
||||
cursor.execute (self.sql.query['getTourney'].replace('%s', self.sql.query['placeholder']),
|
||||
(tourney.tourNo, tourney.siteId)
|
||||
)
|
||||
result=cursor.fetchone()
|
||||
|
||||
expectedValuesDecimal = { 2 : "entries", 3 : "prizepool", 6 : "buyInChips", 9 : "rebuyChips",
|
||||
10 : "addOnChips", 11 : "rebuyAmount", 12 : "addOnAmount", 13 : "totalRebuys",
|
||||
14 : "totalAddOns", 15 : "koBounty" }
|
||||
expectedValues = { 7 : "tourneyName", 16 : "tourneyComment" }
|
||||
|
||||
tourneyDataMatch = True
|
||||
tCommentTs = None
|
||||
starttime = None
|
||||
endtime = None
|
||||
|
||||
try:
|
||||
len(result)
|
||||
tourneyID = result[0]
|
||||
logging.debug("Tourney found in db with TourneyID = %d" % tourneyID)
|
||||
if result[1] <> dbTourneyTypeId:
|
||||
tourneyDataMatch = False
|
||||
logging.debug("Tourney has wrong type ID (expected : %s - found : %s)" % (dbTourneyTypeId, result[1]))
|
||||
if (tourney.starttime is None and result[4] is not None) or ( tourney.starttime is not None and fpdb_simple.parseHandStartTime("- %s" % tourney.starttime) <> result[4]) :
|
||||
tourneyDataMatch = False
|
||||
logging.debug("Tourney data mismatch : wrong starttime : Tourney=%s / db=%s" % (tourney.starttime, result[4]))
|
||||
if (tourney.endtime is None and result[5] is not None) or ( tourney.endtime is not None and fpdb_simple.parseHandStartTime("- %s" % tourney.endtime) <> result[5]) :
|
||||
tourneyDataMatch = False
|
||||
logging.debug("Tourney data mismatch : wrong endtime : Tourney=%s / db=%s" % (tourney.endtime, result[5]))
|
||||
|
||||
for ev in expectedValues :
|
||||
if ( getattr( tourney, expectedValues.get(ev) ) <> result[ev] ):
|
||||
logging.debug("Tourney data mismatch : wrong %s : Tourney=%s / db=%s" % (expectedValues.get(ev), getattr( tourney, expectedValues.get(ev)), result[ev]) )
|
||||
tourneyDataMatch = False
|
||||
#break
|
||||
for evD in expectedValuesDecimal :
|
||||
if ( Decimal(getattr( tourney, expectedValuesDecimal.get(evD)) ) <> result[evD] ):
|
||||
logging.debug("Tourney data mismatch : wrong %s : Tourney=%s / db=%s" % (expectedValuesDecimal.get(evD), getattr( tourney, expectedValuesDecimal.get(evD)), result[evD]) )
|
||||
tourneyDataMatch = False
|
||||
#break
|
||||
|
||||
# TO DO : Deal with matrix summary mutliple parsings
|
||||
|
||||
except:
|
||||
# Tourney not found : create
|
||||
logging.debug("Tourney is not found : create")
|
||||
if tourney.tourneyComment is not None :
|
||||
tCommentTs = datetime.today()
|
||||
if tourney.starttime is not None :
|
||||
starttime = fpdb_simple.parseHandStartTime("- %s" % tourney.starttime)
|
||||
if tourney.endtime is not None :
|
||||
endtime = fpdb_simple.parseHandStartTime("- %s" % tourney.endtime)
|
||||
# TODO : deal with matrix Id processed
|
||||
cursor.execute (self.sql.query['insertTourney'].replace('%s', self.sql.query['placeholder']),
|
||||
(dbTourneyTypeId, tourney.tourNo, tourney.entries, tourney.prizepool, starttime,
|
||||
endtime, tourney.buyInChips, tourney.tourneyName, 0, tourney.rebuyChips, tourney.addOnChips,
|
||||
tourney.rebuyAmount, tourney.addOnAmount, tourney.totalRebuys, tourney.totalAddOns, tourney.koBounty,
|
||||
tourney.tourneyComment, tCommentTs)
|
||||
)
|
||||
tourneyID = self.get_last_insert_id(cursor)
|
||||
|
||||
|
||||
# Deal with inconsistent tourney in db
|
||||
if tourneyDataMatch == False :
|
||||
# Update Tourney
|
||||
if result[16] <> tourney.tourneyComment :
|
||||
tCommentTs = datetime.today()
|
||||
if tourney.starttime is not None :
|
||||
starttime = fpdb_simple.parseHandStartTime("- %s" % tourney.starttime)
|
||||
if tourney.endtime is not None :
|
||||
endtime = fpdb_simple.parseHandStartTime("- %s" % tourney.endtime)
|
||||
|
||||
cursor.execute (self.sql.query['updateTourney'].replace('%s', self.sql.query['placeholder']),
|
||||
(dbTourneyTypeId, tourney.entries, tourney.prizepool, starttime,
|
||||
endtime, tourney.buyInChips, tourney.tourneyName, 0, tourney.rebuyChips, tourney.addOnChips,
|
||||
tourney.rebuyAmount, tourney.addOnAmount, tourney.totalRebuys, tourney.totalAddOns, tourney.koBounty,
|
||||
tourney.tourneyComment, tCommentTs, tourneyID)
|
||||
)
|
||||
|
||||
return tourneyID
|
||||
#end def tRecognizeTourney
|
||||
|
||||
def tStoreTourneyPlayers(self, tourney, dbTourneyId):
|
||||
logging.debug("Database.tStoreTourneyPlayers")
|
||||
# First, get playerids for the players and specifically the one for hero :
|
||||
playersIds = self.recognisePlayerIDs(tourney.players, tourney.siteId)
|
||||
# hero may be None for matrix tourneys summaries
|
||||
# hero = [ tourney.hero ]
|
||||
# heroId = self.recognisePlayerIDs(hero , tourney.siteId)
|
||||
# logging.debug("hero Id = %s - playersId = %s" % (heroId , playersIds))
|
||||
|
||||
tourneyPlayersIds=[]
|
||||
try:
|
||||
cursor = self.get_cursor()
|
||||
|
||||
for i in xrange(len(playersIds)):
|
||||
cursor.execute(self.sql.query['getTourneysPlayers'].replace('%s', self.sql.query['placeholder'])
|
||||
,(dbTourneyId, playersIds[i]))
|
||||
result=cursor.fetchone()
|
||||
#print "tried SELECTing tourneys_players.id:",tmp
|
||||
|
||||
try:
|
||||
len(result)
|
||||
# checking data
|
||||
logging.debug("TourneysPlayers found : checking data")
|
||||
expectedValuesDecimal = { 1 : "payinAmounts", 2 : "finishPositions", 3 : "winnings", 4 : "countRebuys",
|
||||
5 : "countAddOns", 6 : "countKO" }
|
||||
|
||||
tourneyPlayersIds.append(result[0]);
|
||||
|
||||
tourneysPlayersDataMatch = True
|
||||
for evD in expectedValuesDecimal :
|
||||
if ( Decimal(getattr( tourney, expectedValuesDecimal.get(evD))[tourney.players[i]] ) <> result[evD] ):
|
||||
logging.debug("TourneysPlayers data mismatch for TourneysPlayer id=%d, name=%s : wrong %s : Tourney=%s / db=%s" % (result[0], tourney.players[i], expectedValuesDecimal.get(evD), getattr( tourney, expectedValuesDecimal.get(evD))[tourney.players[i]], result[evD]) )
|
||||
tourneysPlayersDataMatch = False
|
||||
#break
|
||||
|
||||
if tourneysPlayersDataMatch == False:
|
||||
logging.debug("TourneysPlayers data update needed")
|
||||
cursor.execute (self.sql.query['updateTourneysPlayers'].replace('%s', self.sql.query['placeholder']),
|
||||
(tourney.payinAmounts[tourney.players[i]], tourney.finishPositions[tourney.players[i]],
|
||||
tourney.winnings[tourney.players[i]] , tourney.countRebuys[tourney.players[i]],
|
||||
tourney.countAddOns[tourney.players[i]] , tourney.countKO[tourney.players[i]],
|
||||
result[7], result[8], result[0])
|
||||
)
|
||||
|
||||
except TypeError:
|
||||
logging.debug("TourneysPlayers not found : need insert")
|
||||
cursor.execute (self.sql.query['insertTourneysPlayers'].replace('%s', self.sql.query['placeholder']),
|
||||
(dbTourneyId, playersIds[i],
|
||||
tourney.payinAmounts[tourney.players[i]], tourney.finishPositions[tourney.players[i]],
|
||||
tourney.winnings[tourney.players[i]] , tourney.countRebuys[tourney.players[i]],
|
||||
tourney.countAddOns[tourney.players[i]] , tourney.countKO[tourney.players[i]],
|
||||
None, None)
|
||||
)
|
||||
tourneyPlayersIds.append(self.get_last_insert_id(cursor))
|
||||
|
||||
except:
|
||||
raise fpdb_simple.FpdbError( "tStoreTourneyPlayers error: " + str(sys.exc_value) )
|
||||
|
||||
return tourneyPlayersIds
|
||||
#end def tStoreTourneyPlayers
|
||||
|
||||
def tUpdateTourneysHandsPlayers(self, tourney, dbTourneysPlayersIds, dbTourneyTypeId):
|
||||
logging.debug("Database.tCheckTourneysHandsPlayers")
|
||||
try:
|
||||
# Massive update seems to take quite some time ...
|
||||
# query = self.sql.query['updateHandsPlayersForTTypeId2'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner'].join([self.sql.query['placeholder'] for id in dbTourneysPlayersIds]) )
|
||||
# cursor = self.get_cursor()
|
||||
# cursor.execute (query, dbTourneysPlayersIds)
|
||||
|
||||
query = self.sql.query['selectHandsPlayersWithWrongTTypeId'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner'].join([self.sql.query['placeholder'] for id in dbTourneysPlayersIds]) )
|
||||
#print "query : %s" % query
|
||||
cursor = self.get_cursor()
|
||||
cursor.execute (query, dbTourneysPlayersIds)
|
||||
result=cursor.fetchall()
|
||||
|
||||
if (len(result) > 0):
|
||||
logging.debug("%d lines need update : %s" % (len(result), result) )
|
||||
listIds = []
|
||||
for i in result:
|
||||
listIds.append(i[0])
|
||||
|
||||
query2 = self.sql.query['updateHandsPlayersForTTypeId'] % (dbTourneyTypeId, self.sql.query['handsPlayersTTypeId_joiner_id'].join([self.sql.query['placeholder'] for id in listIds]) )
|
||||
cursor.execute (query2, listIds)
|
||||
else:
|
||||
logging.debug("No need to update, HandsPlayers are correct")
|
||||
|
||||
except:
|
||||
raise fpdb_simple.FpdbError( "tStoreTourneyPlayers error: " + str(sys.exc_value) )
|
||||
#end def tUpdateTourneysHandsPlayers
|
||||
|
||||
|
||||
# Class used to hold all the data needed to write a hand to the db
|
||||
# mainParser() in fpdb_parse_logic.py creates one of these and then passes it to
|
||||
|
|
|
@ -30,7 +30,6 @@ import gtk
|
|||
import gobject
|
||||
|
||||
# fpdb/FreePokerTools modules
|
||||
import fpdb_simple
|
||||
import fpdb_import
|
||||
import Configuration
|
||||
import Exceptions
|
||||
|
|
|
@ -20,7 +20,6 @@ import pygtk
|
|||
pygtk.require('2.0')
|
||||
import gtk
|
||||
import os
|
||||
import fpdb_simple
|
||||
|
||||
import fpdb_import
|
||||
import fpdb_db
|
||||
|
|
|
@ -38,7 +38,6 @@ except ImportError:
|
|||
logging.info("Not using numpy to define variance in sqlite.")
|
||||
use_numpy = False
|
||||
|
||||
import fpdb_simple
|
||||
import FpdbSQLQueries
|
||||
import Configuration
|
||||
|
||||
|
|
|
@ -35,10 +35,8 @@ import gtk
|
|||
|
||||
# fpdb/FreePokerTools modules
|
||||
|
||||
import fpdb_simple
|
||||
import fpdb_db
|
||||
import Database
|
||||
import fpdb_parse_logic
|
||||
import Configuration
|
||||
import Exceptions
|
||||
|
||||
|
|
|
@ -1,235 +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.
|
||||
|
||||
#parses an in-memory fpdb hand history and calls db routine to store it
|
||||
|
||||
import sys
|
||||
from time import time, strftime
|
||||
from Exceptions import *
|
||||
|
||||
import fpdb_simple
|
||||
import Database
|
||||
|
||||
def mainParser(settings, siteID, category, hand, config, db = None, writeq = None):
|
||||
""" mainParser for Holdem Hands """
|
||||
t0 = time()
|
||||
backend = settings['db-backend']
|
||||
# Ideally db connection is passed in, if not use sql list if passed in,
|
||||
# otherwise start from scratch
|
||||
if db is None:
|
||||
db = Database.Database(c = config, sql = None)
|
||||
category = fpdb_simple.recogniseCategory(hand[0])
|
||||
|
||||
base = "hold" if (category == "holdem" or category == "omahahi" or
|
||||
category == "omahahilo") else "stud"
|
||||
|
||||
#part 0: create the empty arrays
|
||||
# lineTypes valid values: header, name, cards, action, win, rake, ignore
|
||||
# lineStreets valid values: predeal, preflop, flop, turn, river
|
||||
lineTypes = []
|
||||
lineStreets = []
|
||||
cardValues = []
|
||||
cardSuits = []
|
||||
boardValues = []
|
||||
boardSuits = []
|
||||
antes = []
|
||||
allIns = []
|
||||
actionAmounts = []
|
||||
actionNos = []
|
||||
actionTypes = []
|
||||
actionTypeByNo = []
|
||||
seatLines = []
|
||||
winnings = []
|
||||
rakes = []
|
||||
|
||||
#part 1: read hand no and check for duplicate
|
||||
siteHandNo = fpdb_simple.parseSiteHandNo(hand[0])
|
||||
handStartTime = fpdb_simple.parseHandStartTime(hand[0])
|
||||
isTourney = fpdb_simple.isTourney(hand[0])
|
||||
|
||||
smallBlindLine = None
|
||||
for i, line in enumerate(hand):
|
||||
if 'posts small blind' in line or 'posts the small blind' in line:
|
||||
if line[-2:] == "$0": continue
|
||||
smallBlindLine = i
|
||||
break
|
||||
else:
|
||||
smallBlindLine = 0
|
||||
# If we did not find a small blind line, what happens?
|
||||
# if we leave it at None, it errors two lines down.
|
||||
|
||||
gametypeID = fpdb_simple.recogniseGametypeID(backend, db, db.get_cursor(),
|
||||
hand[0], hand[smallBlindLine],
|
||||
siteID, category, isTourney)
|
||||
if isTourney:
|
||||
siteTourneyNo = fpdb_simple.parseTourneyNo(hand[0])
|
||||
buyin = fpdb_simple.parseBuyin(hand[0])
|
||||
fee = fpdb_simple.parseFee(hand[0])
|
||||
entries = -1 #todo: parse this
|
||||
prizepool = -1 #todo: parse this
|
||||
knockout = False
|
||||
tourneyStartTime= handStartTime #todo: read tourney start time
|
||||
rebuyOrAddon = fpdb_simple.isRebuyOrAddon(hand[0])
|
||||
|
||||
# The tourney site id has to be searched because it may already be in
|
||||
# db with a TourneyTypeId which is different from the one automatically
|
||||
# calculated (Summary import first)
|
||||
tourneyTypeId = fpdb_simple.recogniseTourneyTypeId(db, siteID,
|
||||
siteTourneyNo,
|
||||
buyin, fee,
|
||||
knockout,
|
||||
rebuyOrAddon)
|
||||
else:
|
||||
siteTourneyNo = -1
|
||||
buyin = -1
|
||||
fee = -1
|
||||
entries = -1
|
||||
prizepool = -1
|
||||
knockout = 0
|
||||
tourneyStartTime= None
|
||||
rebuyOrAddon = -1
|
||||
|
||||
tourneyTypeId = 1
|
||||
fpdb_simple.isAlreadyInDB(db, gametypeID, siteHandNo)
|
||||
|
||||
hand = fpdb_simple.filterCrap(hand, isTourney)
|
||||
|
||||
#part 2: classify lines by type (e.g. cards, action, win, sectionchange) and street
|
||||
fpdb_simple.classifyLines(hand, category, lineTypes, lineStreets)
|
||||
|
||||
#part 3: read basic player info
|
||||
#3a read player names, startcashes
|
||||
for i, line in enumerate(hand):
|
||||
if lineTypes[i] == "name":
|
||||
seatLines.append(line)
|
||||
|
||||
names = fpdb_simple.parseNames(seatLines)
|
||||
playerIDs = db.recognisePlayerIDs(names, siteID) # inserts players as needed
|
||||
tmp = fpdb_simple.parseCashesAndSeatNos(seatLines)
|
||||
startCashes = tmp['startCashes']
|
||||
seatNos = tmp['seatNos']
|
||||
|
||||
fpdb_simple.createArrays(category, len(names), cardValues, cardSuits, antes,
|
||||
winnings, rakes, actionTypes, allIns,
|
||||
actionAmounts, actionNos, actionTypeByNo)
|
||||
|
||||
#3b read positions
|
||||
if base == "hold":
|
||||
positions = fpdb_simple.parsePositions(hand, names)
|
||||
|
||||
#part 4: take appropriate action for each line based on linetype
|
||||
for i, line in enumerate(hand):
|
||||
if lineTypes[i] == "cards":
|
||||
fpdb_simple.parseCardLine(category, lineStreets[i], line, names,
|
||||
cardValues, cardSuits, boardValues,
|
||||
boardSuits)
|
||||
#if category=="studhilo":
|
||||
# print "hand[i]:", hand[i]
|
||||
# print "cardValues:", cardValues
|
||||
# print "cardSuits:", cardSuits
|
||||
elif lineTypes[i] == "action":
|
||||
fpdb_simple.parseActionLine(base, isTourney, line, lineStreets[i],
|
||||
playerIDs, names, actionTypes, allIns,
|
||||
actionAmounts, actionNos, actionTypeByNo)
|
||||
elif lineTypes[i] == "win":
|
||||
fpdb_simple.parseWinLine(line, names, winnings, isTourney)
|
||||
elif lineTypes[i] == "rake":
|
||||
totalRake = 0 if isTourney else fpdb_simple.parseRake(line)
|
||||
fpdb_simple.splitRake(winnings, rakes, totalRake)
|
||||
elif (lineTypes[i] == "header" or lineTypes[i] == "rake" or
|
||||
lineTypes[i] == "name" or lineTypes[i] == "ignore"):
|
||||
pass
|
||||
elif lineTypes[i] == "ante":
|
||||
fpdb_simple.parseAnteLine(line, isTourney, names, antes)
|
||||
elif lineTypes[i] == "table":
|
||||
tableResult=fpdb_simple.parseTableLine(base, line)
|
||||
else:
|
||||
raise FpdbError("unrecognised lineType:" + lineTypes[i])
|
||||
|
||||
maxSeats = tableResult['maxSeats']
|
||||
tableName = tableResult['tableName']
|
||||
#print "before part5, antes:", antes
|
||||
|
||||
#part 5: final preparations, then call Database.* with
|
||||
# the arrays as they are - that file will fill them.
|
||||
fpdb_simple.convertCardValues(cardValues)
|
||||
if base == "hold":
|
||||
fpdb_simple.convertCardValuesBoard(boardValues)
|
||||
fpdb_simple.convertBlindBet(actionTypes, actionAmounts)
|
||||
fpdb_simple.checkPositions(positions)
|
||||
|
||||
c = db.get_cursor()
|
||||
c.execute("SELECT limitType FROM Gametypes WHERE id=%s" % (db.sql.query['placeholder'],), (gametypeID, ))
|
||||
limit_type = c.fetchone()[0]
|
||||
fpdb_simple.convert3B4B(category, limit_type, actionTypes, actionAmounts)
|
||||
|
||||
totalWinnings = sum(winnings)
|
||||
|
||||
# if hold'em, use positions and not antes, if stud do not use positions, use antes
|
||||
# this is used for handsplayers inserts, so still needed even if hudcache update is being skipped
|
||||
if base == "hold":
|
||||
hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base,
|
||||
category, actionTypes,
|
||||
allIns, actionTypeByNo,
|
||||
winnings,
|
||||
totalWinnings,
|
||||
positions, actionTypes,
|
||||
actionAmounts, None)
|
||||
else:
|
||||
hudImportData = fpdb_simple.generateHudCacheData(playerIDs, base,
|
||||
category, actionTypes,
|
||||
allIns, actionTypeByNo,
|
||||
winnings,
|
||||
totalWinnings, None,
|
||||
actionTypes,
|
||||
actionAmounts, antes)
|
||||
|
||||
try:
|
||||
db.commit() # need to commit new players as different db connection used
|
||||
# for other writes. maybe this will change maybe not ...
|
||||
except: # TODO: this really needs to be narrowed down
|
||||
print "parse: error during commit: " + str(sys.exc_value)
|
||||
|
||||
# HERE's an ugly kludge to keep from failing when positions is undef
|
||||
# We'll fix this by getting rid of the legacy importer. REB
|
||||
try:
|
||||
if positions:
|
||||
pass
|
||||
except NameError:
|
||||
positions = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
# save data structures in a HandToWrite instance and then insert into database:
|
||||
htw = Database.HandToWrite()
|
||||
htw.set_all( config, settings, base, category, siteTourneyNo, buyin
|
||||
, fee, knockout, entries, prizepool, tourneyStartTime
|
||||
, isTourney, tourneyTypeId, siteID, siteHandNo
|
||||
, gametypeID, handStartTime, names, playerIDs, startCashes
|
||||
, positions, antes, cardValues, cardSuits, boardValues, boardSuits
|
||||
, winnings, rakes, actionTypes, allIns, actionAmounts
|
||||
, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
||||
|
||||
# save hand in db via direct call or via q if in a thread
|
||||
if writeq is None:
|
||||
result = db.store_the_hand(htw)
|
||||
else:
|
||||
writeq.put(htw)
|
||||
result = -999 # meaning unknown
|
||||
|
||||
t9 = time()
|
||||
#print "parse and save=(%4.3f)" % (t9-t0)
|
||||
return result
|
||||
#end def mainParser
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user