Absolute: a couple of cleanups and some prep work for AP

I've changed re_GameInfo to be a verbose regex, so I may have broken working hand histories.

No test files at the moment so it is hard to tell.
This commit is contained in:
Worros 2010-09-03 11:49:41 +08:00
parent 3f0cdfbaa5
commit d5f230e4e8

View File

@ -23,6 +23,18 @@ import sys
import logging import logging
from HandHistoryConverter import * from HandHistoryConverter import *
import locale
lang=locale.getdefaultlocale()[0][0:2]
if lang=="en":
def _(string): return string
else:
import gettext
try:
trans = gettext.translation("fpdb", localedir="locale", languages=[lang])
trans.install()
except IOError:
def _(string): return string
# Class for converting Absolute HH format. # Class for converting Absolute HH format.
class Absolute(HandHistoryConverter): class Absolute(HandHistoryConverter):
@ -42,7 +54,13 @@ class Absolute(HandHistoryConverter):
#Seat 6 - FETS63 ($0.75 in chips) #Seat 6 - FETS63 ($0.75 in chips)
#Board [10s 5d Kh Qh 8c] #Board [10s 5d Kh Qh 8c]
re_GameInfo = re.compile(ur"^Stage #(C?[0-9]+): (?P<GAME>Holdem|HORSE)(?: \(1 on 1\)|)? ?(?P<LIMIT>No Limit|Pot Limit|Normal|)? ?(?P<CURRENCY>\$| €|)(?P<SB>[.0-9]+)/?(?:\$| €|)(?P<BB>[.0-9]+)?", re.MULTILINE) re_GameInfo = re.compile(ur"""^Stage #(C?[0-9]+):\s+
(?P<GAME>Holdem|Seven\sCard\sHi\/L|HORSE)
(?:\s\(1\son\s1\)|)?\s+?
(?P<LIMIT>No Limit|Pot\sLimit|Normal|)?\s?
(?P<CURRENCY>\$|\s|)
(?P<SB>[.0-9]+)/?(?:\$|\s|)(?P<BB>[.0-9]+)?
""", re.MULTILINE|re.VERBOSE)
re_HorseGameInfo = re.compile(ur"^Game Type: (?P<LIMIT>Limit) (?P<GAME>Holdem)", re.MULTILINE) re_HorseGameInfo = re.compile(ur"^Game Type: (?P<LIMIT>Limit) (?P<GAME>Holdem)", re.MULTILINE)
# TODO: can set max seats via (1 on 1) to a known 2 .. # TODO: can set max seats via (1 on 1) to a known 2 ..
re_HandInfo = re.compile(ur"^Stage #C?(?P<HID>[0-9]+): .*(?P<DATETIME>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d).*\n(Table: (?P<TABLE>.*) \(Real Money\))?", re.MULTILINE) re_HandInfo = re.compile(ur"^Stage #C?(?P<HID>[0-9]+): .*(?P<DATETIME>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d).*\n(Table: (?P<TABLE>.*) \(Real Money\))?", re.MULTILINE)
@ -50,12 +68,6 @@ class Absolute(HandHistoryConverter):
re_Button = re.compile(ur"Seat #(?P<BUTTON>[0-9]) is the ?[dead]* dealer$", re.MULTILINE) # TODO: that's not the right way to match for "dead" dealer is it? re_Button = re.compile(ur"Seat #(?P<BUTTON>[0-9]) is the ?[dead]* dealer$", re.MULTILINE) # TODO: that's not the right way to match for "dead" dealer is it?
re_PlayerInfo = re.compile(ur"^Seat (?P<SEAT>[0-9]) - (?P<PNAME>.*) \((?:\$| €|)(?P<CASH>[0-9]*[.0-9]+) in chips\)", re.MULTILINE) re_PlayerInfo = re.compile(ur"^Seat (?P<SEAT>[0-9]) - (?P<PNAME>.*) \((?:\$| €|)(?P<CASH>[0-9]*[.0-9]+) in chips\)", re.MULTILINE)
re_Board = re.compile(ur"\[(?P<CARDS>[^\]]*)\]? *$", re.MULTILINE) re_Board = re.compile(ur"\[(?P<CARDS>[^\]]*)\]? *$", re.MULTILINE)
# re_GameInfo = re.compile(ur"^(Blinds )?(?P<CURRENCY>\$| €|)(?P<SB>[.0-9]+)/(?:\$| €)?(?P<BB>[.0-9]+) (?P<LIMIT>NL|PL|) ?(?P<GAME>(Holdem|Omaha|7 Card Stud))", re.MULTILINE)
#re.compile(ur"^(Blinds )?(?P<CURRENCY>\$| €|)(?P<SB>[.0-9]+)/(?:\$| €)?(?P<BB>[.0-9]+) (?P<LIMIT>NL|PL|) (?P<GAME>(Hold\'em|Omaha|7 Card Stud))", re.MULTILINE)
# re_HandInfo = re.compile(ur".*#(?P<HID>[0-9]+)\n.*\n(Blinds )?(?:\$| €|)(?P<SB>[.0-9]+)/(?:\$| €|)(?P<BB>[.0-9]+) (?P<GAMETYPE>.*) - (?P<DATETIME>\d\d\d\d/\d\d/\d\d - \d\d:\d\d:\d\d)\nTable (?P<TABLE>.+$)", re.MULTILINE)
# re_Button = re.compile(ur"^Seat (?P<BUTTON>\d+) is the button", re.MULTILINE)
# re_PlayerInfo = re.compile(ur"^Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\s+((?:\$| €|) (?P<CASH>[.0-9]+) (USD|EUR|)|new player|All-in) \)", re.MULTILINE)
# re_Board = re.compile(ur"\[ (?P<CARDS>.+) \]")
def compilePlayerRegexs(self, hand): def compilePlayerRegexs(self, hand):
@ -112,7 +124,11 @@ class Absolute(HandHistoryConverter):
m = self.re_GameInfo.search(handText) m = self.re_GameInfo.search(handText)
if not m: if not m:
return None tmp = handText[0:100]
log.error(_("determineGameType: Unable to recognise gametype from: '%s'") % tmp)
log.error(_("determineGameType: Raising FpdbParseError"))
raise FpdbParseError(_("Unable to recognise gametype from: '%s'") % tmp)
mg = m.groupdict() mg = m.groupdict()
@ -122,6 +138,7 @@ class Absolute(HandHistoryConverter):
"Holdem" : ('hold','holdem'), "Holdem" : ('hold','holdem'),
'Omaha' : ('hold','omahahi'), 'Omaha' : ('hold','omahahi'),
'Razz' : ('stud','razz'), 'Razz' : ('stud','razz'),
'Seven Card Hi/L' : ('stud','studhilo'),
'7 Card Stud' : ('stud','studhi') '7 Card Stud' : ('stud','studhi')
} }
currencies = { u'':'EUR', '$':'USD', '':'T$' } currencies = { u'':'EUR', '$':'USD', '':'T$' }