Lots of changes. Fixes the hud for auto-import - at least for me.

Does configer Importer to use the Config class.
This commit is contained in:
Worros 2008-11-09 21:57:58 +10:00
parent d0218363c6
commit d4038c3f19
8 changed files with 162 additions and 92 deletions

View File

@ -53,7 +53,7 @@ if __name__ == "__main__":
(options, sys.argv) = parser.parse_args() (options, sys.argv) = parser.parse_args()
settings={'imp-callFpdbHud':False, 'db-backend':2} settings={'callFpdbHud':False, 'db-backend':2}
settings['db-host']=options.server settings['db-host']=options.server
settings['db-user']=options.user settings['db-user']=options.user
settings['db-password']=options.password settings['db-password']=options.password

View File

@ -443,8 +443,8 @@ class Config:
imp['interval'] = self.interval imp['interval'] = self.interval
imp['hhArchiveBase'] = self.hhArchiveBase imp['hhArchiveBase'] = self.hhArchiveBase
except: # Default params except: # Default params
imp['callFpdbHud'] = 10 imp['callFpdbHud'] = True
imp['interval'] = True imp['interval'] = 10
imp['hhArchiveBase'] = "~/.fpdb/HandHistories/" imp['hhArchiveBase'] = "~/.fpdb/HandHistories/"
return imp return imp

View File

@ -17,7 +17,41 @@
######################################################################## ########################################################################
import Configuration import Configuration
from HandHistoryConverter import HandHistoryConverter from HandHistoryConverter import *
# Everleaf HH format
#Everleaf Gaming Game #55198191
#***** Hand history for game #55198191 *****
#Blinds $0.50/$1 NL Hold'em - 2008/09/01 - 10:02:11
#Table Speed Kuala
#Seat 8 is the button
#Total number of players: 10
#Seat 1: spicybum ( $ 77.50 USD )
#Seat 2: harrydebeng ( new player )
#Seat 3: EricBlade ( new player )
#Seat 4: dollar_hecht ( $ 16.40 USD )
#Seat 5: Apolon76 ( $ 154.10 USD )
#Seat 6: dogge ( new player )
#Seat 7: RonKoro ( $ 25.53 USD )
#Seat 8: jay68w ( $ 48.50 USD )
#Seat 9: KillerQueen1 ( $ 51.28 USD )
#Seat 10: Cheburashka ( $ 49.61 USD )
#KillerQueen1: posts small blind [$ 0.50 USD]
#Cheburashka: posts big blind [$ 1 USD]
#** Dealing down cards **
#spicybum folds
#dollar_hecht calls [$ 1 USD]
#Apolon76 folds
#RonKoro folds
#jay68w raises [$ 4.50 USD]
#KillerQueen1 folds
#Cheburashka folds
#dollar_hecht folds
#jay68w does not show cards
#jay68w wins $ 3.50 USD from main pot
class Everleaf(HandHistoryConverter): class Everleaf(HandHistoryConverter):
def __init__(self, config, file): def __init__(self, config, file):
@ -25,12 +59,16 @@ class Everleaf(HandHistoryConverter):
HandHistoryConverter.__init__(self, config, file, "Everleaf") # Call super class init. HandHistoryConverter.__init__(self, config, file, "Everleaf") # Call super class init.
self.sitename = "Everleaf" self.sitename = "Everleaf"
self.setFileType("text") self.setFileType("text")
self.rexx.setSplitHandRegex("\n\n\n")
self.rexx.compileRegexes()
def readSupportedGames(self): def readSupportedGames(self):
pass pass
def determineGameType(self): def determineGameType(self):
pass gametype = ["ring", "hold", "nl"]
return gametype
def readPlayerStacks(self): def readPlayerStacks(self):
pass pass
@ -45,5 +83,5 @@ if __name__ == "__main__":
c = Configuration.Config() c = Configuration.Config()
e = Everleaf(c, "regression-test-files/everleaf/Speed_Kuala.txt") e = Everleaf(c, "regression-test-files/everleaf/Speed_Kuala.txt")
e.processFile() e.processFile()
print str(e) # print str(e)

View File

@ -12,7 +12,6 @@
# Modified for use in fpdb by Carl Gherardi # Modified for use in fpdb by Carl Gherardi
import re import re
import regex
# These are PokerStars specific; # These are PokerStars specific;
# More importantly, they are currently valid for cash game only. # More importantly, they are currently valid for cash game only.
@ -28,129 +27,130 @@ import regex
class FpdbRegex: class FpdbRegex:
def __init__(self): def __init__(self):
__NEW_HAND_REGEX='^.?PokerStars Game #\d+:\s+Hold\'em' self.__SPLIT_HAND_REGEX='\n\n\n'
__HAND_INFO_REGEX='^.*#(\d+):\s+(\S+)\s([\s\S]+)\s\(\$?([.0-9]+)/\$?([.0-9]+)\)\s-\s(\S+)\s-?\s?(\S+)\s\(?(\w+)\)?' self.__NEW_HAND_REGEX='^.?PokerStars Game #\d+:\s+Hold\'em'
__TABLE_INFO_REGEX='^\S+\s+\'.*\'\s+(\d+)-max\s+Seat\s#(\d+)' self.__HAND_INFO_REGEX='^.*#(\d+):\s+(\S+)\s([\s\S]+)\s\(\$?([.0-9]+)/\$?([.0-9]+)\)\s-\s(\S+)\s-?\s?(\S+)\s\(?(\w+)\)?'
__PLAYER_INFO_REGEX='^Seat\s(\d+):\s(.*)\s\(\$?([.\d]+)\s' self.__TABLE_INFO_REGEX='^\S+\s+\'.*\'\s+(\d+)-max\s+Seat\s#(\d+)'
__POST_SB_REGEX='^(.*):\sposts small blind' self.__PLAYER_INFO_REGEX='^Seat\s(\d+):\s(.*)\s\(\$?([.\d]+)\s'
__POST_BB_REGEX='^(.*):\sposts big blind' self.__POST_SB_REGEX='^(.*):\sposts small blind'
__POST_BOTH_REGEX='^(.*):\sposts small & big blinds' self.__POST_BB_REGEX='^(.*):\sposts big blind'
__HAND_STAGE_REGEX='^\*{3}\s(.*)\s\*{3}' self.__POST_BOTH_REGEX='^(.*):\sposts small & big blinds'
__HOLE_CARD_REGEX='^\*{3}\sHOLE CARDS' self.__HAND_STAGE_REGEX='^\*{3}\s(.*)\s\*{3}'
__FLOP_CARD_REGEX='^\*{3}\sFLOP\s\*{3}\s\[(\S{2})\s(\S{2})\s(\S{2})\]' self.__HOLE_CARD_REGEX='^\*{3}\sHOLE CARDS'
__TURN_CARD_REGEX='^\*{3}\sTURN\s\*{3}\s\[\S{2}\s\S{2}\s\S{2}\]\s\[(\S{2})\]' self.__FLOP_CARD_REGEX='^\*{3}\sFLOP\s\*{3}\s\[(\S{2})\s(\S{2})\s(\S{2})\]'
__RIVER_CARD_REGEX='^\*{3}\sRIVER\s\*{3}\s\[\S{2}\s\S{2}\s\S{2}\s\S{2}\]\s\[(\S{2})\]' self.__TURN_CARD_REGEX='^\*{3}\sTURN\s\*{3}\s\[\S{2}\s\S{2}\s\S{2}\]\s\[(\S{2})\]'
__SHOWDOWN_REGEX='^\*{3}\sSHOW DOWN' self.__RIVER_CARD_REGEX='^\*{3}\sRIVER\s\*{3}\s\[\S{2}\s\S{2}\s\S{2}\s\S{2}\]\s\[(\S{2})\]'
__SUMMARY_REGEX='^\*{3}\sSUMMARY' self.__SHOWDOWN_REGEX='^\*{3}\sSHOW DOWN'
__UNCALLED_BET_REGEX='^Uncalled bet \(\$([.\d]+)\) returned to (.*)' self.__SUMMARY_REGEX='^\*{3}\sSUMMARY'
__POT_AND_RAKE_REGEX='^Total\spot\s\$([.\d]+).*\|\sRake\s\$([.\d]+)' self.__UNCALLED_BET_REGEX='^Uncalled bet \(\$([.\d]+)\) returned to (.*)'
__COLLECT_POT_REGEX='^(.*)\scollected\s\$([.\d]+)\sfrom\s((main|side)\s)?pot' self.__POT_AND_RAKE_REGEX='^Total\spot\s\$([.\d]+).*\|\sRake\s\$([.\d]+)'
__POCKET_CARDS_REGEX='^Dealt\sto\s(.*)\s\[(\S{2})\s(\S{2})\]' self.__COLLECT_POT_REGEX='^(.*)\scollected\s\$([.\d]+)\sfrom\s((main|side)\s)?pot'
__SHOWN_CARDS_REGEX='^(.*):\sshows\s\[(\S{2})\s(\S{2})\]' self.__POCKET_CARDS_REGEX='^Dealt\sto\s(.*)\s\[(\S{2})\s(\S{2})\]'
__ACTION_STEP_REGEX='^(.*):\s(bets|checks|raises|calls|folds)((\s\$([.\d]+))?(\sto\s\$([.\d]+))?)?' self.__SHOWN_CARDS_REGEX='^(.*):\sshows\s\[(\S{2})\s(\S{2})\]'
self.__ACTION_STEP_REGEX='^(.*):\s(bets|checks|raises|calls|folds)((\s\$([.\d]+))?(\sto\s\$([.\d]+))?)?'
__SHOWDOWN_ACTION_REGEX='^(.*):\s(shows|mucks)' self.__SHOWDOWN_ACTION_REGEX='^(.*):\s(shows|mucks)'
__SUMMARY_CARDS_REGEX='^Seat\s\d+:\s(.*)\s(showed|mucked)\s\[(\S{2})\s(\S{2})\]' self.__SUMMARY_CARDS_REGEX='^Seat\s\d+:\s(.*)\s(showed|mucked)\s\[(\S{2})\s(\S{2})\]'
__SUMMARY_CARDS_EXTRA_REGEX='^Seat\s\d+:\s(.*)\s(\(.*\)\s)(showed|mucked)\s\[(\S{2})\s(\S{2})\]' self.__SUMMARY_CARDS_EXTRA_REGEX='^Seat\s\d+:\s(.*)\s(\(.*\)\s)(showed|mucked)\s\[(\S{2})\s(\S{2})\]'
self.m = regex.RegexMatch()
def getRegexes(): def compileRegexes(self):
return self.m
def compileRegexes():
### Compile the regexes ### Compile the regexes
m.hand_start_re = re.compile(__NEW_HAND_REGEX) self.split_hand_re = re.compile(self.__SPLIT_HAND_REGEX)
m.hand_info_re = re.compile(__HAND_INFO_REGEX) self.hand_start_re = re.compile(self.__NEW_HAND_REGEX)
m.table_info_re = re.compile(__TABLE_INFO_REGEX) self.hand_info_re = re.compile(self.__HAND_INFO_REGEX)
m.player_info_re = re.compile(__PLAYER_INFO_REGEX) self.table_info_re = re.compile(self.__TABLE_INFO_REGEX)
m.small_blind_re = re.compile(__POST_SB_REGEX) self.player_info_re = re.compile(self.__PLAYER_INFO_REGEX)
m.big_blind_re = re.compile(__POST_BB_REGEX) self.small_blind_re = re.compile(self.__POST_SB_REGEX)
m.both_blinds_re = re.compile(__POST_BOTH_REGEX) self.big_blind_re = re.compile(self.__POST_BB_REGEX)
m.hand_stage_re = re.compile(__HAND_STAGE_REGEX) self.both_blinds_re = re.compile(self.__POST_BOTH_REGEX)
m.hole_cards_re = re.compile(__HOLE_CARD_REGEX) self.hand_stage_re = re.compile(self.__HAND_STAGE_REGEX)
m.flop_cards_re = re.compile(__FLOP_CARD_REGEX) self.hole_cards_re = re.compile(self.__HOLE_CARD_REGEX)
m.turn_card_re = re.compile(__TURN_CARD_REGEX) self.flop_cards_re = re.compile(self.__FLOP_CARD_REGEX)
m.river_card_re = re.compile(__RIVER_CARD_REGEX) self.turn_card_re = re.compile(self.__TURN_CARD_REGEX)
m.showdown_re = re.compile(__SHOWDOWN_REGEX) self.river_card_re = re.compile(self.__RIVER_CARD_REGEX)
m.summary_re = re.compile(__SUMMARY_REGEX) self.showdown_re = re.compile(self.__SHOWDOWN_REGEX)
m.uncalled_bet_re = re.compile(__UNCALLED_BET_REGEX) self.summary_re = re.compile(self.__SUMMARY_REGEX)
m.collect_pot_re = re.compile(__COLLECT_POT_REGEX) self.uncalled_bet_re = re.compile(self.__UNCALLED_BET_REGEX)
m.pocket_cards_re = re.compile(__POCKET_CARDS_REGEX) self.collect_pot_re = re.compile(self.__COLLECT_POT_REGEX)
m.cards_shown_re = re.compile(__SHOWN_CARDS_REGEX) self.pocket_cards_re = re.compile(self.__POCKET_CARDS_REGEX)
m.summary_cards_re = re.compile(__SUMMARY_CARDS_REGEX) self.cards_shown_re = re.compile(self.__SHOWN_CARDS_REGEX)
m.summary_cards_extra_re = re.compile(__SUMMARY_CARDS_EXTRA_REGEX) self.summary_cards_re = re.compile(self.__SUMMARY_CARDS_REGEX)
m.action_re = re.compile(__ACTION_STEP_REGEX) self.summary_cards_extra_re = re.compile(self.__SUMMARY_CARDS_EXTRA_REGEX)
m.rake_re = re.compile(__POT_AND_RAKE_REGEX) self.action_re = re.compile(self.__ACTION_STEP_REGEX)
m.showdown_action_re = re.compile(__SHOWDOWN_ACTION_REGEX) self.rake_re = re.compile(self.__POT_AND_RAKE_REGEX)
self.showdown_action_re = re.compile(self.__SHOWDOWN_ACTION_REGEX)
# Set methods for plugins to override # Set methods for plugins to override
def setSplitHandRegex(self, string):
self.__SPLIT_HAND_REGEX = string
def setNewHandRegex(self, string): def setNewHandRegex(self, string):
__NEW_HAND_REGEX = string self.__NEW_HAND_REGEX = string
def setHandInfoRegex(self, string): def setHandInfoRegex(self, string):
__HAND_INFO_REGEX = string self.__HAND_INFO_REGEX = string
def setTableInfoRegex(self, string): def setTableInfoRegex(self, string):
__TABLE_INFO_REGEX = string self.__TABLE_INFO_REGEX = string
def setPlayerInfoRegex(self, string): def setPlayerInfoRegex(self, string):
__PLAYER_INFO_REGEX = string self.__PLAYER_INFO_REGEX = string
def setPostSbRegex(self, string): def setPostSbRegex(self, string):
__POST_SB_REGEX = string self.__POST_SB_REGEX = string
def setPostBbRegex(self, string): def setPostBbRegex(self, string):
__POST_BB_REGEX = string self.__POST_BB_REGEX = string
def setPostBothRegex(self, string): def setPostBothRegex(self, string):
__POST_BOTH_REGEX = string self.__POST_BOTH_REGEX = string
def setHandStageRegex(self, string): def setHandStageRegex(self, string):
__HAND_STAGE_REGEX = string self.__HAND_STAGE_REGEX = string
def setHoleCardRegex(self, string): def setHoleCardRegex(self, string):
__HOLE_CARD_REGEX = string self.__HOLE_CARD_REGEX = string
def setFlopCardRegex(self, string): def setFlopCardRegex(self, string):
__FLOP_CARD_REGEX = string self.__FLOP_CARD_REGEX = string
def setTurnCardRegex(self, string): def setTurnCardRegex(self, string):
__TURN_CARD_REGEX = string self.__TURN_CARD_REGEX = string
def setRiverCardRegex(self, string): def setRiverCardRegex(self, string):
__RIVER_CARD_REGEX = string self.__RIVER_CARD_REGEX = string
def setShowdownRegex(self, string): def setShowdownRegex(self, string):
__SHOWDOWN_REGEX = string self.__SHOWDOWN_REGEX = string
def setSummaryRegex(self, string): def setSummaryRegex(self, string):
__SUMMARY_REGEX = string self.__SUMMARY_REGEX = string
def setUncalledBetRegex(self, string): def setUncalledBetRegex(self, string):
__UNCALLED_BET_REGEX = string self.__UNCALLED_BET_REGEX = string
def setCollectPotRegex(self, string): def setCollectPotRegex(self, string):
__COLLECT_POT_REGEX = string self.__COLLECT_POT_REGEX = string
def setPocketCardsRegex(self, string): def setPocketCardsRegex(self, string):
__POCKET_CARDS_REGEX = string self.__POCKET_CARDS_REGEX = string
def setShownCardsRegex(self, string): def setShownCardsRegex(self, string):
__SHOWN_CARDS_REGEX = string self.__SHOWN_CARDS_REGEX = string
def setSummaryCardsRegex(self, string): def setSummaryCardsRegex(self, string):
__SUMMARY_CARDS_REGEX = string self.__SUMMARY_CARDS_REGEX = string
def setSummaryCardsExtraRegex(self, string): def setSummaryCardsExtraRegex(self, string):
__SUMMARY_CARDS_EXTRA_REGEX = string self.__SUMMARY_CARDS_EXTRA_REGEX = string
def setActionStepRegex(self, string): def setActionStepRegex(self, string):
__ACTION_STEP_REGEX = string self.__ACTION_STEP_REGEX = string
def setPotAndRakeRegex(self, string): def setPotAndRakeRegex(self, string):
__POT_AND_RAKE_REGEX = string self.__POT_AND_RAKE_REGEX = string
def setShowdownActionRegex(self, string): def setShowdownActionRegex(self, string):
__SHOWDOWN_ACTION_REGEX = string self.__SHOWDOWN_ACTION_REGEX = string

View File

@ -33,9 +33,14 @@ class GuiAutoImport (threading.Thread):
self.settings=settings self.settings=settings
self.config=config self.config=config
imp = self.config.get_import_parameters()
print "Import parameters"
print imp
self.input_settings = {} self.input_settings = {}
self.importer = fpdb_import.Importer(self,self.settings) self.importer = fpdb_import.Importer(self,self.settings, self.config)
self.importer.setCallHud(True) self.importer.setCallHud(True)
self.importer.setMinPrint(30) self.importer.setMinPrint(30)
self.importer.setQuiet(False) self.importer.setQuiet(False)
@ -195,7 +200,7 @@ if __name__== "__main__":
settings['db-databaseName'] = "fpdb" settings['db-databaseName'] = "fpdb"
settings['hud-defaultInterval'] = 10 settings['hud-defaultInterval'] = 10
settings['hud-defaultPath'] = 'C:/Program Files/PokerStars/HandHistory/nutOmatic' settings['hud-defaultPath'] = 'C:/Program Files/PokerStars/HandHistory/nutOmatic'
settings['imp-callFpdbHud'] = True settings['callFpdbHud'] = True
i = GuiAutoImport(settings) i = GuiAutoImport(settings)
main_window = gtk.Window() main_window = gtk.Window()

View File

@ -80,7 +80,7 @@ class GuiBulkImport (threading.Thread):
self.db=db self.db=db
self.settings=settings self.settings=settings
self.config=config self.config=config
self.importer = fpdb_import.Importer(self,self.settings) self.importer = fpdb_import.Importer(self,self.settings, config)
self.vbox=gtk.VBox(False,1) self.vbox=gtk.VBox(False,1)
self.vbox.show() self.vbox.show()

View File

@ -16,7 +16,8 @@
#agpl-3.0.txt in the docs folder of the package. #agpl-3.0.txt in the docs folder of the package.
import Configuration import Configuration
#import FpdbRegex import FpdbRegex
import re
import sys import sys
import traceback import traceback
import os import os
@ -38,6 +39,7 @@ class HandHistoryConverter:
self.hhdir = os.path.join(self.hhbase,sitename) self.hhdir = os.path.join(self.hhbase,sitename)
self.gametype = [] self.gametype = []
# self.ofile = os.path.join(self.hhdir,file) # self.ofile = os.path.join(self.hhdir,file)
self.rexx = FpdbRegex.FpdbRegex()
def __str__(self): def __str__(self):
tmp = "HandHistoryConverter: '%s'\n" % (self.sitename) tmp = "HandHistoryConverter: '%s'\n" % (self.sitename)
@ -95,6 +97,13 @@ class HandHistoryConverter:
return return
self.readFile(self.file) self.readFile(self.file)
self.gametype = self.determineGameType() self.gametype = self.determineGameType()
self.splitFileIntoHands()
def splitFileIntoHands(self):
hands = []
list = self.rexx.split_hand_re.split(self.obs)
for l in list:
hands = hands + [Hand(l)]
def readFile(self, filename): def readFile(self, filename):
"""Read file""" """Read file"""
@ -110,7 +119,7 @@ class HandHistoryConverter:
except: except:
traceback.print_exc(file=sys.stderr) traceback.print_exc(file=sys.stderr)
def writeStars(self): def writeHand(self, file, hand):
"""Write out parsed data""" """Write out parsed data"""
# print sitename + " Game #" + handid + ": " + gametype + " (" + sb + "/" + bb + " - " + starttime # print sitename + " Game #" + handid + ": " + gametype + " (" + sb + "/" + bb + " - " + starttime
# print "Table '" + tablename + "' " + maxseats + "-max Seat #" + buttonpos + " is the button" # print "Table '" + tablename + "' " + maxseats + "-max Seat #" + buttonpos + " is the button"
@ -148,3 +157,23 @@ class HandHistoryConverter:
result*=100 result*=100
return result return result
#end def float2int #end def float2int
class Hand:
# def __init__(self, sitename, gametype, sb, bb, string):
def __init__(self, string):
# self.sitename = sitename
# self.gametype = gametype
# self.sb = sb
# self.bb = bb
self.string = string
print string
self.handid = None
self.tablename = "Slartibartfast"
self.maxseats = 10
self.counted_seats = 0
self.buttonpos = 0
self.seating = []
self.players = []
self.action = []

View File

@ -41,23 +41,22 @@ from time import time
class Importer: class Importer:
def __init__(self, caller, settings): def __init__(self, caller, settings, config):
"""Constructor""" """Constructor"""
self.settings=settings self.settings=settings
self.caller=caller self.caller=caller
self.config = config
self.db = None self.db = None
self.cursor = None self.cursor = None
self.filelist = {} self.filelist = {}
self.dirlist = {} self.dirlist = {}
self.monitor = False self.monitor = False
self.updated = {} #Time last import was run {file:mtime} self.updated = {} #Time last import was run {file:mtime}
self.callHud = False
self.lines = None self.lines = None
self.faobs = None #File as one big string self.faobs = None #File as one big string
self.pos_in_file = {} # dict to remember how far we have read in the file self.pos_in_file = {} # dict to remember how far we have read in the file
#Set defaults #Set defaults
if not self.settings.has_key('imp-callFpdbHud'): self.callHud = self.config.get_import_parameters().get("callFpdbHud")
self.settings['imp-callFpdbHud'] = False
if not self.settings.has_key('minPrint'): if not self.settings.has_key('minPrint'):
self.settings['minPrint'] = 30 self.settings['minPrint'] = 30
self.dbConnect() self.dbConnect()
@ -237,8 +236,7 @@ class Importer:
stored+=1 stored+=1
self.db.commit() self.db.commit()
# if settings['imp-callFpdbHud'] and self.callHud and os.sep=='/': if self.callHud:
if self.settings['imp-callFpdbHud'] and self.callHud:
#print "call to HUD here. handsId:",handsId #print "call to HUD here. handsId:",handsId
#pipe the Hands.id out to the HUD #pipe the Hands.id out to the HUD
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep) self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)