From 2c251d94f27302ebb1a0ef77f126cd7292bec0d2 Mon Sep 17 00:00:00 2001 From: steffen123 Date: Tue, 2 Sep 2008 01:00:43 +0100 Subject: [PATCH] p78 - implemented stud HudCache generation and storing --- docs/known-bugs-and-planned-features.txt | 3 +- pyfpdb/fpdb.py | 32 ++--- pyfpdb/fpdb_parse_logic.py | 5 +- pyfpdb/fpdb_save_to_db.py | 10 +- pyfpdb/fpdb_simple.py | 152 +++++++++++++---------- 5 files changed, 107 insertions(+), 95 deletions(-) diff --git a/docs/known-bugs-and-planned-features.txt b/docs/known-bugs-and-planned-features.txt index e4e43af7..7ff766cb 100644 --- a/docs/known-bugs-and-planned-features.txt +++ b/docs/known-bugs-and-planned-features.txt @@ -10,8 +10,6 @@ find correct sf logo link windows integrated installer update install-in-gentoo on website update ebuild and ubuntu guide for HUD_config.xml -implement stud HudCache -implement storeHudCache for stud base store raw hand in db and write reimport function using the raw hand field ftp: read maxSeats @@ -25,6 +23,7 @@ printhand each and the 2/3 relevant printplayerflags respectively on ps-lhe-ring alpha4 (release 8Sep?) ====== change to savannah? +implement steal and positions in stud anonymiser script to generate testdata without making a dozen find&replace all... remember to replace hand no with running no Everything that didn't make it into alpha3 Import draw (maybe without HudCache for a start) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 1a0ffaa6..def44534 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -407,7 +407,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) self.window.connect("destroy", self.destroy) - self.window.set_title("Free Poker DB - version: alpha2+, p76") + self.window.set_title("Free Poker DB - version: alpha2+, p78") self.window.set_border_width(1) self.window.set_size_request(1020,400) self.window.set_resizable(True) @@ -417,22 +417,22 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") ( "/Main/_Load Profile (broken)", "L", self.dia_load_profile, 0, None ), ( "/Main/_Edit Profile (todo)", "E", self.dia_edit_profile, 0, None ), ( "/Main/_Save Profile (todo)", None, self.dia_save_profile, 0, None ), - ( "/Main/sep1", None, None, 0, "" ), - ( "/Main/_Quit", "Q", self.quit, 0, None ), - ( "/_Import", None, None, 0, "" ), - ( "/Import/_Bulk Import", "B", self.tab_bulk_import, 0, None ), - ( "/Import/_Auto Import (todo)", "A", self.tab_auto_import, 0, None ), - ( "/Import/Auto _Rating (todo)", "R", self.not_implemented, 0, None ), - ( "/_Viewers", None, None, 0, "" ), - ( "/Viewers/_Graphs (todo)", None, self.not_implemented, 0, None ), - ( "/Viewers/H_and Replayer (todo)", None, self.not_implemented, 0, None ), - ( "/Viewers/Player _Details (todo)", None, self.not_implemented, 0, None ), - ( "/Viewers/_Player Stats (tabulated view) (todo)", None, self.not_implemented, 0, None ), - ( "/Viewers/Starting _Hands (todo)", None, self.not_implemented, 0, None ), - ( "/Viewers/_Session Replayer (todo)", None, self.not_implemented, 0, None ), - ( "/Viewers/Poker_table Viewer", "T", self.tab_table_viewer, 0, None ), + ("/Main/sep1", None, None, 0, "" ), + ("/Main/_Quit", "Q", self.quit, 0, None ), + ("/_Import", None, None, 0, "" ), + ("/Import/_Bulk Import", "B", self.tab_bulk_import, 0, None ), + ("/Import/_Auto Import and HUD", "A", self.tab_auto_import, 0, None ), + ("/Import/Auto _Rating (todo)", "R", self.not_implemented, 0, None ), + ("/_Viewers", None, None, 0, "" ), + ("/_Viewers/_Auto Import and HUD", "A", self.tab_auto_import, 0, None ), + ("/Viewers/_Graphs (todo)", None, self.not_implemented, 0, None ), + ("/Viewers/Hand _Replayer (todo)", None, self.not_implemented, 0, None ), + ("/Viewers/Player _Details (todo)", None, self.not_implemented, 0, None ), + ("/Viewers/_Player Stats (tabulated view) (todo)", None, self.not_implemented, 0, None ), + ("/Viewers/Starting _Hands (todo)", None, self.not_implemented, 0, None ), + ("/Viewers/_Session Replayer (todo)", None, self.not_implemented, 0, None ), + ("/Viewers/Poker_table Viewer", "T", self.tab_table_viewer, 0, None ), #( "/Viewers/Tourney Replayer - #( "/H_UD", None, None, 0, "" ), ( "/_Database", None, None, 0, "" ), ( "/Database/Create or Delete _Database (todo)", None, self.dia_create_del_database, 0, None ), ( "/Database/Create or Delete _User (todo)", None, self.dia_create_del_user, 0, None ), diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index a33f040a..6696f64e 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -118,10 +118,9 @@ def mainParser(db, cursor, site, category, hand): totalWinnings+=winnings[i] if base=="hold": - hudImportData=fpdb_simple.generateHudCacheData(playerIDs, category, actionTypes, actionTypeByNo, winnings, totalWinnings, positions) + hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes, actionTypeByNo, winnings, totalWinnings, positions) else: - print "todo: stud HudCache" - hudImportData=None + hudImportData=fpdb_simple.generateHudCacheData(playerIDs, base, category, actionTypes, actionTypeByNo, winnings, totalWinnings, None) if isTourney: ranks=[] diff --git a/pyfpdb/fpdb_save_to_db.py b/pyfpdb/fpdb_save_to_db.py index dccbcba7..c07fd225 100644 --- a/pyfpdb/fpdb_save_to_db.py +++ b/pyfpdb/fpdb_save_to_db.py @@ -27,9 +27,9 @@ def ring_stud(cursor, base, category, site_hand_no, gametype_id, hand_start_time hands_id=fpdb_simple.storeHands(cursor, site_hand_no, gametype_id, hand_start_time, names, tableName, maxSeats) hands_players_ids=fpdb_simple.store_hands_players_stud(cursor, hands_id, player_ids, - start_cashes, antes, card_values, card_suits, winnings, rakes) + start_cashes, antes, card_values, card_suits, winnings, rakes, seatNos) - fpdb_simple.storeHudCache(cursor, category, gametype_id, player_ids, hudImportData) + fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData) fpdb_simple.storeActions(cursor, hands_players_ids, action_types, action_amounts, actionNos) return hands_id @@ -44,7 +44,7 @@ def ring_holdem_omaha(cursor, base, category, site_hand_no, gametype_id, hand_st hands_players_ids=fpdb_simple.store_hands_players_holdem_omaha(cursor, category, hands_id, player_ids, start_cashes, positions, card_values, card_suits, winnings, rakes, seatNos) - fpdb_simple.storeHudCache(cursor, category, gametype_id, player_ids, hudImportData) + fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData) fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) @@ -65,7 +65,7 @@ def tourney_holdem_omaha(cursor, base, category, siteTourneyNo, buyin, fee, knoc hands_players_ids=fpdb_simple.store_hands_players_holdem_omaha_tourney(cursor, category, hands_id, player_ids, start_cashes, positions, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids) - fpdb_simple.storeHudCache(cursor, category, gametype_id, player_ids, hudImportData) + fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData) fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits) @@ -90,7 +90,7 @@ def tourney_stud(cursor, base, category, site_tourney_no, buyin, fee, knockout, hands_players_ids=fpdb_simple.store_hands_players_stud_tourney(cursor, hands_id, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes, tourneys_players_ids) - fpdb_simple.storeHudData(cursor, category, player_ids, hudImportData) + fpdb_simple.storeHudData(cursor, base, category, player_ids, hudImportData) fpdb_simple.storeActions(cursor, hands_players_ids, action_types, action_amounts) return hands_id diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 923c2053..1c854008 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -1201,7 +1201,7 @@ def store_hands_players_holdem_omaha(cursor, category, hands_id, player_ids, sta #end def store_hands_players_holdem_omaha def store_hands_players_stud(cursor, hands_id, player_ids, start_cashes, antes, - card_values, card_suits, winnings, rakes): + card_values, card_suits, winnings, rakes, seatNos): #stores hands_players rows for stud/razz games. returns an array of the resulting IDs result=[] for i in range (len(player_ids)): @@ -1210,14 +1210,14 @@ def store_hands_players_stud(cursor, hands_id, player_ids, start_cashes, antes, card1Value, card1Suit, card2Value, card2Suit, card3Value, card3Suit, card4Value, card4Suit, card5Value, card5Suit, card6Value, card6Suit, - card7Value, card7Suit, winnings, rake) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, + card7Value, card7Suit, winnings, rake, seatNo) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", (hands_id, player_ids[i], start_cashes[i], antes[i], 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], card_values[i][4], card_suits[i][4], card_values[i][5], card_suits[i][5], - card_values[i][6], card_suits[i][6], winnings[i], rakes[i])) + card_values[i][6], card_suits[i][6], winnings[i], rakes[i], seatNos[i])) cursor.execute("SELECT id FROM HandsPlayers WHERE handId=%s AND playerId=%s", (hands_id, player_ids[i])) result.append(cursor.fetchall()[0][0]) return result @@ -1278,7 +1278,7 @@ def store_hands_players_stud_tourney(cursor, hands_id, player_ids, start_cashes, return result #end def store_hands_players_stud_tourney -def generateHudCacheData(player_ids, category, action_types, actionTypeByNo, winnings, totalWinnings, positions): +def generateHudCacheData(player_ids, base, category, action_types, actionTypeByNo, winnings, totalWinnings, positions): """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""" #setup subarrays of the result dictionary. street0VPI=[] @@ -1333,15 +1333,16 @@ def generateHudCacheData(player_ids, category, action_types, actionTypeByNo, win buttonId=-1 sbId=-1 bbId=-1 - for player in range(len(positions)): - if positions==1: - cutoffId=player_ids[player] - if positions==0: - buttonId=player_ids[player] - if positions=='S': - sbId=player_ids[player] - if positions=='B': - bbId=player_ids[player] + if base=="hold": + for player in range(len(positions)): + if positions==1: + cutoffId=player_ids[player] + if positions==0: + buttonId=player_ids[player] + if positions=='S': + sbId=player_ids[player] + if positions=='B': + bbId=player_ids[player] someoneStole=False @@ -1400,30 +1401,31 @@ def generateHudCacheData(player_ids, category, action_types, actionTypeByNo, win myStreet0_3B4BDone=True #steal calculations - if len(player_ids)>=5: #no point otherwise - if positions[player]==1: - if firstPfRaiserId==player_ids[player]: - myStealAttemptChance=True - myStealAttempted=True - elif firstPfRaiserId==buttonId or firstPfRaiserId==sbId or firstPfRaiserId==bbId or firstPfRaiserId==-1: - myStealAttemptChance=True - if positions[player]==0: - if firstPfRaiserId==player_ids[player]: - myStealAttemptChance=True - myStealAttempted=True - elif firstPfRaiserId==sbId or firstPfRaiserId==bbId or firstPfRaiserId==-1: - myStealAttemptChance=True - if positions[player]=='S': - if firstPfRaiserId==player_ids[player]: - myStealAttemptChance=True - myStealAttempted=True - elif firstPfRaiserId==bbId or firstPfRaiserId==-1: - myStealAttemptChance=True - if positions[player]=='B': - pass + if base=="hold": + if len(player_ids)>=5: #no point otherwise + if positions[player]==1: + if firstPfRaiserId==player_ids[player]: + myStealAttemptChance=True + myStealAttempted=True + elif firstPfRaiserId==buttonId or firstPfRaiserId==sbId or firstPfRaiserId==bbId or firstPfRaiserId==-1: + myStealAttemptChance=True + if positions[player]==0: + if firstPfRaiserId==player_ids[player]: + myStealAttemptChance=True + myStealAttempted=True + elif firstPfRaiserId==sbId or firstPfRaiserId==bbId or firstPfRaiserId==-1: + myStealAttemptChance=True + if positions[player]=='S': + if firstPfRaiserId==player_ids[player]: + myStealAttemptChance=True + myStealAttempted=True + elif firstPfRaiserId==bbId or firstPfRaiserId==-1: + myStealAttemptChance=True + if positions[player]=='B': + pass - if myStealAttempted: - someoneStole=True + if myStealAttempted: + someoneStole=True #calculate saw* values if (len(action_types[1][player])>0): @@ -1523,21 +1525,25 @@ def generateHudCacheData(player_ids, category, action_types, actionTypeByNo, win wonAtSD.append(myWonAtSD) stealAttemptChance.append(myStealAttemptChance) stealAttempted.append(myStealAttempted) - 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<=7: - hudDataPositions.append('L') - else: - raise FpdbError("invalid position") + 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<=7: + hudDataPositions.append('L') + else: + raise FpdbError("invalid position") + elif base=="stud": + #todo: stud positions and steals + pass #add each array to the to-be-returned dictionary result={'street0VPI':street0VPI} @@ -1578,17 +1584,18 @@ def generateHudCacheData(player_ids, category, action_types, actionTypeByNo, win myFoldSbToStealChance=False myFoldedSbToSteal=False - if someoneStole and (positions[player]=='B' or positions[player]=='S') and firstPfRaiserId!=player_ids[player]: - street=0 - for count in range (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 + if base=="hold": + if someoneStole and (positions[player]=='B' or positions[player]=='S') and firstPfRaiserId!=player_ids[player]: + street=0 + for count in range (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) @@ -1797,10 +1804,14 @@ def generateFoldToCB(street, playerIDs, didStreetCB, streetCBDone, foldToStreetC foldToStreetCBDone[player]=True #end def generateFoldToCB -def storeHudCache(cursor, category, gametypeId, playerIds, hudImportData): - if (category=="holdem" or category=="omahahi" or category=="omahahilo"): +def storeHudCache(cursor, base, category, gametypeId, playerIds, hudImportData): +# if (category=="holdem" or category=="omahahi" or category=="omahahilo"): + for player in range (len(playerIds)): - cursor.execute("SELECT * FROM HudCache WHERE gametypeId=%s AND playerId=%s AND activeSeats=%s AND position=%s", (gametypeId, playerIds[player], len(playerIds), hudImportData['position'][player])) + if base=="hold": + cursor.execute("SELECT * FROM HudCache WHERE gametypeId=%s AND playerId=%s AND activeSeats=%s AND position=%s", (gametypeId, playerIds[player], len(playerIds), hudImportData['position'][player])) + else: + cursor.execute("SELECT * FROM HudCache WHERE gametypeId=%s AND playerId=%s AND activeSeats=%s", (gametypeId, playerIds[player], len(playerIds))) row=cursor.fetchone() #print "gametypeId:", gametypeId, "playerIds[player]",playerIds[player], "len(playerIds):",len(playerIds), "row:",row @@ -1826,7 +1837,10 @@ def storeHudCache(cursor, category, gametypeId, playerIds, hudImportData): newrow.append(row[i]) row=newrow - row[4]=hudImportData['position'][player] + if base=="hold": + row[4]=hudImportData['position'][player] + else: + row[4]=0 row[5]=1 #tourneysGametypeId row[6]+=1 #HDs if hudImportData['street0VPI'][player]: row[7]+=1 @@ -1938,8 +1952,8 @@ def storeHudCache(cursor, category, gametypeId, playerIds, hudImportData): row[41], row[42], row[43], row[44], row[45], row[46], row[47], row[48], row[49], row[50], row[51], row[52], row[53], row[54], row[55], row[56], row[57], row[58], row[59], row[60], row[1], row[2], row[3], row[4], row[5])) - else: - print "todo: implement storeHudCache for stud base" +# else: +# print "todo: implement storeHudCache for stud base" #end def storeHudCache def store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, startTime):