From a7f71137050b590fbe9345f20dbce5f9e2f0f553 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 13 Mar 2009 18:45:15 +0900 Subject: [PATCH 01/13] Make determineGameType return 'tour' of currency is T$ --- pyfpdb/EverleafToFpdb.py | 6 ++---- pyfpdb/test_Everleaf.py | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index 8f411770..41c3c4ff 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -130,12 +130,10 @@ or None if we fail to get the info """ info['bb'] = mg['BB'] if 'CURRENCY' in mg: info['currency'] = currencies[mg['CURRENCY']] + if info['currency'] == 'T$': + info['type'] = 'tour' # NB: SB, BB must be interpreted as blinds or bets depending on limit type. - if not self.debugging and info['base']=='stud': - logging.warning("Not processing Everleaf Stud hand") - #return None - return info diff --git a/pyfpdb/test_Everleaf.py b/pyfpdb/test_Everleaf.py index 6adfc495..9f557159 100644 --- a/pyfpdb/test_Everleaf.py +++ b/pyfpdb/test_Everleaf.py @@ -31,7 +31,7 @@ Blinds 10/20 NL Hold'em - 2009/02/25 - 17:30:32 Table 2 Seat 1 is the button Total number of players: 10""", - {'type':'ring', 'base':"hold", 'category':'holdem', 'limitType':'nl', 'sb':'10', 'bb':'20', 'currency':'T$'}), + {'type':'tour', 'base':"hold", 'category':'holdem', 'limitType':'nl', 'sb':'10', 'bb':'20', 'currency':'T$'}), ("""Everleaf Gaming Game #65087798 ***** Hand history for game #65087798 ***** @@ -43,7 +43,7 @@ Table Plymouth""", ***** Hand history for game #65295370 ***** Blinds $0.50/$1 PL Omaha - 2008/12/07 - 21:59:48 Table Guanajuato""", - {'type':'ring', 'base':'hold', 'category':'omahahi', 'limitType':'pl', 'sb':'0.50', 'bb':'1','currency':'USD'}) + {'type':'ring', 'base':'hold', 'category':'omahahi', 'limitType':'pl', 'sb':'0.50', 'bb':'1','currency':'USD'}), ) for (header, info) in pairs: From f4e3c8de2800a31d2e6407ee517ab50838d9b932 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 14 Mar 2009 02:51:10 +0900 Subject: [PATCH 02/13] Remove lookupLimitBetSize() - appears to no longer be necessary --- pyfpdb/Hand.py | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index d91450be..5728e4a2 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -29,6 +29,7 @@ from Exceptions import * class Hand: UPS = {'a':'A', 't':'T', 'j':'J', 'q':'Q', 'k':'K', 'S':'s', 'C':'c', 'H':'h', 'D':'d'} + LCS = {'H':'h', 'D':'d', 'C':'c', 'S':'s'} def __init__(self, sitename, gametype, handText): self.sitename = sitename self.gametype = gametype @@ -316,32 +317,6 @@ Map the tuple self.gametype onto the pokerstars string describing it return retstring - def lookupLimitBetSize(self): - #Lookup table for limit games - betlist = { - "Everleaf" : { "0.10" : ("0.02", "0.05"), - "0.20" : ("0.05", "0.10"), - "0.50" : ("0.10", "0.25"), - "1" : ("0.25", "0.50"), - "2" : ("0.50", "1.00"), - "4" : ("1.00", "2.00"), - "6" : ("1.00", "3.00") - }, - "FullTilt" : { "0.10" : ("0.02", "0.05"), - "0.20" : ("0.05", "0.10"), - "1" : ("0.25", "0.50"), - "2" : ("0.50", "1"), - "4" : ("1", "2") - } - } - try: - ret = betlist[self.sitename][self.bb] - except: - logging.warning("Don't know the small blind/big blind size for %s, big bet size %s." % (self.sitename, self.bb)) - ret = (Decimal(self.sb)/2,Decimal(self.bb)/2) - - return ret - def writeHand(self, fh=sys.__stdout__): print >>fh, "Override me" @@ -449,23 +424,6 @@ Card ranks will be uppercased #Only print stacks of players who do something preflop print >>fh, _("Seat %s: %s ($%s in chips) " %(player[0], player[1], player[2])) - - #May be more than 1 bb posting - if self.gametype['limitType'] == "fl": - (smallbet, bigbet) = self.lookupLimitBetSize() - else: - smallbet = self.sb - bigbet = self.bb - -# for a in self.posted: -# if(a[1] == "small blind"): -# print >>fh, _("%s: posts small blind $%s" %(a[0], smallbet)) -# if(a[1] == "big blind"): -# print >>fh, _("%s: posts big blind $%s" %(a[0], bigbet)) -# if(a[1] == "both"): -# print >>fh, _("%s: posts small & big blinds $%.2f" %(a[0], (Decimal(smallbet) + Decimal(bigbet)))) -# I think these can just be actions in 'blindsantes' round - if self.actions['BLINDSANTES']: for act in self.actions['BLINDSANTES']: self.printActionLine(act, fh) From 321e38a16f5b8accd011ae785cf1a9d1f3227831 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 14 Mar 2009 03:10:53 +0900 Subject: [PATCH 03/13] Move 'plugin loader' to Utils file so HUD and Importer can share --- pyfpdb/Hud.py | 14 +++----------- pyfpdb/Utils.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 pyfpdb/Utils.py diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 07396f61..3df3781a 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -43,16 +43,8 @@ import Configuration import Stats import Mucked import Database -import HUD_main - -def importName(module_name, name): - """Import a named object 'name' from module 'module_name'.""" -# Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!! - try: - module = __import__(module_name, globals(), locals(), [name]) - except: - return None - return(getattr(module, name)) +import HUD_main +import Utils class Hud: @@ -88,7 +80,7 @@ class Hud: if not game_params['aux'] == [""]: for aux in game_params['aux']: aux_params = config.get_aux_parameters(aux) - my_import = importName(aux_params['module'], aux_params['class']) + my_import = Utils.importName(aux_params['module'], aux_params['class']) if my_import == None: continue self.aux_windows.append(my_import(self, config, aux_params)) diff --git a/pyfpdb/Utils.py b/pyfpdb/Utils.py new file mode 100644 index 00000000..f7827451 --- /dev/null +++ b/pyfpdb/Utils.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2009, Carl Gherardi +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +######################################################################## + +def importName(module_name, name): + """Import a named object 'name' from module 'module_name'.""" +# Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!! + try: + module = __import__(module_name, globals(), locals(), [name]) + except: + return None + return(getattr(module, name)) + From 875f2183793c7d47cf9c59b05a66b9900bb9de2a Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 14 Mar 2009 04:23:36 +0900 Subject: [PATCH 04/13] Move it back again, found another way --- pyfpdb/Hud.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 3df3781a..c9e0ea07 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -46,6 +46,16 @@ import Database import HUD_main import Utils +def importName(module_name, name, params): + """Import a named object 'name' from module 'module_name'.""" +# Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!! +# Modded by Carl G to support additional params + try: + module = __import__(module_name, globals(), locals(), [name]) + except: + return None + return(getattr(module, name)) + class Hud: def __init__(self, parent, table, max, poker_game, config, db_connection): @@ -80,7 +90,7 @@ class Hud: if not game_params['aux'] == [""]: for aux in game_params['aux']: aux_params = config.get_aux_parameters(aux) - my_import = Utils.importName(aux_params['module'], aux_params['class']) + my_import = importName(aux_params['module'], aux_params['class']) if my_import == None: continue self.aux_windows.append(my_import(self, config, aux_params)) From 6ebab0698135c15ac60d40359e3a8c84013ad2d9 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 14 Mar 2009 05:00:12 +0900 Subject: [PATCH 05/13] Make converters dynamically loadable in autoimport Adds 1 restriction to the HHC sub classes, the classname must be the same as the filename - ToFpdb.py FulltiltToFpdb.py must contain a hhc class named Fulltilt EverleafToFpdb.py must contain a hhc class named Everleaf --- pyfpdb/EverleafToFpdb.py | 1 + pyfpdb/FulltiltToFpdb.py | 10 +++++----- pyfpdb/Utils.py | 29 ----------------------------- pyfpdb/fpdb_import.py | 27 +++++++++++++-------------- 4 files changed, 19 insertions(+), 48 deletions(-) delete mode 100644 pyfpdb/Utils.py diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index 41c3c4ff..d5deeeb8 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -43,6 +43,7 @@ out_path (default '-' = sys.stdout) follow : whether to tail -f the input autostart: whether to run the thread (or you can call start() yourself) debugging: if False, pass on partially supported game types. If true, have a go and error...""" + print "DEBUG: XXXXXXXXXXXXXXX" HandHistoryConverter.__init__(self, in_path, out_path, sitename="Everleaf", follow=follow) logging.info("Initialising Everleaf converter class") self.filetype = "text" diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index 4455961a..fb2bf6ea 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -22,9 +22,9 @@ import sys import logging from HandHistoryConverter import * -# FullTilt HH Format converter +# Fulltilt HH Format converter -class FullTilt(HandHistoryConverter): +class Fulltilt(HandHistoryConverter): # Static regexes re_GameInfo = re.compile('- (?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+) (Ante \$(?P[.0-9]+) )?- (?P(No Limit|Pot Limit|Limit))? (?P(Hold\'em|Omaha Hi|Razz))') @@ -39,8 +39,8 @@ class FullTilt(HandHistoryConverter): in_path (default '-' = sys.stdin) out_path (default '-' = sys.stdout) follow : whether to tail -f the input""" - HandHistoryConverter.__init__(self, in_path, out_path, sitename="FullTilt", follow=follow) - logging.info("Initialising FullTilt converter class") + HandHistoryConverter.__init__(self, in_path, out_path, sitename="Fulltilt", follow=follow) + logging.info("Initialising Fulltilt converter class") self.filetype = "text" self.codepage = "cp1252" if autostart: @@ -314,4 +314,4 @@ if __name__ == "__main__": LOG_FILENAME = './logging.out' logging.basicConfig(filename=LOG_FILENAME,level=options.verbosity) - e = FullTilt(in_path = options.ipath, out_path = options.opath, follow = options.follow) + e = Fulltilt(in_path = options.ipath, out_path = options.opath, follow = options.follow) diff --git a/pyfpdb/Utils.py b/pyfpdb/Utils.py deleted file mode 100644 index f7827451..00000000 --- a/pyfpdb/Utils.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright 2009, Carl Gherardi -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -######################################################################## - -def importName(module_name, name): - """Import a named object 'name' from module 'module_name'.""" -# Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!! - try: - module = __import__(module_name, globals(), locals(), [name]) - except: - return None - return(getattr(module, name)) - diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 2b4a2d88..8c4bd0f9 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -33,8 +33,6 @@ import fpdb_simple import fpdb_db import fpdb_parse_logic import Configuration -import EverleafToFpdb -import FulltiltToFpdb # database interface modules try: @@ -238,21 +236,22 @@ class Importer: except: out_path = os.path.join(hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file)) - # someone can just create their own python module for it - if filter in ("EverleafToFpdb","Everleaf"): - conv = EverleafToFpdb.Everleaf(in_path = file, out_path = out_path) - elif filter == "FulltiltToFpdb": - conv = FulltiltToFpdb.FullTilt(in_path = file, out_path = out_path) + filter_name = filter.replace("ToFpdb", "") + + mod = __import__(filter) + obj = getattr(mod, filter_name, None) + if callable(obj): + conv = obj(in_path = file, out_path = out_path) + if(conv.getStatus()): + (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site) + else: + # conversion didn't work + # TODO: appropriate response? + return (0, 0, 0, 1, 0) else: - print "Unknown filter ", filter + print "Unknown filter filter_name:'%s' in filter:'%s'" %(filter_name, filter) return - if(conv.getStatus()): - (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site) - else: - # conversion didn't work - # TODO: appropriate response? - return (0, 0, 0, 1, 0) #This will barf if conv.getStatus != True return (stored, duplicates, partial, errors, ttime) From bbdbe7e47dd0bcb9457ec4856a5252097425382a Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 14 Mar 2009 05:10:13 +0900 Subject: [PATCH 06/13] Remove TODO for previous patch --- pyfpdb/fpdb_import.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 8c4bd0f9..ef0894e3 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -226,7 +226,6 @@ class Importer: conv = None # Load filter, process file, pass returned filename to import_fpdb_file - # TODO: Shouldn't we be able to use some sort of lambda or something to just call a Python object by whatever name we specify? then we don't have to hardcode them, print "converting %s" % file hhbase = self.config.get_import_parameters().get("hhArchiveBase") hhbase = os.path.expanduser(hhbase) From d3103f099e7a0abd982cb5e6f1e11f4eb46eac76 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 14 Mar 2009 06:42:20 +0900 Subject: [PATCH 07/13] Make Stars Badugi recognised --- pyfpdb/PokerStarsToFpdb.py | 5 +++-- pyfpdb/test_FullTilt.py | 2 +- pyfpdb/test_PokerStars.py | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 05027121..8c2e4884 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -69,7 +69,7 @@ from HandHistoryConverter import * class PokerStars(HandHistoryConverter): # Static regexes - re_GameInfo = re.compile('PokerStars Game #(?P[0-9]+):\s+(HORSE)? \(?(?PHold\'em|Razz|7 Card Stud|Omaha Hi/Lo) (?PNo Limit|Limit|Pot Limit),? \(?(?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+)\) - (?P.*$)', re.MULTILINE) + re_GameInfo = re.compile("PokerStars Game #(?P[0-9]+):\s+(HORSE)? \(?(?PHold\'em|Razz|7 Card Stud|Omaha Hi/Lo|Badugi) (?PNo Limit|Limit|Pot Limit),? \(?(?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+)\) - (?P.*$)", re.MULTILINE) re_SplitHands = re.compile('\n\n+') re_HandInfo = re.compile("^Table \'(?P[- a-zA-Z]+)\'(?P.+?$)?", re.MULTILINE) re_Button = re.compile('Seat #(?P