Work on plugin initialisation, add Carbon poker plugin

This commit is contained in:
Worros 2008-11-09 09:49:05 +10:00
parent 4f64464df3
commit 7df572895b
3 changed files with 138 additions and 5 deletions

75
pyfpdb/CarbonToFpdb.py Normal file
View File

@ -0,0 +1,75 @@
#!/usr/bin/env python
# Copyright 2008, 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
########################################################################
# Standard Library modules
import Configuration
import traceback
import xml.dom.minidom
from xml.dom.minidom import Node
from HandHistoryConverter import HandHistoryConverter
# Carbon format looks like:
# 1) <description type="Holdem" stakes="No Limit ($0.25/$0.50)"/>
# 2) <game id="14902583-5578" starttime="20081006145401" numholecards="2" gametype="2" realmoney="true" data="20081006|Niagara Falls (14902583)|14902583|14902583-5578|false">
# 3) <players dealer="8">
# <player seat="3" nickname="PlayerInSeat3" balance="$43.29" dealtin="true" />
# ...
# 4) <round id="BLINDS" sequence="1">
# <event sequence="1" type="SMALL_BLIND" player="0" amount="0.25"/>
# <event sequence="2" type="BIG_BLIND" player="1" amount="0.50"/>
# 5) <round id="PREFLOP" sequence="2">
# <event sequence="3" type="CALL" player="2" amount="0.50"/>
# 6) <round id="POSTFLOP" sequence="3">
# <event sequence="16" type="BET" player="3" amount="1.00"/>
# ....
# <cards type="COMMUNITY" cards="7d,Jd,Jh"/>
# The full sequence for a NHLE cash game is:
# BLINDS, PREFLOP, POSTFLOP, POSTTURN, POSTRIVER, SHOWDOWN, END_OF_GAME
# This sequence can be terminated after BLINDS at any time by END_OF_FOLDED_GAME
class CarbonPoker(HandHistoryConverter):
def __init__(self, config, filename):
print "Initialising Carbon Poker converter class"
HandHistoryConverter.__init__(self, config, filename) # Call super class init
self.sitename = "Carbon"
self.setFileType("xml")
def readSupportedGames(self):
pass
def determineGameType(self):
desc_node = doc.getElementsByTagName("description")
type = desc_node.getAttribute("type")
stakes = desc_node.getAttribute("stakes")
def readPlayerStacks(self):
pass
def readBlinds(self):
pass
def readAction(self):
pass
if __name__ == "__main__":
c = Configuration.Config()
e = CarbonPoker(c, "regression-test-files/carbon-poker/Niagara Falls (15245216).xml")
print str(e)

View File

@ -16,11 +16,16 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
######################################################################## ########################################################################
import Configuration
from HandHistoryConverter import HandHistoryConverter from HandHistoryConverter import HandHistoryConverter
class Everleaf(HandHistoryConverter): class Everleaf(HandHistoryConverter):
def __init__(self): def __init__(self, config, file):
print "Initialising Everleaf converter class" print "Initialising Everleaf converter class"
HandHistoryConverter.__init__(self, config, file) # Call super class init.
self.sitename = "Everleaf"
self.setFileType("text")
def readSupportedGames(self): def readSupportedGames(self):
pass pass
@ -37,4 +42,7 @@ class Everleaf(HandHistoryConverter):
pass pass
if __name__ == "__main__": if __name__ == "__main__":
e = Everleaf() c = Configuration.Config()
e = Everleaf(c, "regression-test-files/everleaf/Speed_Kuala.txt")
print str(e)

View File

@ -16,8 +16,22 @@
#agpl-3.0.txt in the docs folder of the package. #agpl-3.0.txt in the docs folder of the package.
class HandHistoryConverter: class HandHistoryConverter:
def __init__(self): def __init__(self, config, file):
pass print "HandHistory init called"
self.c = config
self.sitename = ""
self.obs = "" # One big string
self.filetype = "text"
self.doc = None # For XML based HH files
self.file = file
self.hhbase = self.c.get_import_parameters().get("hhArchiveBase")
def __str__(self):
tmp = "HandHistoryConverter: '%s'\n" % (self.sitename)
tmp = tmp + "\thhbase: %s\n" % (self.hhbase)
tmp = tmp + "\tfiletype: %s\n" % (self.filetype)
return tmp
# Functions to be implemented in the inheriting class # Functions to be implemented in the inheriting class
def readSupportedGames(self): abstract def readSupportedGames(self): abstract
def determineGameType(self): abstract def determineGameType(self): abstract
@ -25,11 +39,47 @@ class HandHistoryConverter:
def readBlinds(self): abstract def readBlinds(self): abstract
def readAction(self): abstract def readAction(self): abstract
# Functions not necessary to implement in sub class # Functions not necessary to implement in sub class
def setFileType(self, filetype = "text"):
self.filetype = filetype
def processFile(self):
self.readFile()
def readFile(self, filename): def readFile(self, filename):
"""Read file""" """Read file"""
if(self.filetype == "text"):
infile=open(filename, "rU")
self.obs = readfile(inputFile)
inputFile.close()
elif(self.filetype == "xml"):
try:
doc = xml.dom.minidom.parse(filename)
self.doc = doc
except:
traceback.print_exc(file=sys.stderr)
def writeStars(self): def writeStars(self):
"""Write out parsed data""" """Write out parsed data"""
# print sitename + " Game #" + handid + ": " + gametype + " (" + sb + "/" + bb + " - " + starttime
# print "Table '" + tablename + "' " + maxseats + "-max Seat #" + buttonpos + " is the button"
#
# counter = 1
# for player in seating:
# print "Seat " + counter + ": " + playername + "($" + playermoney + " in chips"
#
# print playername + ": posts small blind " + sb
# print playername + ": posts big blind " + bb
#
# print "*** HOLE CARDS ***"
# print "Dealt to " + hero + " [" + holecards + "]"
#
## ACTION STUFF
#
# print "*** SUMMARY ***"
# print "Total pot $" + totalpot + " | Rake $" + rake
# print "Board [" + boardcards + "]"
#
## SUMMARY STUFF