From a87f43f9336a15f8fff47b2b30d5b1dfc9211a42 Mon Sep 17 00:00:00 2001 From: Chaz Littlejohn Date: Thu, 24 Mar 2011 06:00:10 +0000 Subject: [PATCH] Updated the import process for Draw hands so that cards, along with additional draws can now be stored. HandsPlayers now includes 20 card fields to accomodate up to 4 five card hands for each player. The regex for the 'stands pat' action was also improved so that hero cards from those streets could be taken from that line of text --- pyfpdb/Database.py | 15 +++++++++- pyfpdb/DerivedStats.py | 6 ++-- pyfpdb/FulltiltToFpdb.py | 9 ++---- pyfpdb/Hand.py | 14 ++++++++-- pyfpdb/PokerStarsToFpdb.py | 7 +++-- pyfpdb/SQL.py | 57 +++++++++++++++++++++++++++++++++++++- 6 files changed, 92 insertions(+), 16 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 9e7895be..38eb802e 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -73,7 +73,7 @@ except ImportError: use_numpy = False -DB_VERSION = 151 +DB_VERSION = 152 # Variance created as sqlite has a bunch of undefined aggregate functions. @@ -1915,6 +1915,19 @@ class Database: pdata[p]['card5'], pdata[p]['card6'], pdata[p]['card7'], + pdata[p]['card8'], + pdata[p]['card9'], + pdata[p]['card10'], + pdata[p]['card11'], + pdata[p]['card12'], + pdata[p]['card13'], + pdata[p]['card14'], + pdata[p]['card15'], + pdata[p]['card16'], + pdata[p]['card17'], + pdata[p]['card18'], + pdata[p]['card19'], + pdata[p]['card20'], pdata[p]['winnings'], pdata[p]['rake'], pdata[p]['totalProfit'], diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index 3b955929..d29a33ad 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -214,10 +214,10 @@ class DerivedStats(): for player in hand.players: hcs = hand.join_holecards(player[1], asList=True) - hcs = hcs + [u'0x', u'0x', u'0x', u'0x', u'0x'] - #for i, card in enumerate(hcs[:7], 1): #Python 2.6 syntax + hcs = hcs + [u'0x']*18 + #for i, card in enumerate(hcs[:20, 1): #Python 2.6 syntax # self.handsplayers[player[1]]['card%s' % i] = Card.encodeCard(card) - for i, card in enumerate(hcs[:7]): + for i, card in enumerate(hcs[:20]): self.handsplayers[player[1]]['card%s' % (i+1)] = Card.encodeCard(card) self.handsplayers[player[1]]['startCards'] = Card.calcStartCards(hand, player[1]) diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index c6775e92..d26c60eb 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -172,10 +172,7 @@ class Fulltilt(HandHistoryConverter): self.re_BringIn = re.compile(r"^%(PLAYERS)s brings in for [%(LS)s]?(?P[%(NUM)s]+)" % self.substitutions, re.MULTILINE) self.re_PostBoth = re.compile(r"^%(PLAYERS)s posts small \& big blinds \[[%(LS)s]? (?P[%(NUM)s]+)" % self.substitutions, re.MULTILINE) self.re_HeroCards = re.compile(r"^Dealt to %s(?: \[(?P.+?)\])?( \[(?P.+?)\])" % player_re, re.MULTILINE) - self.re_Action = re.compile(r""" - ^%(PLAYERS)s(?P bets| checks| raises to| completes it to| calls| folds| discards| stands pat) - ( [%(LS)s]?(?P[%(NUM)s]+))? - (\scards?(\s\[(?P.+?)\])?)?""" % self.substitutions, re.MULTILINE) + self.re_Action = re.compile(r"^%(PLAYERS)s(?P bets| checks| raises to| completes it to| calls| folds| discards| stands pat)( [%(LS)s]?(?P[%(NUM)s]+))?(\son|\scards?)?(\s\[(?P.+?)\])?" % self.substitutions, re.MULTILINE) self.re_ShowdownAction = re.compile(r"^%s shows \[(?P.*)\]" % player_re, re.MULTILINE) self.re_CollectPot = re.compile(r"^Seat (?P[0-9]+): %(PLAYERS)s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \([%(LS)s]?(?P[%(NUM)s]+)\)(, mucked| with.*)?" % self.substitutions, re.MULTILINE) self.re_SitsOut = re.compile(r"^%s sits out" % player_re, re.MULTILINE) @@ -487,9 +484,9 @@ class Fulltilt(HandHistoryConverter): elif action.group('ATYPE') == ' checks': hand.addCheck( street, action.group('PNAME')) elif action.group('ATYPE') == ' discards': - hand.addDiscard(street, action.group('PNAME'), action.group('BET'), action.group('DISCARDED')) + hand.addDiscard(street, action.group('PNAME'), action.group('BET'), action.group('CARDS')) elif action.group('ATYPE') == ' stands pat': - hand.addStandsPat( street, action.group('PNAME')) + hand.addStandsPat( street, action.group('PNAME'), action.group('CARDS')) else: print _("FullTilt: DEBUG: unimplemented readAction: '%s' '%s'") %(action.group('PNAME'),action.group('ATYPE'),) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index cb3bb405..7f89c050 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -661,10 +661,13 @@ Add a raise on [street] by [player] to [amountTo] self.pot.addMoney(player, amount) - def addStandsPat(self, street, player): + def addStandsPat(self, street, player, cards): self.checkPlayerExists(player) act = (player, 'stands pat') self.actions[street].append(act) + if cards: + cards = cards.split(' ') + self.addHoleCards(street, player, open=[], closed=cards) def addFold(self, street, player): @@ -1224,7 +1227,14 @@ class DrawHand(Hand): def join_holecards(self, player, asList=False): """With asList = True it returns the set cards for a player including down cards if they aren't know""" # FIXME: This should actually return - holecards = [u'0x', u'0x', u'0x', u'0x', u'0x'] + holecards = [u'0x']*20 + + for i, street in enumerate(self.holeStreets): + if player in self.holecards[street].keys(): + allhole = self.holecards[street][player][0] + self.holecards[street][player][1] + for c in range(len(allhole)): + idx = c + (i*5) + holecards[idx] = allhole[c] if asList == False: return " ".join(holecards) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index f1364ab1..d6abca84 100644 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -145,7 +145,8 @@ class PokerStars(HandHistoryConverter): (\s(%(CUR)s)?(?P[.\d]+))?(\sto\s%(CUR)s(?P[.\d]+))? # the number discarded goes in \s*(and\sis\sall.in)? (and\shas\sreached\sthe\s[%(CUR)s\d\.]+\scap)? - (\scards?(\s\[(?P.+?)\])?)?\s*$""" + (\son|\scards?)? + (\s\[(?P.+?)\])?\s*$""" % short_subst, re.MULTILINE|re.VERBOSE) re_ShowdownAction = re.compile(r"^%s: shows \[(?P.*)\]" % short_subst['PLYR'], re.MULTILINE) re_sitsOut = re.compile("^%s sits out" % short_subst['PLYR'], re.MULTILINE) @@ -432,9 +433,9 @@ class PokerStars(HandHistoryConverter): elif action.group('ATYPE') == ' checks': hand.addCheck( street, action.group('PNAME')) elif action.group('ATYPE') == ' discards': - hand.addDiscard(street, action.group('PNAME'), action.group('BET'), action.group('DISCARDED')) + hand.addDiscard(street, action.group('PNAME'), action.group('BET'), action.group('CARDS')) elif action.group('ATYPE') == ' stands pat': - hand.addStandsPat( street, action.group('PNAME')) + hand.addStandsPat( street, action.group('PNAME'), action.group('CARDS')) else: print (_("DEBUG: ") + _("Unimplemented readAction: '%s' '%s'") % (action.group('PNAME'),action.group('ATYPE'))) diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index e389feea..e5b4c3d8 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -633,6 +633,19 @@ class Sql: card5 smallint, card6 smallint, card7 smallint, + card8 smallint, /* cards 8-20 for draw hands */ + card9 smallint, + card10 smallint, + card11 smallint, + card12 smallint, + card13 smallint, + card14 smallint, + card15 smallint, + card16 smallint, + card17 smallint, + card18 smallint, + card19 smallint, + card20 smallint, startCards smallint, ante INT, @@ -760,6 +773,19 @@ class Sql: card5 smallint, card6 smallint, card7 smallint, + card8 smallint, /* cards 8-20 for draw hands */ + card9 smallint, + card10 smallint, + card11 smallint, + card12 smallint, + card13 smallint, + card14 smallint, + card15 smallint, + card16 smallint, + card17 smallint, + card18 smallint, + card19 smallint, + card20 smallint, startCards smallint, ante INT, @@ -886,6 +912,19 @@ class Sql: card5 INT, card6 INT, card7 INT, + card8 INT, /* cards 8-20 for draw hands */ + card9 INT, + card10 INT, + card11 INT, + card12 INT, + card13 INT, + card14 INT, + card15 INT, + card16 INT, + card17 INT, + card18 INT, + card19 INT, + card20 INT, startCards INT, ante INT, @@ -4799,6 +4838,19 @@ class Sql: card5, card6, card7, + card8, + card9, + card10, + card11, + card12, + card13, + card14, + card15, + card16, + card17, + card18, + card19, + card20, winnings, rake, totalProfit, @@ -4913,7 +4965,10 @@ class Sql: %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, - %s, %s, %s, %s + %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, + %s, %s )""" self.query['store_hands_actions'] = """insert into HandsActions (