2010-12-31 00:49:39 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""RushNotesAux.py
|
|
|
|
|
|
|
|
EXPERIMENTAL - USE WITH CARE
|
|
|
|
|
|
|
|
Auxilliary process to push HUD data into the FullTilt player notes XML
|
|
|
|
This will allow a rudimentary "HUD" in rush games
|
|
|
|
|
|
|
|
The existing notes file will be altered by this function
|
|
|
|
"""
|
|
|
|
# Copyright 2010, "Gimick" of the FPDB project fpdb.sourceforge.net
|
|
|
|
#
|
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU Affero General Public License as published by
|
|
|
|
#the Free Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
#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 Affero General Public License
|
|
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#In the "official" distribution you can find the license in agpl-3.0.txt.
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
|
2011-01-09 00:28:41 +01:00
|
|
|
##########for each hand processed, attempts to create update for player notes in FullTilt
|
2010-12-31 00:49:39 +01:00
|
|
|
##########based upon the AW howto notes written by Ray E. Barker (nutomatic) at fpdb.sourceforge.net
|
2011-01-09 00:28:41 +01:00
|
|
|
##########Huge thanks to Ray for his guidance and encouragement to create this !!
|
2010-12-31 00:49:39 +01:00
|
|
|
|
2011-01-09 00:28:41 +01:00
|
|
|
#
|
2010-12-31 00:49:39 +01:00
|
|
|
#debugmode will write logfiles for the __init__ and update_data methods
|
2011-01-09 00:28:41 +01:00
|
|
|
# writes into ./pyfpdb/~Rushdebug.*
|
|
|
|
#
|
2011-01-05 23:35:42 +01:00
|
|
|
debugmode = False
|
2010-12-31 00:49:39 +01:00
|
|
|
|
|
|
|
# Standard Library modules
|
|
|
|
import os
|
2011-01-01 19:53:53 +01:00
|
|
|
import sys
|
2010-12-31 00:49:39 +01:00
|
|
|
from xml.dom import minidom
|
|
|
|
from datetime import datetime
|
|
|
|
from time import *
|
|
|
|
|
|
|
|
# FreePokerDatabase modules
|
|
|
|
from Mucked import Aux_Window
|
|
|
|
from Mucked import Seat_Window
|
|
|
|
from Mucked import Aux_Seats
|
|
|
|
import Stats
|
2011-01-09 00:28:41 +01:00
|
|
|
import Card
|
2010-12-31 00:49:39 +01:00
|
|
|
|
2011-01-01 19:53:53 +01:00
|
|
|
#
|
2011-01-09 00:28:41 +01:00
|
|
|
# overload minidom methods to fix bug where \n is parsed as " ".
|
2011-01-01 19:53:53 +01:00
|
|
|
# described here: http://bugs.python.org/issue7139
|
|
|
|
#
|
|
|
|
|
|
|
|
def _write_data(writer, data, isAttrib=False):
|
|
|
|
"Writes datachars to writer."
|
|
|
|
if isAttrib:
|
|
|
|
data = data.replace("\r", "
").replace("\n", "
")
|
|
|
|
data = data.replace("\t", "	")
|
|
|
|
writer.write(data)
|
|
|
|
minidom._write_data = _write_data
|
|
|
|
|
|
|
|
def writexml(self, writer, indent="", addindent="", newl=""):
|
|
|
|
# indent = current indentation
|
|
|
|
# addindent = indentation to add to higher levels
|
|
|
|
# newl = newline string
|
|
|
|
writer.write(indent+"<" + self.tagName)
|
|
|
|
|
|
|
|
attrs = self._get_attributes()
|
|
|
|
a_names = attrs.keys()
|
|
|
|
a_names.sort()
|
|
|
|
|
|
|
|
for a_name in a_names:
|
|
|
|
writer.write(" %s=\"" % a_name)
|
|
|
|
_write_data(writer, attrs[a_name].value, isAttrib=True)
|
|
|
|
writer.write("\"")
|
|
|
|
if self.childNodes:
|
|
|
|
writer.write(">%s"%(newl))
|
|
|
|
for node in self.childNodes:
|
|
|
|
node.writexml(writer,indent+addindent,addindent,newl)
|
|
|
|
writer.write("%s</%s>%s" % (indent,self.tagName,newl))
|
|
|
|
else:
|
|
|
|
writer.write("/>%s"%(newl))
|
|
|
|
# For an introduction to overriding instance methods, see
|
|
|
|
# http://irrepupavel.com/documents/python/instancemethod/
|
|
|
|
instancemethod = type(minidom.Element.writexml)
|
|
|
|
minidom.Element.writexml = instancemethod(
|
|
|
|
writexml, None, minidom.Element)
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
class RushNotes(Aux_Window):
|
|
|
|
|
|
|
|
def __init__(self, hud, config, params):
|
|
|
|
|
|
|
|
self.hud = hud
|
|
|
|
self.config = config
|
|
|
|
|
|
|
|
#
|
|
|
|
# following line makes all the site params magically available (thanks Ray!)
|
|
|
|
#
|
|
|
|
site_params_dict = self.hud.config.get_site_parameters(self.hud.site)
|
|
|
|
|
|
|
|
heroname = site_params_dict['screen_name']
|
|
|
|
sitename = site_params_dict['site_name']
|
|
|
|
notepath = site_params_dict['site_path'] # this is a temporary hijack of site-path
|
|
|
|
self.heroid = self.hud.db_connection.get_player_id(self.config, sitename, heroname)
|
|
|
|
self.notefile = notepath + "/" + heroname + ".xml"
|
2011-01-09 00:28:41 +01:00
|
|
|
self.rushtables = ("Mach 10", "Lightning", "Celerity", "Flash", "Zoom")
|
|
|
|
|
2011-01-01 19:53:53 +01:00
|
|
|
if not os.path.isfile(self.notefile):
|
|
|
|
self.active = False
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
self.active = True
|
2010-12-31 00:49:39 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# read in existing notefile and backup with date/time in name
|
|
|
|
# todo change to not use dom
|
|
|
|
#
|
|
|
|
now = datetime.now()
|
|
|
|
notefilebackup = self.notefile + ".backup." + now.strftime("%Y%m%d%H%M%S")
|
|
|
|
xmlnotefile = minidom.parse(self.notefile)
|
|
|
|
outputfile = open(notefilebackup, 'w')
|
|
|
|
xmlnotefile.writexml(outputfile)
|
|
|
|
outputfile.close()
|
|
|
|
xmlnotefile.unlink
|
|
|
|
|
2011-01-09 00:28:41 +01:00
|
|
|
#
|
2010-12-31 00:49:39 +01:00
|
|
|
# Create a fresh queue file with skeleton XML
|
2011-01-09 00:28:41 +01:00
|
|
|
#
|
2010-12-31 00:49:39 +01:00
|
|
|
self.queuefile = self.notefile + ".queue"
|
2011-01-09 00:28:41 +01:00
|
|
|
queuedom = minidom.Document()
|
2010-12-31 00:49:39 +01:00
|
|
|
|
|
|
|
pld=queuedom.createElement("PLAYERDATA")
|
|
|
|
queuedom.appendChild(pld)
|
|
|
|
|
|
|
|
nts=queuedom.createElement("NOTES")
|
|
|
|
pld.appendChild(nts)
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
nte = queuedom.createElement("NOTE")
|
|
|
|
nte = queuedom.createTextNode("\n")
|
2011-01-09 00:28:41 +01:00
|
|
|
nts.insertBefore(nte,None)
|
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
outputfile = open(self.queuefile, 'w')
|
|
|
|
queuedom.writexml(outputfile)
|
|
|
|
outputfile.close()
|
|
|
|
queuedom.unlink
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
if (debugmode):
|
|
|
|
#initialise logfiles
|
|
|
|
debugfile=open("~Rushdebug.init", "w")
|
|
|
|
debugfile.write("conf="+str(config)+"\n")
|
|
|
|
debugfile.write("spdi="+str(site_params_dict)+"\n")
|
|
|
|
debugfile.write("para="+str(params)+"\n")
|
|
|
|
debugfile.write("hero="+heroname+" "+str(self.heroid)+"\n")
|
|
|
|
debugfile.write("back="+notefilebackup+"\n")
|
2011-01-09 00:28:41 +01:00
|
|
|
debugfile.write("queu="+self.queuefile+"\n")
|
2010-12-31 00:49:39 +01:00
|
|
|
debugfile.close()
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
open("~Rushdebug.data", "w").close()
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
|
|
|
|
def update_data(self, new_hand_id, db_connection):
|
|
|
|
#this method called once for every hand processed
|
|
|
|
# self.hud.stat_dict contains the stats information for this hand
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2011-01-01 19:53:53 +01:00
|
|
|
if not self.active:
|
|
|
|
return
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
if (debugmode):
|
|
|
|
debugfile=open("~Rushdebug.data", "a")
|
|
|
|
debugfile.write(new_hand_id+"\n")
|
|
|
|
now = datetime.now()
|
|
|
|
debugfile.write(now.strftime("%Y%m%d%H%M%S")+ " update_data begins"+ "\n")
|
|
|
|
debugfile.write("hero="+str(self.heroid)+"\n")
|
|
|
|
#debugfile.write(str(self.hud.stat_dict)+"\n")
|
2011-01-09 00:28:41 +01:00
|
|
|
debugfile.write("table="+self.hud.table.name+"\n")
|
|
|
|
debugfile.write("players="+str(self.hud.stat_dict.keys())+"\n")
|
|
|
|
debugfile.write("db="+str(db_connection)+"\n")
|
2010-12-31 00:49:39 +01:00
|
|
|
|
2011-01-09 00:28:41 +01:00
|
|
|
if self.hud.table.name not in self.rushtables:
|
2010-12-31 00:49:39 +01:00
|
|
|
return
|
|
|
|
#
|
|
|
|
# Grab a list of player id's
|
|
|
|
#
|
|
|
|
handplayers = self.hud.stat_dict.keys()
|
|
|
|
|
|
|
|
#
|
|
|
|
# build a dictionary of stats text for each player in the hand (excluding the hero)
|
|
|
|
# xmlqueuedict contains {playername : stats text}
|
|
|
|
#
|
|
|
|
xmlqueuedict = {}
|
|
|
|
for playerid in handplayers:
|
|
|
|
# ignore hero, no notes available for hero at Full Tilt
|
|
|
|
if playerid == self.heroid: continue
|
|
|
|
|
|
|
|
playername=unicode(str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'playername')[1]))
|
|
|
|
# Use index[3] which is a short description
|
|
|
|
n=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'n')[3] + " ")
|
|
|
|
vpip=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'vpip')[3] + " ")
|
|
|
|
pfr=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'pfr')[3] + " ")
|
|
|
|
three_B=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'three_B')[3] + " ")
|
|
|
|
cbet=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'cbet')[3] + " ")
|
2011-01-01 19:53:53 +01:00
|
|
|
fbbsteal=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'f_BB_steal')[3] + " ")
|
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
steal=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'steal')[3] + " ")
|
|
|
|
ffreq1=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'ffreq1')[3] + " ")
|
|
|
|
agg_freq=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'agg_freq')[3] + " ")
|
2011-01-05 23:35:42 +01:00
|
|
|
BBper100=str(Stats.do_stat(self.hud.stat_dict, player = playerid, stat = 'BBper100')[3])
|
|
|
|
if BBper100[6] == "-": BBper100=BBper100[0:6] + "(" + BBper100[7:] + ")"
|
2011-01-09 00:28:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# grab villain known starting hands
|
|
|
|
# only those where they VPIP'd, so limp in the BB will not be shown
|
|
|
|
# sort by hand strength. Output will show position too,
|
|
|
|
# so KK.1 is KK from late posn etc.
|
|
|
|
# ignore non-rush hands (check against known rushtablenames)
|
|
|
|
# cards decoding is hard-coded for holdem, so that's tuff atm
|
|
|
|
# three categories of known hands are shown:
|
|
|
|
# agression preflop hands
|
|
|
|
# non-aggression preflop hands
|
|
|
|
# bigblind called to defend hands
|
|
|
|
#
|
|
|
|
# This isn't perfect, but it isn't too bad a starting point
|
|
|
|
#
|
|
|
|
|
|
|
|
PFcall="PFcall"
|
|
|
|
PFaggr="PFaggr"
|
|
|
|
PFdefend="PFdefend"
|
|
|
|
|
|
|
|
c = db_connection.get_cursor()
|
|
|
|
c.execute(("SELECT handId, position, startCards, street0Aggr, tableName " +
|
|
|
|
"FROM hands, handsPlayers " +
|
|
|
|
"WHERE handsplayers.handId = hands.id " +
|
|
|
|
"AND street0VPI = 1 " +
|
|
|
|
"AND startCards > 0 " +
|
|
|
|
"AND playerId = %d " +
|
|
|
|
"ORDER BY startCards DESC " +
|
|
|
|
";")
|
|
|
|
% int(playerid))
|
|
|
|
|
|
|
|
for (qid, qposition, qstartcards, qstreet0Aggr, qtablename) in c.fetchall():
|
|
|
|
if (debugmode):
|
|
|
|
debugfile.write("pid, hid, pos, cards, aggr, table player"+
|
|
|
|
str(playerid)+"/"+str(qid)+"/"+str(qposition)+"/"+
|
|
|
|
str(qstartcards)+"/"+str(qstreet0Aggr)+"/"+
|
|
|
|
str(qtablename)+"/"+str(playername)+
|
|
|
|
"\n")
|
|
|
|
|
|
|
|
humancards = Card.decodeStartHandValue("holdem", qstartcards)
|
|
|
|
|
|
|
|
if qtablename not in self.rushtables:
|
|
|
|
pass
|
|
|
|
elif qposition == "B" and qstreet0Aggr == False:
|
|
|
|
PFdefend=PFdefend+"/"+humancards
|
|
|
|
elif qstreet0Aggr == True:
|
|
|
|
PFaggr=PFaggr+"/"+humancards+"."+qposition
|
|
|
|
else:
|
|
|
|
PFcall=PFcall+"/"+humancards+"."+qposition
|
|
|
|
c.close
|
|
|
|
|
|
|
|
#
|
|
|
|
# build up final text package (top/tail with ~fpdb~ ~ends~
|
|
|
|
# for later search/replace by Merge module
|
|
|
|
#
|
|
|
|
xmlqueuedict[playername] = ("~fpdb~" + "\n" +
|
|
|
|
n + vpip + pfr + three_B + fbbsteal + "\n" +
|
|
|
|
steal + cbet + ffreq1 + "\n" +
|
|
|
|
agg_freq + BBper100 + "\n" +
|
|
|
|
PFcall+"\n"+PFaggr+"\n"+PFdefend +"\n"
|
2011-01-05 23:35:42 +01:00
|
|
|
"~ends~")
|
2011-01-01 19:53:53 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
if (debugmode):
|
|
|
|
now = datetime.now()
|
|
|
|
debugfile.write(now.strftime("%Y%m%d%H%M%S")+" villain data has been processed" + "\n")
|
|
|
|
debugfile.write(str(xmlqueuedict)+"\n")
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
#
|
|
|
|
# delaying processing of xml until now. Grab current queuefile contents and
|
|
|
|
# read each existing NOTE element in turn, if matched to a player in xmlqueuedict
|
|
|
|
# update their text in the xml and delete the dictionary item
|
|
|
|
#
|
|
|
|
xmlnotefile = minidom.parse(self.queuefile)
|
|
|
|
notelist = xmlnotefile.getElementsByTagName('NOTE')
|
|
|
|
|
|
|
|
for noteentry in notelist: #for each note in turn
|
|
|
|
noteplayer = noteentry.getAttribute("PlayerId") #extract the playername from xml
|
|
|
|
if noteplayer in xmlqueuedict: # does that player exist in the queue?
|
|
|
|
noteentry.setAttribute("Text",xmlqueuedict[noteplayer])
|
|
|
|
del xmlqueuedict[noteplayer] #remove from list, does not need to be added later on
|
|
|
|
|
|
|
|
#
|
|
|
|
#create entries for new players (those remaining in the dictionary)
|
|
|
|
#
|
|
|
|
if len(xmlqueuedict) > 0:
|
|
|
|
playerdata=xmlnotefile.lastChild #move to the PLAYERDATA node (assume last one in the list)
|
|
|
|
notesnode=playerdata.childNodes[0] #Find NOTES node
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
for newplayer in xmlqueuedict:
|
|
|
|
newentry = xmlnotefile.createElement("NOTE")
|
|
|
|
newentry.setAttribute("PlayerId", newplayer)
|
2011-01-09 00:28:41 +01:00
|
|
|
newentry.setAttribute("Text", xmlqueuedict[newplayer])
|
2010-12-31 00:49:39 +01:00
|
|
|
notesnode.insertBefore(newentry,None)
|
|
|
|
newentry = xmlnotefile.createTextNode("\n")
|
|
|
|
notesnode.insertBefore(newentry,None)
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
if (debugmode):
|
|
|
|
now = datetime.now()
|
|
|
|
debugfile.write(now.strftime("%Y%m%d%H%M%S")+" xml pre-processing complete"+ "\n")
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
#
|
|
|
|
# OverWrite existing xml file with updated DOM and cleanup
|
|
|
|
#
|
|
|
|
updatednotes = open(self.queuefile, 'w')
|
|
|
|
xmlnotefile.writexml(updatednotes)
|
|
|
|
updatednotes.close()
|
2011-01-09 00:28:41 +01:00
|
|
|
|
2010-12-31 00:49:39 +01:00
|
|
|
xmlnotefile.unlink
|
|
|
|
|
|
|
|
if (debugmode):
|
|
|
|
now = datetime.now()
|
|
|
|
debugfile.write(now.strftime("%Y%m%d%H%M%S")+" dom written, process finished"+ "\n")
|
|
|
|
debugfile.close()
|
2011-01-01 19:53:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|