From 1d0177f6d47a93666f642334aa9438960c2475b8 Mon Sep 17 00:00:00 2001 From: Worros Date: Tue, 13 Oct 2009 14:04:19 +0800 Subject: [PATCH 1/8] [NEWIMPORT] Finish up Hand import Decided to leave streetXRaisesN alone for the moment --- pyfpdb/Database.py | 25 +++++++++++++------------ pyfpdb/DerivedStats.py | 28 +++++++++------------------- pyfpdb/fpdb.py | 0 3 files changed, 22 insertions(+), 31 deletions(-) mode change 100644 => 100755 pyfpdb/fpdb.py diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index e05a38b8..60ce39aa 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1391,6 +1391,7 @@ class Database: importtime, seats, maxseats, + texture, playersVpi, boardcard1, boardcard2, @@ -1402,6 +1403,11 @@ class Database: playersAtStreet3, playersAtStreet4, playersAtShowdown, + street0Raises, + street1Raises, + street2Raises, + street3Raises, + street4Raises, street1Pot, street2Pot, street3Pot, @@ -1411,13 +1417,7 @@ class Database: VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, - %s, %s, %s)""" -#--- texture, -#-- street0Raises, -#-- street1Raises, -#-- street2Raises, -#-- street3Raises, -#-- street4Raises, + %s, %s, %s, %s, %s, %s, %s, %s, %s)""" q = q.replace('%s', self.sql.query['placeholder']) print "DEBUG: p: %s" %p @@ -1430,6 +1430,7 @@ class Database: datetime.today(), #importtime p['seats'], p['maxSeats'], + p['texture'], p['playersVpi'], p['boardcard1'], p['boardcard2'], @@ -1441,11 +1442,11 @@ class Database: p['playersAtStreet3'], p['playersAtStreet4'], p['playersAtShowdown'], -# hudCache['street0Raises'], -# hudCache['street1Raises'], -# hudCache['street2Raises'], -# hudCache['street3Raises'], -# hudCache['street4Raises'], + p['street0Raises'], + p['street1Raises'], + p['street2Raises'], + p['street3Raises'], + p['street4Raises'], p['street1Pot'], p['street2Pot'], p['street3Pot'], diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index 7d428be9..fa85df14 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -47,6 +47,7 @@ class DerivedStats(): self.hands['importTime'] = None self.hands['seats'] = self.countPlayers(hand) self.hands['maxSeats'] = hand.maxseats + self.hands['texture'] = None # No calculation done for this yet. # This (i think...) is correct for both stud and flop games, as hand.board['street'] disappears, and # those values remain default in stud. @@ -66,27 +67,11 @@ class DerivedStats(): self.hands['street4Pot'], self.hands['showdownPot']) = hand.getStreetTotals() - self.vpip(hand) # Gives playersVpi (num of players vpip) self.playersAtStreetX(hand) # Gives playersAtStreet1..4 and Showdown - # texture smallint, - - # street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */ - # Needs to be recorded - # street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */ - # Needs to be recorded - # street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */ - # Needs to be recorded - # street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */ - # Needs to be recorded - # street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */ - # Needs to be recorded - - # comment TEXT, - # commentTs DATETIME - - + # comment TEXT, + # commentTs DATETIME def assembleHandsPlayers(self, hand): self.vpip(self.hand) @@ -145,7 +130,12 @@ class DerivedStats(): # [ (player, action, ....), (player2, action, ...) ] # No idea what this value is actually supposed to be # In theory its "num small bets paid to see flop/street4, including blind" which makes sense for limit. Not so useful for nl - pass + # Leaving empty for the moment, + self.hands['street0Raises'] = 0 # /* num small bets paid to see flop/street4, including blind */ + self.hands['street1Raises'] = 0 # /* num small bets paid to see turn/street5 */ + self.hands['street2Raises'] = 0 # /* num big bets paid to see river/street6 */ + self.hands['street3Raises'] = 0 # /* num big bets paid to see sd/street7 */ + self.hands['street4Raises'] = 0 # /* num big bets paid to see showdown */ def aggr(self, hand, i): aggrers = set() diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py old mode 100644 new mode 100755 From 00a85936316259b9cde846aa40fc5a0ac2ffbe5f Mon Sep 17 00:00:00 2001 From: Worros Date: Tue, 13 Oct 2009 14:12:25 +0800 Subject: [PATCH 2/8] Fix table re-create bug in fillDefaultData --- pyfpdb/Database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 60ce39aa..b283a716 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1152,7 +1152,7 @@ class Database: elif self.backend == self.MYSQL_INNODB: c.execute("""insert into TourneyTypes(id, siteId, buyin, fee, maxSeats, knockout ,rebuyOrAddon, speed, headsUp, shootout, matrix) - values (1, 0, 0, 0, False, False, null, False, False, False);""") + values (DEFAULT, 1, 0, 0, 0, False, False, null, False, False, False);""") #end def fillDefaultData From f4887235a071c66c1f5f1ccc5d322dfe72afd15d Mon Sep 17 00:00:00 2001 From: Worros Date: Tue, 13 Oct 2009 15:58:05 +0800 Subject: [PATCH 3/8] [NEWIMPORT] Fix Hand import so it runs Also comment out some debug --- pyfpdb/DerivedStats.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index fa85df14..0140f49f 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -68,7 +68,10 @@ class DerivedStats(): self.hands['showdownPot']) = hand.getStreetTotals() self.vpip(hand) # Gives playersVpi (num of players vpip) + #print "DEBUG: vpip: %s" %(self.hands['playersVpi']) self.playersAtStreetX(hand) # Gives playersAtStreet1..4 and Showdown + #print "DEBUG: playersAtStreet 1:'%s' 2:'%s' 3:'%s' 4:'%s'" %(self.hands['playersAtStreet1'],self.hands['playersAtStreet2'],self.hands['playersAtStreet3'],self.hands['playersAtStreet4']) + self.streetXRaises(hand) # Empty function currently # comment TEXT, # commentTs DATETIME @@ -84,11 +87,12 @@ class DerivedStats(): if act[1] in ('calls','bets', 'raises'): vpipers.add(act[0]) - for player in hand.players: - if player[1] in vpipers: - self.handsplayers[player[1]]['vpip'] = True - else: - self.handsplayers[player[1]]['vpip'] = False + #for player in hand.players: + # print "DEBUG: '%s' '%s' '%s'" %(player, player[1], vpipers) + # if player[1] in vpipers: + # self.handsplayers[player[1]]['vpip'] = True + # else: + # self.handsplayers[player[1]]['vpip'] = False self.hands['playersVpi'] = len(vpipers) def playersAtStreetX(self, hand): @@ -105,7 +109,7 @@ class DerivedStats(): for street in hand.actionStreets: actors = {} - for act in a[street]: + for act in hand.actions[street]: actors[act[0]] = 1 #print "len(actors.keys(%s)): %s" % ( street, len(actors.keys())) if hand.gametype['base'] in ("hold"): From 4d04a4b1dbe54b14ed28148916ca49d932f4ab21 Mon Sep 17 00:00:00 2001 From: Worros Date: Tue, 13 Oct 2009 17:30:49 +0800 Subject: [PATCH 4/8] [NEWIMPORT] Take a copy of generateHudCache for DerivedStats Commented out, should give a good basis for generating the stats from Hand class --- pyfpdb/DerivedStats.py | 690 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 690 insertions(+) diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index 0140f49f..315ae707 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -81,6 +81,696 @@ class DerivedStats(): for i, street in enumerate(hand.actionStreets[1:]): self.aggr(self.hand, i) + def assembleHudCache(self, hand): +# # def generateHudCacheData(player_ids, base, category, action_types, allIns, actionTypeByNo +# # ,winnings, totalWinnings, positions, actionTypes, actionAmounts, antes): +# #"""calculates data for the HUD during import. IMPORTANT: if you change this method make +# # sure to also change the following storage method and table_viewer.prepare_data if necessary +# #""" +# #print "generateHudCacheData, len(player_ids)=", len(player_ids) +# #setup subarrays of the result dictionary. +# street0VPI=[] +# street0Aggr=[] +# street0_3BChance=[] +# street0_3BDone=[] +# street1Seen=[] +# street2Seen=[] +# street3Seen=[] +# street4Seen=[] +# sawShowdown=[] +# street1Aggr=[] +# street2Aggr=[] +# street3Aggr=[] +# street4Aggr=[] +# otherRaisedStreet1=[] +# otherRaisedStreet2=[] +# otherRaisedStreet3=[] +# otherRaisedStreet4=[] +# foldToOtherRaisedStreet1=[] +# foldToOtherRaisedStreet2=[] +# foldToOtherRaisedStreet3=[] +# foldToOtherRaisedStreet4=[] +# wonWhenSeenStreet1=[] +# +# wonAtSD=[] +# stealAttemptChance=[] +# stealAttempted=[] +# hudDataPositions=[] +# +# street0Calls=[] +# street1Calls=[] +# street2Calls=[] +# street3Calls=[] +# street4Calls=[] +# street0Bets=[] +# street1Bets=[] +# street2Bets=[] +# street3Bets=[] +# street4Bets=[] +# #street0Raises=[] +# #street1Raises=[] +# #street2Raises=[] +# #street3Raises=[] +# #street4Raises=[] +# +# # Summary figures for hand table: +# result={} +# result['playersVpi']=0 +# result['playersAtStreet1']=0 +# result['playersAtStreet2']=0 +# result['playersAtStreet3']=0 +# result['playersAtStreet4']=0 +# result['playersAtShowdown']=0 +# result['street0Raises']=0 +# result['street1Raises']=0 +# result['street2Raises']=0 +# result['street3Raises']=0 +# result['street4Raises']=0 +# result['street1Pot']=0 +# result['street2Pot']=0 +# result['street3Pot']=0 +# result['street4Pot']=0 +# result['showdownPot']=0 +# +# firstPfRaiseByNo=-1 +# firstPfRaiserId=-1 +# firstPfRaiserNo=-1 +# firstPfCallByNo=-1 +# firstPfCallerId=-1 +# +# for i, action in enumerate(actionTypeByNo[0]): +# if action[1] == "bet": +# firstPfRaiseByNo = i +# firstPfRaiserId = action[0] +# for j, pid in enumerate(player_ids): +# if pid == firstPfRaiserId: +# firstPfRaiserNo = j +# break +# break +# for i, action in enumerate(actionTypeByNo[0]): +# if action[1] == "call": +# firstPfCallByNo = i +# firstPfCallerId = action[0] +# break +# firstPlayId = firstPfCallerId +# if firstPfRaiseByNo <> -1: +# if firstPfRaiseByNo < firstPfCallByNo or firstPfCallByNo == -1: +# firstPlayId = firstPfRaiserId +# +# +# cutoffId=-1 +# buttonId=-1 +# sbId=-1 +# bbId=-1 +# if base=="hold": +# for player, pos in enumerate(positions): +# if pos == 1: +# cutoffId = player_ids[player] +# if pos == 0: +# buttonId = player_ids[player] +# if pos == 'S': +# sbId = player_ids[player] +# if pos == 'B': +# bbId = player_ids[player] +# +# someoneStole=False +# +# #run a loop for each player preparing the actual values that will be commited to SQL +# for player in xrange(len(player_ids)): +# #set default values +# myStreet0VPI=False +# myStreet0Aggr=False +# myStreet0_3BChance=False +# myStreet0_3BDone=False +# myStreet1Seen=False +# myStreet2Seen=False +# myStreet3Seen=False +# myStreet4Seen=False +# mySawShowdown=False +# myStreet1Aggr=False +# myStreet2Aggr=False +# myStreet3Aggr=False +# myStreet4Aggr=False +# myOtherRaisedStreet1=False +# myOtherRaisedStreet2=False +# myOtherRaisedStreet3=False +# myOtherRaisedStreet4=False +# myFoldToOtherRaisedStreet1=False +# myFoldToOtherRaisedStreet2=False +# myFoldToOtherRaisedStreet3=False +# myFoldToOtherRaisedStreet4=False +# myWonWhenSeenStreet1=0.0 +# myWonAtSD=0.0 +# myStealAttemptChance=False +# myStealAttempted=False +# myStreet0Calls=0 +# myStreet1Calls=0 +# myStreet2Calls=0 +# myStreet3Calls=0 +# myStreet4Calls=0 +# myStreet0Bets=0 +# myStreet1Bets=0 +# myStreet2Bets=0 +# myStreet3Bets=0 +# myStreet4Bets=0 +# #myStreet0Raises=0 +# #myStreet1Raises=0 +# #myStreet2Raises=0 +# #myStreet3Raises=0 +# #myStreet4Raises=0 +# +# #calculate VPIP and PFR +# street=0 +# heroPfRaiseCount=0 +# for currentAction in action_types[street][player]: # finally individual actions +# if currentAction == "bet": +# myStreet0Aggr = True +# if currentAction == "bet" or currentAction == "call": +# myStreet0VPI = True +# +# if myStreet0VPI: +# result['playersVpi'] += 1 +# myStreet0Calls = action_types[street][player].count('call') +# myStreet0Bets = action_types[street][player].count('bet') +# # street0Raises = action_types[street][player].count('raise') bet count includes raises for now +# result['street0Raises'] += myStreet0Bets +# +# #PF3BChance and PF3B +# pfFold=-1 +# pfRaise=-1 +# if firstPfRaiseByNo != -1: +# for i, actionType in enumerate(actionTypeByNo[0]): +# if actionType[0] == player_ids[player]: +# if actionType[1] == "bet" and pfRaise == -1 and i > firstPfRaiseByNo: +# pfRaise = i +# if actionType[1] == "fold" and pfFold == -1: +# pfFold = i +# if pfFold == -1 or pfFold > firstPfRaiseByNo: +# myStreet0_3BChance = True +# if pfRaise > firstPfRaiseByNo: +# myStreet0_3BDone = True +# +# #steal calculations +# if base=="hold": +# if len(player_ids)>=3: # no point otherwise # was 5, use 3 to match pokertracker definition +# if positions[player]==1: +# if firstPfRaiserId==player_ids[player] \ +# and (firstPfCallByNo==-1 or firstPfCallByNo>firstPfRaiseByNo): +# myStealAttempted=True +# myStealAttemptChance=True +# if firstPlayId==cutoffId or firstPlayId==buttonId or firstPlayId==sbId or firstPlayId==bbId or firstPlayId==-1: +# myStealAttemptChance=True +# if positions[player]==0: +# if firstPfRaiserId==player_ids[player] \ +# and (firstPfCallByNo==-1 or firstPfCallByNo>firstPfRaiseByNo): +# myStealAttempted=True +# myStealAttemptChance=True +# if firstPlayId==buttonId or firstPlayId==sbId or firstPlayId==bbId or firstPlayId==-1: +# myStealAttemptChance=True +# if positions[player]=='S': +# if firstPfRaiserId==player_ids[player] \ +# and (firstPfCallByNo==-1 or firstPfCallByNo>firstPfRaiseByNo): +# myStealAttempted=True +# myStealAttemptChance=True +# if firstPlayId==sbId or firstPlayId==bbId or firstPlayId==-1: +# myStealAttemptChance=True +# if positions[player]=='B': +# pass +# +# if myStealAttempted: +# someoneStole=True +# +# +# #calculate saw* values +# isAllIn = False +# if any(i for i in allIns[0][player]): +# isAllIn = True +# if (len(action_types[1][player])>0 or isAllIn): +# myStreet1Seen = True +# +# if any(i for i in allIns[1][player]): +# isAllIn = True +# if (len(action_types[2][player])>0 or isAllIn): +# myStreet2Seen = True +# +# if any(i for i in allIns[2][player]): +# isAllIn = True +# if (len(action_types[3][player])>0 or isAllIn): +# myStreet3Seen = True +# +# #print "base:", base +# if base=="hold": +# mySawShowdown = True +# if any(actiontype == "fold" for actiontype in action_types[3][player]): +# mySawShowdown = False +# else: +# #print "in else" +# if any(i for i in allIns[3][player]): +# isAllIn = True +# if (len(action_types[4][player])>0 or isAllIn): +# #print "in if" +# myStreet4Seen = True +# +# mySawShowdown = True +# if any(actiontype == "fold" for actiontype in action_types[4][player]): +# mySawShowdown = False +# +# if myStreet1Seen: +# result['playersAtStreet1'] += 1 +# if myStreet2Seen: +# result['playersAtStreet2'] += 1 +# if myStreet3Seen: +# result['playersAtStreet3'] += 1 +# if myStreet4Seen: +# result['playersAtStreet4'] += 1 +# if mySawShowdown: +# result['playersAtShowdown'] += 1 +# +# #flop stuff +# street=1 +# if myStreet1Seen: +# if any(actiontype == "bet" for actiontype in action_types[street][player]): +# myStreet1Aggr = True +# +# myStreet1Calls = action_types[street][player].count('call') +# myStreet1Bets = action_types[street][player].count('bet') +# # street1Raises = action_types[street][player].count('raise') bet count includes raises for now +# result['street1Raises'] += myStreet1Bets +# +# for otherPlayer in xrange(len(player_ids)): +# if player==otherPlayer: +# pass +# else: +# for countOther in xrange(len(action_types[street][otherPlayer])): +# if action_types[street][otherPlayer][countOther]=="bet": +# myOtherRaisedStreet1=True +# for countOtherFold in xrange(len(action_types[street][player])): +# if action_types[street][player][countOtherFold]=="fold": +# myFoldToOtherRaisedStreet1=True +# +# #turn stuff - copy of flop with different vars +# street=2 +# if myStreet2Seen: +# if any(actiontype == "bet" for actiontype in action_types[street][player]): +# myStreet2Aggr = True +# +# myStreet2Calls = action_types[street][player].count('call') +# myStreet2Bets = action_types[street][player].count('bet') +# # street2Raises = action_types[street][player].count('raise') bet count includes raises for now +# result['street2Raises'] += myStreet2Bets +# +# for otherPlayer in xrange(len(player_ids)): +# if player==otherPlayer: +# pass +# else: +# for countOther in xrange(len(action_types[street][otherPlayer])): +# if action_types[street][otherPlayer][countOther]=="bet": +# myOtherRaisedStreet2=True +# for countOtherFold in xrange(len(action_types[street][player])): +# if action_types[street][player][countOtherFold]=="fold": +# myFoldToOtherRaisedStreet2=True +# +# #river stuff - copy of flop with different vars +# street=3 +# if myStreet3Seen: +# if any(actiontype == "bet" for actiontype in action_types[street][player]): +# myStreet3Aggr = True +# +# myStreet3Calls = action_types[street][player].count('call') +# myStreet3Bets = action_types[street][player].count('bet') +# # street3Raises = action_types[street][player].count('raise') bet count includes raises for now +# result['street3Raises'] += myStreet3Bets +# +# for otherPlayer in xrange(len(player_ids)): +# if player==otherPlayer: +# pass +# else: +# for countOther in xrange(len(action_types[street][otherPlayer])): +# if action_types[street][otherPlayer][countOther]=="bet": +# myOtherRaisedStreet3=True +# for countOtherFold in xrange(len(action_types[street][player])): +# if action_types[street][player][countOtherFold]=="fold": +# myFoldToOtherRaisedStreet3=True +# +# #stud river stuff - copy of flop with different vars +# street=4 +# if myStreet4Seen: +# if any(actiontype == "bet" for actiontype in action_types[street][player]): +# myStreet4Aggr=True +# +# myStreet4Calls = action_types[street][player].count('call') +# myStreet4Bets = action_types[street][player].count('bet') +# # street4Raises = action_types[street][player].count('raise') bet count includes raises for now +# result['street4Raises'] += myStreet4Bets +# +# for otherPlayer in xrange(len(player_ids)): +# if player==otherPlayer: +# pass +# else: +# for countOther in xrange(len(action_types[street][otherPlayer])): +# if action_types[street][otherPlayer][countOther]=="bet": +# myOtherRaisedStreet4=True +# for countOtherFold in xrange(len(action_types[street][player])): +# if action_types[street][player][countOtherFold]=="fold": +# myFoldToOtherRaisedStreet4=True +# +# if winnings[player] != 0: +# if myStreet1Seen: +# myWonWhenSeenStreet1 = winnings[player] / float(totalWinnings) +# if mySawShowdown: +# myWonAtSD=myWonWhenSeenStreet1 +# +# #add each value to the appropriate array +# street0VPI.append(myStreet0VPI) +# street0Aggr.append(myStreet0Aggr) +# street0_3BChance.append(myStreet0_3BChance) +# street0_3BDone.append(myStreet0_3BDone) +# street1Seen.append(myStreet1Seen) +# street2Seen.append(myStreet2Seen) +# street3Seen.append(myStreet3Seen) +# street4Seen.append(myStreet4Seen) +# sawShowdown.append(mySawShowdown) +# street1Aggr.append(myStreet1Aggr) +# street2Aggr.append(myStreet2Aggr) +# street3Aggr.append(myStreet3Aggr) +# street4Aggr.append(myStreet4Aggr) +# otherRaisedStreet1.append(myOtherRaisedStreet1) +# otherRaisedStreet2.append(myOtherRaisedStreet2) +# otherRaisedStreet3.append(myOtherRaisedStreet3) +# otherRaisedStreet4.append(myOtherRaisedStreet4) +# foldToOtherRaisedStreet1.append(myFoldToOtherRaisedStreet1) +# foldToOtherRaisedStreet2.append(myFoldToOtherRaisedStreet2) +# foldToOtherRaisedStreet3.append(myFoldToOtherRaisedStreet3) +# foldToOtherRaisedStreet4.append(myFoldToOtherRaisedStreet4) +# wonWhenSeenStreet1.append(myWonWhenSeenStreet1) +# wonAtSD.append(myWonAtSD) +# stealAttemptChance.append(myStealAttemptChance) +# stealAttempted.append(myStealAttempted) +# if base=="hold": +# pos=positions[player] +# if pos=='B': +# hudDataPositions.append('B') +# elif pos=='S': +# hudDataPositions.append('S') +# elif pos==0: +# hudDataPositions.append('D') +# elif pos==1: +# hudDataPositions.append('C') +# elif pos>=2 and pos<=4: +# hudDataPositions.append('M') +# elif pos>=5 and pos<=8: +# hudDataPositions.append('E') +# ### RHH Added this elif to handle being a dead hand before the BB (pos==9) +# elif pos==9: +# hudDataPositions.append('X') +# else: +# raise FpdbError("invalid position") +# elif base=="stud": +# #todo: stud positions and steals +# pass +# +# street0Calls.append(myStreet0Calls) +# street1Calls.append(myStreet1Calls) +# street2Calls.append(myStreet2Calls) +# street3Calls.append(myStreet3Calls) +# street4Calls.append(myStreet4Calls) +# street0Bets.append(myStreet0Bets) +# street1Bets.append(myStreet1Bets) +# street2Bets.append(myStreet2Bets) +# street3Bets.append(myStreet3Bets) +# street4Bets.append(myStreet4Bets) +# #street0Raises.append(myStreet0Raises) +# #street1Raises.append(myStreet1Raises) +# #street2Raises.append(myStreet2Raises) +# #street3Raises.append(myStreet3Raises) +# #street4Raises.append(myStreet4Raises) +# +# #add each array to the to-be-returned dictionary +# result['street0VPI']=street0VPI +# result['street0Aggr']=street0Aggr +# result['street0_3BChance']=street0_3BChance +# result['street0_3BDone']=street0_3BDone +# result['street1Seen']=street1Seen +# result['street2Seen']=street2Seen +# result['street3Seen']=street3Seen +# result['street4Seen']=street4Seen +# result['sawShowdown']=sawShowdown +# +# result['street1Aggr']=street1Aggr +# result['otherRaisedStreet1']=otherRaisedStreet1 +# result['foldToOtherRaisedStreet1']=foldToOtherRaisedStreet1 +# result['street2Aggr']=street2Aggr +# result['otherRaisedStreet2']=otherRaisedStreet2 +# result['foldToOtherRaisedStreet2']=foldToOtherRaisedStreet2 +# result['street3Aggr']=street3Aggr +# result['otherRaisedStreet3']=otherRaisedStreet3 +# result['foldToOtherRaisedStreet3']=foldToOtherRaisedStreet3 +# result['street4Aggr']=street4Aggr +# result['otherRaisedStreet4']=otherRaisedStreet4 +# result['foldToOtherRaisedStreet4']=foldToOtherRaisedStreet4 +# result['wonWhenSeenStreet1']=wonWhenSeenStreet1 +# result['wonAtSD']=wonAtSD +# result['stealAttemptChance']=stealAttemptChance +# result['stealAttempted']=stealAttempted +# result['street0Calls']=street0Calls +# result['street1Calls']=street1Calls +# result['street2Calls']=street2Calls +# result['street3Calls']=street3Calls +# result['street4Calls']=street4Calls +# result['street0Bets']=street0Bets +# result['street1Bets']=street1Bets +# result['street2Bets']=street2Bets +# result['street3Bets']=street3Bets +# result['street4Bets']=street4Bets +# #result['street0Raises']=street0Raises +# #result['street1Raises']=street1Raises +# #result['street2Raises']=street2Raises +# #result['street3Raises']=street3Raises +# #result['street4Raises']=street4Raises +# +# #now the various steal values +# foldBbToStealChance=[] +# foldedBbToSteal=[] +# foldSbToStealChance=[] +# foldedSbToSteal=[] +# for player in xrange(len(player_ids)): +# myFoldBbToStealChance=False +# myFoldedBbToSteal=False +# myFoldSbToStealChance=False +# myFoldedSbToSteal=False +# +# if base=="hold": +# if someoneStole and (positions[player]=='B' or positions[player]=='S') and firstPfRaiserId!=player_ids[player]: +# street=0 +# for count in xrange(len(action_types[street][player])):#individual actions +# if positions[player]=='B': +# myFoldBbToStealChance=True +# if action_types[street][player][count]=="fold": +# myFoldedBbToSteal=True +# if positions[player]=='S': +# myFoldSbToStealChance=True +# if action_types[street][player][count]=="fold": +# myFoldedSbToSteal=True +# +# +# foldBbToStealChance.append(myFoldBbToStealChance) +# foldedBbToSteal.append(myFoldedBbToSteal) +# foldSbToStealChance.append(myFoldSbToStealChance) +# foldedSbToSteal.append(myFoldedSbToSteal) +# result['foldBbToStealChance']=foldBbToStealChance +# result['foldedBbToSteal']=foldedBbToSteal +# result['foldSbToStealChance']=foldSbToStealChance +# result['foldedSbToSteal']=foldedSbToSteal +# +# #now CB +# street1CBChance=[] +# street1CBDone=[] +# didStreet1CB=[] +# for player in xrange(len(player_ids)): +# myStreet1CBChance=False +# myStreet1CBDone=False +# +# if street0VPI[player]: +# myStreet1CBChance=True +# if street1Aggr[player]: +# myStreet1CBDone=True +# didStreet1CB.append(player_ids[player]) +# +# street1CBChance.append(myStreet1CBChance) +# street1CBDone.append(myStreet1CBDone) +# result['street1CBChance']=street1CBChance +# result['street1CBDone']=street1CBDone +# +# #now 2B +# street2CBChance=[] +# street2CBDone=[] +# didStreet2CB=[] +# for player in xrange(len(player_ids)): +# myStreet2CBChance=False +# myStreet2CBDone=False +# +# if street1CBDone[player]: +# myStreet2CBChance=True +# if street2Aggr[player]: +# myStreet2CBDone=True +# didStreet2CB.append(player_ids[player]) +# +# street2CBChance.append(myStreet2CBChance) +# street2CBDone.append(myStreet2CBDone) +# result['street2CBChance']=street2CBChance +# result['street2CBDone']=street2CBDone +# +# #now 3B +# street3CBChance=[] +# street3CBDone=[] +# didStreet3CB=[] +# for player in xrange(len(player_ids)): +# myStreet3CBChance=False +# myStreet3CBDone=False +# +# if street2CBDone[player]: +# myStreet3CBChance=True +# if street3Aggr[player]: +# myStreet3CBDone=True +# didStreet3CB.append(player_ids[player]) +# +# street3CBChance.append(myStreet3CBChance) +# street3CBDone.append(myStreet3CBDone) +# result['street3CBChance']=street3CBChance +# result['street3CBDone']=street3CBDone +# +# #and 4B +# street4CBChance=[] +# street4CBDone=[] +# didStreet4CB=[] +# for player in xrange(len(player_ids)): +# myStreet4CBChance=False +# myStreet4CBDone=False +# +# if street3CBDone[player]: +# myStreet4CBChance=True +# if street4Aggr[player]: +# myStreet4CBDone=True +# didStreet4CB.append(player_ids[player]) +# +# street4CBChance.append(myStreet4CBChance) +# street4CBDone.append(myStreet4CBDone) +# result['street4CBChance']=street4CBChance +# result['street4CBDone']=street4CBDone +# +# +# result['position']=hudDataPositions +# +# foldToStreet1CBChance=[] +# foldToStreet1CBDone=[] +# foldToStreet2CBChance=[] +# foldToStreet2CBDone=[] +# foldToStreet3CBChance=[] +# foldToStreet3CBDone=[] +# foldToStreet4CBChance=[] +# foldToStreet4CBDone=[] +# +# for player in xrange(len(player_ids)): +# myFoldToStreet1CBChance=False +# myFoldToStreet1CBDone=False +# foldToStreet1CBChance.append(myFoldToStreet1CBChance) +# foldToStreet1CBDone.append(myFoldToStreet1CBDone) +# +# myFoldToStreet2CBChance=False +# myFoldToStreet2CBDone=False +# foldToStreet2CBChance.append(myFoldToStreet2CBChance) +# foldToStreet2CBDone.append(myFoldToStreet2CBDone) +# +# myFoldToStreet3CBChance=False +# myFoldToStreet3CBDone=False +# foldToStreet3CBChance.append(myFoldToStreet3CBChance) +# foldToStreet3CBDone.append(myFoldToStreet3CBDone) +# +# myFoldToStreet4CBChance=False +# myFoldToStreet4CBDone=False +# foldToStreet4CBChance.append(myFoldToStreet4CBChance) +# foldToStreet4CBDone.append(myFoldToStreet4CBDone) +# +# if len(didStreet1CB)>=1: +# generateFoldToCB(1, player_ids, didStreet1CB, street1CBDone, foldToStreet1CBChance, foldToStreet1CBDone, actionTypeByNo) +# +# if len(didStreet2CB)>=1: +# generateFoldToCB(2, player_ids, didStreet2CB, street2CBDone, foldToStreet2CBChance, foldToStreet2CBDone, actionTypeByNo) +# +# if len(didStreet3CB)>=1: +# generateFoldToCB(3, player_ids, didStreet3CB, street3CBDone, foldToStreet3CBChance, foldToStreet3CBDone, actionTypeByNo) +# +# if len(didStreet4CB)>=1: +# generateFoldToCB(4, player_ids, didStreet4CB, street4CBDone, foldToStreet4CBChance, foldToStreet4CBDone, actionTypeByNo) +# +# result['foldToStreet1CBChance']=foldToStreet1CBChance +# result['foldToStreet1CBDone']=foldToStreet1CBDone +# result['foldToStreet2CBChance']=foldToStreet2CBChance +# result['foldToStreet2CBDone']=foldToStreet2CBDone +# result['foldToStreet3CBChance']=foldToStreet3CBChance +# result['foldToStreet3CBDone']=foldToStreet3CBDone +# result['foldToStreet4CBChance']=foldToStreet4CBChance +# result['foldToStreet4CBDone']=foldToStreet4CBDone +# +# +# totalProfit=[] +# +# street1CheckCallRaiseChance=[] +# street1CheckCallRaiseDone=[] +# street2CheckCallRaiseChance=[] +# street2CheckCallRaiseDone=[] +# street3CheckCallRaiseChance=[] +# street3CheckCallRaiseDone=[] +# street4CheckCallRaiseChance=[] +# street4CheckCallRaiseDone=[] +# #print "b4 totprof calc, len(playerIds)=", len(player_ids) +# for pl in xrange(len(player_ids)): +# #print "pl=", pl +# myTotalProfit=winnings[pl] # still need to deduct other costs +# if antes: +# myTotalProfit=winnings[pl] - antes[pl] +# for i in xrange(len(actionTypes)): #iterate through streets +# #for j in xrange(len(actionTypes[i])): #iterate through names (using pl loop above) +# for k in xrange(len(actionTypes[i][pl])): #iterate through individual actions of that player on that street +# myTotalProfit -= actionAmounts[i][pl][k] +# +# myStreet1CheckCallRaiseChance=False +# myStreet1CheckCallRaiseDone=False +# myStreet2CheckCallRaiseChance=False +# myStreet2CheckCallRaiseDone=False +# myStreet3CheckCallRaiseChance=False +# myStreet3CheckCallRaiseDone=False +# myStreet4CheckCallRaiseChance=False +# myStreet4CheckCallRaiseDone=False +# +# #print "myTotalProfit=", myTotalProfit +# totalProfit.append(myTotalProfit) +# #print "totalProfit[]=", totalProfit +# +# street1CheckCallRaiseChance.append(myStreet1CheckCallRaiseChance) +# street1CheckCallRaiseDone.append(myStreet1CheckCallRaiseDone) +# street2CheckCallRaiseChance.append(myStreet2CheckCallRaiseChance) +# street2CheckCallRaiseDone.append(myStreet2CheckCallRaiseDone) +# street3CheckCallRaiseChance.append(myStreet3CheckCallRaiseChance) +# street3CheckCallRaiseDone.append(myStreet3CheckCallRaiseDone) +# street4CheckCallRaiseChance.append(myStreet4CheckCallRaiseChance) +# street4CheckCallRaiseDone.append(myStreet4CheckCallRaiseDone) +# +# result['totalProfit']=totalProfit +# #print "res[totalProfit]=", result['totalProfit'] +# +# result['street1CheckCallRaiseChance']=street1CheckCallRaiseChance +# result['street1CheckCallRaiseDone']=street1CheckCallRaiseDone +# result['street2CheckCallRaiseChance']=street2CheckCallRaiseChance +# result['street2CheckCallRaiseDone']=street2CheckCallRaiseDone +# result['street3CheckCallRaiseChance']=street3CheckCallRaiseChance +# result['street3CheckCallRaiseDone']=street3CheckCallRaiseDone +# result['street4CheckCallRaiseChance']=street4CheckCallRaiseChance +# result['street4CheckCallRaiseDone']=street4CheckCallRaiseDone +# return result +# #end def generateHudCacheData + pass + def vpip(self, hand): vpipers = set() for act in hand.actions[hand.actionStreets[1]]: From 843bd754f6e9e259a81050c0da4f2704eee78d0d Mon Sep 17 00:00:00 2001 From: Worros Date: Tue, 13 Oct 2009 17:42:02 +0800 Subject: [PATCH 5/8] [NEWIMPORT] Prep insert functions Cleaned up storeHandsPlayers and added storeHudCacheNew Haven't decided on the data structures to be passed in as yet so the functions only insert the bare minimum and have a list of commented out variables --- pyfpdb/Database.py | 402 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 306 insertions(+), 96 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index b283a716..f0146c7f 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1420,8 +1420,7 @@ class Database: %s, %s, %s, %s, %s, %s, %s, %s, %s)""" q = q.replace('%s', self.sql.query['placeholder']) - print "DEBUG: p: %s" %p - print "DEBUG: gtid: %s" % p['gameTypeId'] + self.cursor.execute(q, ( p['tableName'], p['gameTypeId'], @@ -1456,101 +1455,312 @@ class Database: #return getLastInsertId(backend, conn, cursor) # def storeHand - def storeHandsPlayers(self, p): - #def store_hands_players_holdem_omaha(self, backend, category, hands_id, player_ids, start_cashes - # ,positions, card_values, card_suits, winnings, rakes, seatNos, hudCache): - # result=[] - # - # # postgres (and others?) needs the booleans converted to ints before saving: - # # (or we could just save them as boolean ... but then we can't sum them so easily in sql ???) - # # NO - storing booleans for now so don't need this - # #hudCacheInt = {} - # #for k,v in hudCache.iteritems(): - # # if k in ('wonWhenSeenStreet1', 'wonAtSD', 'totalProfit'): - # # hudCacheInt[k] = v - # # else: - # # hudCacheInt[k] = map(lambda x: 1 if x else 0, v) - # - # try: - # inserts = [] - # for i in xrange(len(player_ids)): - # card1 = Card.cardFromValueSuit(card_values[i][0], card_suits[i][0]) - # card2 = Card.cardFromValueSuit(card_values[i][1], card_suits[i][1]) - # - # if (category=="holdem"): - # startCards = Card.twoStartCards(card_values[i][0], card_suits[i][0], card_values[i][1], card_suits[i][1]) - # card3 = None - # card4 = None - # elif (category=="omahahi" or category=="omahahilo"): - # startCards = Card.fourStartCards(card_values[i][0], card_suits[i][0], card_values[i][1], card_suits[i][1] - # ,card_values[i][2], card_suits[i][2], card_values[i][3], card_suits[i][3]) - # card3 = Card.cardFromValueSuit(card_values[i][2], card_suits[i][2]) - # card4 = Card.cardFromValueSuit(card_values[i][3], card_suits[i][3]) - # else: - # raise FpdbError("invalid category") - # - # inserts.append( ( - # hands_id, player_ids[i], start_cashes[i], positions[i], 1, # tourneytypeid - needed for hudcache - # card1, card2, card3, card4, startCards, - # winnings[i], rakes[i], seatNos[i], hudCache['totalProfit'][i], - # hudCache['street0VPI'][i], hudCache['street0Aggr'][i], - # hudCache['street0_3BChance'][i], hudCache['street0_3BDone'][i], - # hudCache['street1Seen'][i], hudCache['street2Seen'][i], hudCache['street3Seen'][i], - # hudCache['street4Seen'][i], hudCache['sawShowdown'][i], - # hudCache['street1Aggr'][i], hudCache['street2Aggr'][i], hudCache['street3Aggr'][i], hudCache['street4Aggr'][i], - # hudCache['otherRaisedStreet1'][i], hudCache['otherRaisedStreet2'][i], - # hudCache['otherRaisedStreet3'][i], hudCache['otherRaisedStreet4'][i], - # hudCache['foldToOtherRaisedStreet1'][i], hudCache['foldToOtherRaisedStreet2'][i], - # hudCache['foldToOtherRaisedStreet3'][i], hudCache['foldToOtherRaisedStreet4'][i], - # hudCache['wonWhenSeenStreet1'][i], hudCache['wonAtSD'][i], - # hudCache['stealAttemptChance'][i], hudCache['stealAttempted'][i], hudCache['foldBbToStealChance'][i], - # hudCache['foldedBbToSteal'][i], hudCache['foldSbToStealChance'][i], hudCache['foldedSbToSteal'][i], - # hudCache['street1CBChance'][i], hudCache['street1CBDone'][i], hudCache['street2CBChance'][i], hudCache['street2CBDone'][i], - # hudCache['street3CBChance'][i], hudCache['street3CBDone'][i], hudCache['street4CBChance'][i], hudCache['street4CBDone'][i], - # hudCache['foldToStreet1CBChance'][i], hudCache['foldToStreet1CBDone'][i], - # hudCache['foldToStreet2CBChance'][i], hudCache['foldToStreet2CBDone'][i], - # hudCache['foldToStreet3CBChance'][i], hudCache['foldToStreet3CBDone'][i], - # hudCache['foldToStreet4CBChance'][i], hudCache['foldToStreet4CBDone'][i], - # hudCache['street1CheckCallRaiseChance'][i], hudCache['street1CheckCallRaiseDone'][i], - # hudCache['street2CheckCallRaiseChance'][i], hudCache['street2CheckCallRaiseDone'][i], - # hudCache['street3CheckCallRaiseChance'][i], hudCache['street3CheckCallRaiseDone'][i], - # hudCache['street4CheckCallRaiseChance'][i], hudCache['street4CheckCallRaiseDone'][i], - # hudCache['street0Calls'][i], hudCache['street1Calls'][i], hudCache['street2Calls'][i], hudCache['street3Calls'][i], hudCache['street4Calls'][i], - # hudCache['street0Bets'][i], hudCache['street1Bets'][i], hudCache['street2Bets'][i], hudCache['street3Bets'][i], hudCache['street4Bets'][i] - # ) ) - # c = self.get_cursor() - # c.executemany (""" - # INSERT INTO HandsPlayers - # (handId, playerId, startCash, position, tourneyTypeId, - # card1, card2, card3, card4, startCards, winnings, rake, seatNo, totalProfit, - # street0VPI, street0Aggr, street0_3BChance, street0_3BDone, - # street1Seen, street2Seen, street3Seen, street4Seen, sawShowdown, - # street1Aggr, street2Aggr, street3Aggr, street4Aggr, - # otherRaisedStreet1, otherRaisedStreet2, otherRaisedStreet3, otherRaisedStreet4, - # foldToOtherRaisedStreet1, foldToOtherRaisedStreet2, foldToOtherRaisedStreet3, foldToOtherRaisedStreet4, - # wonWhenSeenStreet1, wonAtSD, - # stealAttemptChance, stealAttempted, foldBbToStealChance, foldedBbToSteal, foldSbToStealChance, foldedSbToSteal, - # street1CBChance, street1CBDone, street2CBChance, street2CBDone, - # street3CBChance, street3CBDone, street4CBChance, street4CBDone, - # foldToStreet1CBChance, foldToStreet1CBDone, foldToStreet2CBChance, foldToStreet2CBDone, - # foldToStreet3CBChance, foldToStreet3CBDone, foldToStreet4CBChance, foldToStreet4CBDone, - # street1CheckCallRaiseChance, street1CheckCallRaiseDone, street2CheckCallRaiseChance, street2CheckCallRaiseDone, - # street3CheckCallRaiseChance, street3CheckCallRaiseDone, street4CheckCallRaiseChance, street4CheckCallRaiseDone, - # street0Calls, street1Calls, street2Calls, street3Calls, street4Calls, - # street0Bets, street1Bets, street2Bets, street3Bets, street4Bets - # ) - # VALUES (%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, %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, %s, %s, %s, %s, %s)""".replace('%s', self.sql.query['placeholder']) - # ,inserts ) - # result.append( self.get_last_insert_id(c) ) # wrong? not used currently - # except: - # raise FpdbError( "store_hands_players_holdem_omaha error: " + str(sys.exc_value) ) - # - # return result + def storeHandsPlayers(self, hid, pid, p): + q = """INSERT INTO HandsPlayers ( + handId, + playerId + ) + VALUES ( + %s, %s + )""" - pass +# startCash, +# position, +# tourneyTypeId, +# card1, +# card2, +# card3, +# card4, +# startCards, +# winnings, +# rake, +# seatNo, +# totalProfit, +# street0VPI, +# street0Aggr, +# street0_3BChance, +# street0_3BDone, +# street1Seen, +# street2Seen, +# street3Seen, +# street4Seen, +# sawShowdown, +# street1Aggr, +# street2Aggr, +# street3Aggr, +# street4Aggr, +# otherRaisedStreet1, +# otherRaisedStreet2, +# otherRaisedStreet3, +# otherRaisedStreet4, +# foldToOtherRaisedStreet1, +# foldToOtherRaisedStreet2, +# foldToOtherRaisedStreet3, +# foldToOtherRaisedStreet4, +# wonWhenSeenStreet1, +# wonAtSD, +# stealAttemptChance, +# stealAttempted, +# foldBbToStealChance, +# foldedBbToSteal, +# foldSbToStealChance, +# foldedSbToSteal, +# street1CBChance, +# street1CBDone, +# street2CBChance, +# street2CBDone, +# street3CBChance, +# street3CBDone, +# street4CBChance, +# street4CBDone, +# foldToStreet1CBChance, +# foldToStreet1CBDone, +# foldToStreet2CBChance, +# foldToStreet2CBDone, +# foldToStreet3CBChance, +# foldToStreet3CBDone, +# foldToStreet4CBChance, +# foldToStreet4CBDone, +# street1CheckCallRaiseChance, +# street1CheckCallRaiseDone, +# street2CheckCallRaiseChance, +# street2CheckCallRaiseDone, +# street3CheckCallRaiseChance, +# street3CheckCallRaiseDone, +# street4CheckCallRaiseChance, +# street4CheckCallRaiseDone, +# street0Calls, +# street1Calls, +# street2Calls, +# street3Calls, +# street4Calls, +# street0Bets, +# street1Bets, +# street2Bets, +# street3Bets, +# street4Bets + + q = q.replace('%s', self.sql.query['placeholder']) + + self.cursor.execute(q, ( + hid, + pid + )) +# startCash, +# position, +# tourneyTypeId, +# card1, +# card2, +# card3, +# card4, +# startCards, +# winnings, +# rake, +# seatNo, +# totalProfit, +# street0VPI, +# street0Aggr, +# street0_3BChance, +# street0_3BDone, +# street1Seen, +# street2Seen, +# street3Seen, +# street4Seen, +# sawShowdown, +# street1Aggr, +# street2Aggr, +# street3Aggr, +# street4Aggr, +# otherRaisedStreet1, +# otherRaisedStreet2, +# otherRaisedStreet3, +# otherRaisedStreet4, +# foldToOtherRaisedStreet1, +# foldToOtherRaisedStreet2, +# foldToOtherRaisedStreet3, +# foldToOtherRaisedStreet4, +# wonWhenSeenStreet1, +# wonAtSD, +# stealAttemptChance, +# stealAttempted, +# foldBbToStealChance, +# foldedBbToSteal, +# foldSbToStealChance, +# foldedSbToSteal, +# street1CBChance, +# street1CBDone, +# street2CBChance, +# street2CBDone, +# street3CBChance, +# street3CBDone, +# street4CBChance, +# street4CBDone, +# foldToStreet1CBChance, +# foldToStreet1CBDone, +# foldToStreet2CBChance, +# foldToStreet2CBDone, +# foldToStreet3CBChance, +# foldToStreet3CBDone, +# foldToStreet4CBChance, +# foldToStreet4CBDone, +# street1CheckCallRaiseChance, +# street1CheckCallRaiseDone, +# street2CheckCallRaiseChance, +# street2CheckCallRaiseDone, +# street3CheckCallRaiseChance, +# street3CheckCallRaiseDone, +# street4CheckCallRaiseChance, +# street4CheckCallRaiseDone, +# street0Calls, +# street1Calls, +# street2Calls, +# street3Calls, +# street4Calls, +# street0Bets, +# street1Bets, +# street2Bets, +# street3Bets, +# street4Bets + + def storeHudCacheNew(self, gid, pid, hc): + q = """INSERT INTO HudCache ( + gametypeId, + playerId + ) + VALUES ( + %s, %s + )""" + +# gametypeId, +# playerId, +# activeSeats, +# position, +# tourneyTypeId, +# styleKey, +# HDs, +# street0VPI, +# street0Aggr, +# street0_3BChance, +# street0_3BDone, +# street1Seen, +# street2Seen, +# street3Seen, +# street4Seen, +# sawShowdown, +# street1Aggr, +# street2Aggr, +# street3Aggr, +# street4Aggr, +# otherRaisedStreet1, +# otherRaisedStreet2, +# otherRaisedStreet3, +# otherRaisedStreet4, +# foldToOtherRaisedStreet1, +# foldToOtherRaisedStreet2, +# foldToOtherRaisedStreet3, +# foldToOtherRaisedStreet4, +# wonWhenSeenStreet1, +# wonAtSD, +# stealAttemptChance, +# stealAttempted, +# foldBbToStealChance, +# foldedBbToSteal, +# foldSbToStealChance, +# foldedSbToSteal, +# street1CBChance, +# street1CBDone, +# street2CBChance, +# street2CBDone, +# street3CBChance, +# street3CBDone, +# street4CBChance, +# street4CBDone, +# foldToStreet1CBChance, +# foldToStreet1CBDone, +# foldToStreet2CBChance, +# foldToStreet2CBDone, +# foldToStreet3CBChance, +# foldToStreet3CBDone, +# foldToStreet4CBChance, +# foldToStreet4CBDone, +# totalProfit, +# street1CheckCallRaiseChance, +# street1CheckCallRaiseDone, +# street2CheckCallRaiseChance, +# street2CheckCallRaiseDone, +# street3CheckCallRaiseChance, +# street3CheckCallRaiseDone, +# street4CheckCallRaiseChance, +# street4CheckCallRaiseDone) + + q = q.replace('%s', self.sql.query['placeholder']) + + self.cursor.execute(q, ( + gid, + pid + )) + +# gametypeId, +# playerId, +# activeSeats, +# position, +# tourneyTypeId, +# styleKey, +# HDs, +# street0VPI, +# street0Aggr, +# street0_3BChance, +# street0_3BDone, +# street1Seen, +# street2Seen, +# street3Seen, +# street4Seen, +# sawShowdown, +# street1Aggr, +# street2Aggr, +# street3Aggr, +# street4Aggr, +# otherRaisedStreet1, +# otherRaisedStreet2, +# otherRaisedStreet3, +# otherRaisedStreet4, +# foldToOtherRaisedStreet1, +# foldToOtherRaisedStreet2, +# foldToOtherRaisedStreet3, +# foldToOtherRaisedStreet4, +# wonWhenSeenStreet1, +# wonAtSD, +# stealAttemptChance, +# stealAttempted, +# foldBbToStealChance, +# foldedBbToSteal, +# foldSbToStealChance, +# foldedSbToSteal, +# street1CBChance, +# street1CBDone, +# street2CBChance, +# street2CBDone, +# street3CBChance, +# street3CBDone, +# street4CBChance, +# street4CBDone, +# foldToStreet1CBChance, +# foldToStreet1CBDone, +# foldToStreet2CBChance, +# foldToStreet2CBDone, +# foldToStreet3CBChance, +# foldToStreet3CBDone, +# foldToStreet4CBChance, +# foldToStreet4CBDone, +# totalProfit, +# street1CheckCallRaiseChance, +# street1CheckCallRaiseDone, +# street2CheckCallRaiseChance, +# street2CheckCallRaiseDone, +# street3CheckCallRaiseChance, +# street3CheckCallRaiseDone, +# street4CheckCallRaiseChance, +# street4CheckCallRaiseDone) ################################# From 785e3d63a23beb143f85a951ea8a2b0450c8f8db Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 13 Oct 2009 21:52:13 +0100 Subject: [PATCH 6/8] add 'is db running' printed message when pg db connect fails --- pyfpdb/fpdb_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 17fecc2c..986c747f 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -111,7 +111,7 @@ class fpdb_db: password = password, database = database) except: - msg = "PostgreSQL connection to database (%s) user (%s) failed." % (database, user) + msg = "PostgreSQL connection to database (%s) user (%s) failed. Are you sure the DB is running?" % (database, user) print msg raise FpdbError(msg) elif backend == fpdb_db.SQLITE: From 4b0a399ffd273b016f4ba36b272cb814f8dda9b1 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 13 Oct 2009 21:53:51 +0100 Subject: [PATCH 7/8] stop fpdb.py accessing fpdb_db directly --- pyfpdb/Database.py | 25 ++++++++++++++----------- pyfpdb/fpdb.py | 28 +++++++++++++++++----------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index f0146c7f..4a0f2e17 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -188,14 +188,7 @@ class Database: log.info("Creating Database instance, sql = %s" % sql) self.config = c self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql - self.fdb.do_connect(c) - self.connection = self.fdb.db - - db_params = c.get_db_parameters() - self.import_options = c.get_import_parameters() - self.type = db_params['db-type'] - self.backend = db_params['db-backend'] - self.db_server = db_params['db-server'] + self.do_connect(c) if self.backend == self.PGSQL: from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_READ_COMMITTED, ISOLATION_LEVEL_SERIALIZABLE @@ -206,14 +199,14 @@ class Database: # where possible avoid creating new SQL instance by using the global one passed in if sql is None: - self.sql = SQL.Sql(type = self.type, db_server = db_params['db-server']) + self.sql = SQL.Sql(type = self.type, db_server = self.db_server) else: self.sql = sql - if self.backend == self.SQLITE and db_params['db-databaseName'] == ':memory:' and self.fdb.wrongDbVersion: + if self.backend == self.SQLITE and self.database == ':memory:' and self.wrongDbVersion: log.info("sqlite/:memory: - creating") self.recreate_tables() - self.fdb.wrongDbVersion = False + self.wrongDbVersion = False self.pcache = None # PlayerId cache self.cachemiss = 0 # Delete me later - using to count player cache misses @@ -245,6 +238,16 @@ class Database: def do_connect(self, c): self.fdb.do_connect(c) + self.connection = self.fdb.db + self.wrongDbVersion = self.fdb.wrongDbVersion + + db_params = c.get_db_parameters() + self.import_options = c.get_import_parameters() + self.type = db_params['db-type'] + self.backend = db_params['db-backend'] + self.db_server = db_params['db-server'] + self.database = db_params['db-databaseName'] + self.host = db_params['db-host'] def commit(self): self.fdb.db.commit() diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 6d58f733..18bc65d9 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -44,6 +44,7 @@ else: print "Python " + sys.version[0:3] + '...\n' +import traceback import threading import Options import string @@ -64,7 +65,6 @@ import gtk import interlocks -import fpdb_simple import GuiBulkImport import GuiPlayerStats import GuiPositionalStats @@ -76,7 +76,7 @@ import SQL import Database import FpdbSQLQueries import Configuration -import Exceptions +from Exceptions import * VERSION = "0.11" @@ -234,13 +234,13 @@ class fpdb: dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm deleting and recreating tables") diastring = "Please confirm that you want to (re-)create the tables. If there already are tables in the database " \ - +self.db.fdb.database+" on "+self.db.fdb.host+" they will be deleted." + +self.db.database+" on "+self.db.host+" they will be deleted." dia_confirm.format_secondary_text(diastring)#todo: make above string with bold for db, host and deleted response = dia_confirm.run() dia_confirm.destroy() if response == gtk.RESPONSE_YES: - #if self.db.fdb.backend == self.fdb_lock.fdb.MYSQL_INNODB: + #if self.db.backend == self.fdb_lock.fdb.MYSQL_INNODB: # mysql requires locks on all tables or none - easier to release this lock # than lock all the other tables # ToDo: lock all other tables so that lock doesn't have to be released @@ -455,17 +455,23 @@ class fpdb: self.sql = SQL.Sql(type = self.settings['db-type'], db_server = self.settings['db-server']) try: self.db = Database.Database(self.config, sql = self.sql) - except Exceptions.FpdbMySQLFailedError: + except FpdbMySQLFailedError: self.warning_box("Unable to connect to MySQL! Is the MySQL server running?!", "FPDB ERROR") exit() except FpdbError: - print "Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user']) + #print "Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user']) + self.warning_box("Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user']), "FPDB ERROR") + err = traceback.extract_tb(sys.exc_info()[2])[-1] + print "*** Error: " + err[2] + "(" + str(err[1]) + "): " + str(sys.exc_info()[1]) sys.stderr.write("Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user'])) except: - print "Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user']) + #print "Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user']) + self.warning_box("Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user']), "FPDB ERROR") + err = traceback.extract_tb(sys.exc_info()[2])[-1] + print "*** Error: " + err[2] + "(" + str(err[1]) + "): " + str(sys.exc_info()[1]) sys.stderr.write("Failed to connect to %s database with username %s." % (self.settings['db-server'], self.settings['db-user'])) - if self.db.fdb.wrongDbVersion: + if self.db.wrongDbVersion: diaDbVersionWarning = gtk.Dialog(title="Strong Warning - Invalid database version", parent=None, flags=0, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK)) label = gtk.Label("An invalid DB version or missing tables have been detected.") @@ -484,14 +490,14 @@ class fpdb: diaDbVersionWarning.destroy() if self.status_bar == None: - self.status_bar = gtk.Label("Status: Connected to %s database named %s on host %s"%(self.db.get_backend_name(),self.db.fdb.database, self.db.fdb.host)) + self.status_bar = gtk.Label("Status: Connected to %s database named %s on host %s"%(self.db.get_backend_name(),self.db.database, self.db.host)) self.main_vbox.pack_end(self.status_bar, False, True, 0) self.status_bar.show() else: - self.status_bar.set_text("Status: Connected to %s database named %s on host %s" % (self.db.get_backend_name(),self.db.fdb.database, self.db.fdb.host)) + self.status_bar.set_text("Status: Connected to %s database named %s on host %s" % (self.db.get_backend_name(),self.db.database, self.db.host)) # Database connected to successfully, load queries to pass on to other classes - self.db.connection.rollback() + self.db.rollback() self.validate_config() From 4d92e3d2a0275c8339062e9425f49dab9d605a0a Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 13 Oct 2009 23:06:09 +0100 Subject: [PATCH 8/8] update graph viewer to work with enhanced filter --- pyfpdb/Filters.py | 16 +++++---- pyfpdb/GuiGraphViewer.py | 77 ++++++++++++++++++++++++++-------------- pyfpdb/SQL.py | 12 +++---- 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/pyfpdb/Filters.py b/pyfpdb/Filters.py index ac036cbf..6ad242bb 100644 --- a/pyfpdb/Filters.py +++ b/pyfpdb/Filters.py @@ -32,19 +32,20 @@ import FpdbSQLQueries class Filters(threading.Thread): def __init__(self, db, config, qdict, display = {}, debug=True): - self.debug=debug + # config and qdict are now redundant + self.debug = debug #print "start of GraphViewer constructor" - self.db=db - self.cursor=db.cursor - self.sql=qdict - self.conf = config + self.db = db + self.cursor = db.cursor + self.sql = db.sql + self.conf = db.config self.display = display self.sites = {} self.games = {} self.limits = {} self.seats = {} - self.groups = {} + self.groups = {} self.siteid = {} self.heroes = {} self.boxes = {} @@ -451,6 +452,9 @@ class Filters(threading.Thread): hbox.pack_start(vbox3, False, False, 0) found = {'nl':False, 'fl':False, 'ring':False, 'tour':False} for i, line in enumerate(result): + if "UseType" in self.display: + if line[0] != self.display["UseType"]: + continue hbox = gtk.HBox(False, 0) if i <= len(result)/2: vbox2.pack_start(hbox, False, False, 0) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index f5beadcf..f91c9870 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -53,20 +53,26 @@ class GuiGraphViewer (threading.Thread): self.db = Database.Database(self.conf, sql=self.sql) - filters_display = { "Heroes" : True, - "Sites" : True, - "Games" : True, - "Limits" : True, - "Seats" : False, - "Dates" : True, - "Button1" : True, - "Button2" : True + filters_display = { "Heroes" : True, + "Sites" : True, + "Games" : True, + "Limits" : True, + "LimitSep" : True, + "LimitType" : True, + "Type" : False, + "UseType" : 'ring', + "Seats" : False, + "SeatSep" : False, + "Dates" : True, + "Groups" : False, + "Button1" : True, + "Button2" : True } self.filters = Filters.Filters(self.db, self.conf, self.sql, display = filters_display) - self.filters.registerButton1Name("Refresh Graph") + self.filters.registerButton1Name("Refresh _Graph") self.filters.registerButton1Callback(self.generateGraph) - self.filters.registerButton2Name("Export to File") + self.filters.registerButton2Name("_Export to File") self.filters.registerButton2Callback(self.exportGraph) self.mainHBox = gtk.HBox(False, 0) @@ -146,10 +152,8 @@ class GuiGraphViewer (threading.Thread): raise def generateGraph(self, widget, data): - print "generateGraph: start" try: self.clearGraphData() - print "after cleardata" sitenos = [] playerids = [] @@ -158,15 +162,18 @@ class GuiGraphViewer (threading.Thread): heroes = self.filters.getHeroes() siteids = self.filters.getSiteIds() limits = self.filters.getLimits() - print "got filter data" + for i in ('show', 'none'): + if i in limits: + limits.remove(i) # Which sites are selected? for site in sites: if sites[site] == True: sitenos.append(siteids[site]) - self.db.cursor.execute(self.sql.query['getPlayerId'], (heroes[site],)) - result = self.db.cursor.fetchall() + c = self.db.get_cursor() + c.execute(self.sql.query['getPlayerId'], (heroes[site],)) + result = c.fetchall() if len(result) == 1: - playerids.append(result[0][0]) + playerids.append( int(result[0][0]) ) if not sitenos: #Should probably pop up here. @@ -182,12 +189,10 @@ class GuiGraphViewer (threading.Thread): return #Set graph properties - print "add_subplot" self.ax = self.fig.add_subplot(111) #Get graph data from DB starttime = time() - print "get line: playerids =", playerids, "sitenos =", sitenos, "limits =", limits line = self.getRingProfitGraph(playerids, sitenos, limits) print "Graph generated in: %s" %(time() - starttime) @@ -234,12 +239,31 @@ class GuiGraphViewer (threading.Thread): # [5L] into (5) not (5,) and [5L, 2829L] into (5, 2829) nametest = str(tuple(names)) sitetest = str(tuple(sites)) - limittest = str(tuple(limits)) - nametest = nametest.replace("L", "") - nametest = nametest.replace(",)",")") - sitetest = sitetest.replace(",)",")") - limittest = limittest.replace("L", "") - limittest = limittest.replace(",)",")") + #nametest = nametest.replace("L", "") + + lims = [int(x) for x in limits if x.isdigit()] + nolims = [int(x[0:-2]) for x in limits if len(x) > 2 and x[-2:] == 'nl'] + limittest = "and ( (gt.limitType = 'fl' and gt.bigBlind in " + # and ( (limit and bb in()) or (nolimit and bb in ()) ) + if lims: + blindtest = str(tuple(lims)) + blindtest = blindtest.replace("L", "") + blindtest = blindtest.replace(",)",")") + limittest = limittest + blindtest + ' ) ' + else: + limittest = limittest + '(-1) ) ' + limittest = limittest + " or (gt.limitType = 'nl' and gt.bigBlind in " + if nolims: + blindtest = str(tuple(nolims)) + blindtest = blindtest.replace("L", "") + blindtest = blindtest.replace(",)",")") + limittest = limittest + blindtest + ' ) )' + else: + limittest = limittest + '(-1) ) )' + if type == 'ring': + limittest = limittest + " and gt.type = 'ring' " + elif type == 'tour': + limittest = limittest + " and gt.type = 'tour' " #Must be a nicer way to deal with tuples of size 1 ie. (2,) - which makes sql barf tmp = tmp.replace("", nametest) @@ -247,6 +271,7 @@ class GuiGraphViewer (threading.Thread): tmp = tmp.replace("", start_date) tmp = tmp.replace("", end_date) tmp = tmp.replace("", limittest) + tmp = tmp.replace(",)", ")") #print "DEBUG: sql query:" #print tmp @@ -255,10 +280,10 @@ class GuiGraphViewer (threading.Thread): winnings = self.db.cursor.fetchall() self.db.rollback() - if(winnings == ()): + if winnings == (): return None - y=map(lambda x:float(x[3]), winnings) + y = map(lambda x:float(x[1]), winnings) line = cumsum(y) return line/100 #end of def getRingProfitGraph diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 0f414e41..bb918d97 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -2455,16 +2455,16 @@ class Sql: # self.query['playerStatsByPosition'] = """ """ self.query['getRingProfitAllHandsPlayerIdSite'] = """ - SELECT hp.handId, hp.totalProfit, hp.totalProfit, hp.totalProfit + SELECT hp.handId, hp.totalProfit FROM HandsPlayers hp - INNER JOIN Players pl ON (hp.playerId = pl.id) - INNER JOIN Hands h ON (h.id = hp.handId) - INNER JOIN Gametypes g ON (h.gametypeId = g.id) - where pl.id in + INNER JOIN Players pl ON (pl.id = hp.playerId) + INNER JOIN Hands h ON (h.id = hp.handId) + INNER JOIN Gametypes gt ON (gt.id = h.gametypeId) + WHERE pl.id in AND pl.siteId in AND h.handStart > '' AND h.handStart < '' - AND g.bigBlind in + AND hp.tourneysPlayersId IS NULL GROUP BY h.handStart, hp.handId, hp.totalProfit ORDER BY h.handStart"""