Merge branch 'master' of git://git.assembla.com/fpdboz

This commit is contained in:
sqlcoder 2009-12-22 16:51:20 +00:00
commit 7f7d56c4c7
12 changed files with 104 additions and 27 deletions

View File

@ -16,6 +16,25 @@
#agpl-3.0.txt in the docs folder of the package.
# From fpdb_simple
card_map = { "0": 0, "2": 2, "3" : 3, "4" : 4, "5" : 5, "6" : 6, "7" : 7, "8" : 8,
"9" : 9, "T" : 10, "J" : 11, "Q" : 12, "K" : 13, "A" : 14}
# FIXME: the following is a workaround until switching to newimport.
# This should be moved into DerivedStats
# I'd also like to change HandsPlayers.startCards to a different datatype
# so we can 'trivially' add different start card classifications
def calcStartCards(hand, player):
if hand.gametype['category'] == 'holdem':
hcs = hand.join_holecards(player, asList=True)
#print "DEBUG: hcs: %s" % hcs
value1 = card_map[hcs[0][0]]
value2 = card_map[hcs[1][0]]
return twoStartCards(value1, hcs[0][1], value2, hcs[1][1])
else:
# FIXME: Only do startCards value for holdem at the moment
return 0
def twoStartCards(value1, suit1, value2, suit2):

View File

@ -1651,7 +1651,8 @@ class Database:
pdata[p]['street2CheckCallRaiseDone'],
pdata[p]['street3CheckCallRaiseChance'],
pdata[p]['street3CheckCallRaiseDone'],
pdata[p]['street4CheckCallRaiseChance']
pdata[p]['street4CheckCallRaiseChance'],
pdata[p]['street4CheckCallRaiseDone']
) )
q = self.sql.query['store_hands_players']

View File

@ -47,6 +47,7 @@ class DerivedStats():
self.handsplayers[player[1]]['wonWhenSeenStreet1'] = 0.0
self.handsplayers[player[1]]['sawShowdown'] = False
self.handsplayers[player[1]]['wonAtSD'] = 0.0
self.handsplayers[player[1]]['startCards'] = 0
for i in range(5):
self.handsplayers[player[1]]['street%dCalls' % i] = 0
self.handsplayers[player[1]]['street%dBets' % i] = 0
@ -57,7 +58,6 @@ class DerivedStats():
#FIXME - Everything below this point is incomplete.
self.handsplayers[player[1]]['position'] = 2
self.handsplayers[player[1]]['tourneyTypeId'] = 1
self.handsplayers[player[1]]['startCards'] = 0
self.handsplayers[player[1]]['street0_3BChance'] = False
self.handsplayers[player[1]]['street0_3BDone'] = False
self.handsplayers[player[1]]['stealAttemptChance'] = False
@ -168,9 +168,11 @@ class DerivedStats():
for player in hand.players:
hcs = hand.join_holecards(player[1], asList=True)
hcs = hcs + [u'0x', u'0x', u'0x', u'0x', u'0x']
for i, card in enumerate(hcs[:7], 1):
self.handsplayers[player[1]]['card%s' % i] = Card.encodeCard(card)
#for i, card in enumerate(hcs[:7], 1): #Python 2.6 syntax
# self.handsplayers[player[1]]['card%s' % i] = Card.encodeCard(card)
for i, card in enumerate(hcs[:7]):
self.handsplayers[player[1]]['card%s' % (i+1)] = Card.encodeCard(card)
self.handsplayers[player[1]]['startCards'] = Card.calcStartCards(hand, player[1])
# position,
#Stud 3rd street card test
@ -266,13 +268,17 @@ class DerivedStats():
# Then no bets before the player with initiatives first action on current street
# ie. if player on street-1 had initiative
# and no donkbets occurred
for i, street in enumerate(hand.actionStreets[2:], start=1):
name = self.lastBetOrRaiser(hand.actionStreets[i])
# XXX: enumerate(list, start=x) is python 2.6 syntax; 'start'
# came there
#for i, street in enumerate(hand.actionStreets[2:], start=1):
for i, street in enumerate(hand.actionStreets[2:]):
name = self.lastBetOrRaiser(hand.actionStreets[i+1])
if name:
chance = self.noBetsBefore(hand.actionStreets[i+1], name)
self.handsplayers[name]['street%dCBChance' %i] = True
chance = self.noBetsBefore(hand.actionStreets[i+2], name)
self.handsplayers[name]['street%dCBChance' % (i+1)] = True
if chance == True:
self.handsplayers[name]['street%dCBDone' %i] = self.betStreet(hand.actionStreets[i+1], name)
self.handsplayers[name]['street%dCBDone' % (i+1)] = self.betStreet(hand.actionStreets[i+2], name)
def seen(self, hand, i):
pas = set()

View File

@ -326,6 +326,8 @@ def main(argv=None):
help="How often to print a one-line status report (0 (default) means never)")
parser.add_option("-u", "--usage", action="store_true", dest="usage", default=False,
help="Print some useful one liners")
parser.add_option("-s", "--starsarchive", action="store_true", dest="starsArchive", default=False,
help="Do the required conversion for Stars Archive format (ie. as provided by support")
(options, argv) = parser.parse_args(args = argv)
if options.usage == True:
@ -369,6 +371,8 @@ def main(argv=None):
importer.setThreads(-1)
importer.addBulkImportImportFileOrDir(os.path.expanduser(options.filename), site=options.filtername)
importer.setCallHud(False)
if options.starsArchive:
importer.setStarsArchive(True)
(stored, dups, partial, errs, ttime) = importer.runImport()
importer.clearFileList()
print 'GuiBulkImport done: Stored: %d \tDuplicates: %d \tPartial: %d \tErrors: %d in %s seconds - %.0f/sec'\

View File

@ -54,6 +54,7 @@ class Hand(object):
self.starttime = 0
self.handText = handText
self.handid = 0
self.cancelled = False
self.dbid_hands = 0
self.dbid_pids = None
self.dbid_gt = 0
@ -263,6 +264,9 @@ If a player has None chips he won't be added."""
log.debug("markStreets:\n"+ str(self.streets))
else:
log.error("markstreets didn't match")
log.error(" - Assuming hand cancelled")
self.cancelled = True
raise FpdbParseError
def checkPlayerExists(self,player):
if player not in [p[1] for p in self.players]:
@ -613,6 +617,8 @@ class HoldemOmahaHand(Hand):
hhc.readPlayerStacks(self)
hhc.compilePlayerRegexs(self)
hhc.markStreets(self)
if self.cancelled:
return
hhc.readBlinds(self)
hhc.readAntes(self)
hhc.readButton(self)

View File

@ -57,7 +57,7 @@ class HandHistoryConverter():
codepage = "cp1252"
def __init__(self, in_path = '-', out_path = '-', follow=False, index=0, autostart=True):
def __init__(self, in_path = '-', out_path = '-', follow=False, index=0, autostart=True, starsArchive=False):
"""\
in_path (default '-' = sys.stdin)
out_path (default '-' = sys.stdout)
@ -66,6 +66,7 @@ follow : whether to tail -f the input"""
log.info("HandHistory init - %s subclass, in_path '%s'; out_path '%s'" % (self.sitename, in_path, out_path) )
self.index = 0
self.starsArchive = starsArchive
self.in_path = in_path
self.out_path = out_path
@ -254,6 +255,11 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py.
self.readFile()
self.obs = self.obs.strip()
self.obs = self.obs.replace('\r\n', '\n')
if self.starsArchive == True:
log.debug("Converting starsArchive format to readable")
m = re.compile('^Hand #\d+', re.MULTILINE)
self.obs = m.sub('', self.obs)
if self.obs is None or self.obs == "":
log.info("Read no hands.")
return []

View File

@ -89,6 +89,7 @@ class PartyPoker(HandHistoryConverter):
(?P<TTYPE>[a-zA-Z0-9 ]+)\s+
(?: \#|\(|)(?P<TABLE>\d+)\)?\s+
(?:[^ ]+\s+\#(?P<MTTTABLE>\d+).+)? # table number for mtt
(\(No\sDP\)\s)?
\((?P<PLAY>Real|Play)\s+Money\)\s+ # FIXME: check if play money is correct
Seat\s+(?P<BUTTON>\d+)\sis\sthe\sbutton
""",

View File

@ -203,6 +203,8 @@ class PokerStars(HandHistoryConverter):
if key == 'TOURNO':
hand.tourNo = info[key]
if key == 'BUYIN':
#FIXME: The key looks like: '€0.82+€0.18 EUR'
# This should be parsed properly and used
hand.buyin = info[key]
if key == 'LEVEL':
hand.level = info[key]

View File

@ -3404,10 +3404,11 @@ class Sql:
street2CheckCallRaiseDone,
street3CheckCallRaiseChance,
street3CheckCallRaiseDone,
street4CheckCallRaiseChance
street4CheckCallRaiseChance,
street4CheckCallRaiseDone
)
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,

View File

@ -91,6 +91,7 @@ class Importer:
self.settings.setdefault("writeQMaxWait", 10) # not used
self.settings.setdefault("dropIndexes", "don't drop")
self.settings.setdefault("dropHudCache", "don't drop")
self.settings.setdefault("starsArchive", False)
self.writeq = None
self.database = Database.Database(self.config, sql = self.sql)
@ -134,6 +135,9 @@ class Importer:
def setDropHudCache(self, value):
self.settings['dropHudCache'] = value
def setStarsArchive(self, value):
self.settings['starsArchive'] = value
# def setWatchTime(self):
# self.updated = time()
@ -425,25 +429,31 @@ class Importer:
mod = __import__(filter)
obj = getattr(mod, filter_name, None)
if callable(obj):
hhc = obj(in_path = file, out_path = out_path, index = 0) # Index into file 0 until changeover
hhc = obj(in_path = file, out_path = out_path, index = 0, starsArchive = self.settings['starsArchive']) # Index into file 0 until changeover
if hhc.getStatus() and self.NEWIMPORT == False:
(stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(db, out_path, site, q)
elif hhc.getStatus() and self.NEWIMPORT == True:
#This code doesn't do anything yet
handlist = hhc.getProcessedHands()
self.pos_in_file[file] = hhc.getLastCharacterRead()
to_hud = []
for hand in handlist:
#try, except duplicates here?
hand.prepInsert(self.database)
hand.insert(self.database)
if self.callHud and hand.dbid_hands != 0:
#print "DEBUG: call to HUD: handsId: %s" % hand.dbid_hands
#pipe the Hands.id out to the HUD
print "fpdb_import: sending hand to hud", hand.dbid_hands, "pipe =", self.caller.pipe_to_hud
self.caller.pipe_to_hud.stdin.write("%s" % (hand.dbid_hands) + os.linesep)
if hand is not None:
#try, except duplicates here?
hand.prepInsert(self.database)
hand.insert(self.database)
if self.callHud and hand.dbid_hands != 0:
to_hud.append(hand.dbid_hands)
else:
log.error("Hand processed but empty")
self.database.commit()
#pipe the Hands.id out to the HUD
for hid in to_hud:
print "fpdb_import: sending hand to hud", hand.dbid_hands, "pipe =", self.caller.pipe_to_hud
self.caller.pipe_to_hud.stdin.write("%s" % (hid) + os.linesep)
errors = getattr(hhc, 'numErrors')
stored = getattr(hhc, 'numHands')
else:

View File

@ -1,4 +1,5 @@
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
#Copyright 2008 Steffen Jobbagy-Felso
#This program is free software: you can redistribute it and/or modify
@ -538,7 +539,11 @@ def parseAnteLine(line, isTourney, names, antes):
#returns the buyin of a tourney in cents
def parseBuyin(topline):
pos1 = topline.find("$")+1
pos2 = topline.find("+")
if pos1 != 0:
pos2 = topline.find("+")
else:
pos1 = topline.find("")+3
pos2 = topline.find("+")
return float2int(topline[pos1:pos2])
#parses a card line and changes the passed arrays accordingly
@ -635,9 +640,14 @@ def parseCashesAndSeatNos(lines):
#returns the buyin of a tourney in cents
def parseFee(topline):
pos1=topline.find("$")+1
pos1=topline.find("$",pos1)+1
pos2=topline.find(" ", pos1)
pos1 = topline.find("$")+1
if pos1 != 0:
pos1 = topline.find("$", pos1)+1
pos2 = topline.find(" ", pos1)
else:
pos1 = topline.find("")+3
pos1 = topline.find("", pos1)+3
pos2 = topline.find(" ", pos1)
return float2int(topline[pos1:pos2])
#returns a datetime object with the starttime indicated in the given topline

View File

@ -0,0 +1,11 @@
PokerStars Game #25979907808: Omaha Pot Limit ($0.05/$0.10 USD) - 2009/03/15 6:20:33 ET
Table 'Waterman' 6-max Seat #1 is the button
Seat 1: s0rrow ($11.65 in chips)
s0rrow: posts small blind $0.05
ritalinIV: is sitting out
Hand cancelled
*** SUMMARY ***
Seat 1: s0rrow (button) collected ($0)