Merge branch 'master' of git://git.assembla.com/fpdb-sql

This commit is contained in:
Worros 2010-08-05 12:03:54 +08:00
commit c8006dc468
3 changed files with 129 additions and 19 deletions

View File

@ -673,6 +673,37 @@ Left-Drag to Move"
<hhc site="Carbon" converter="CarbonToFpdb"/>
</hhcs>
<!-- attribute names chosen to be in alphabetic order so that order can be set when retrieved -->
<gui_cash_stats>
<col col_name="game" col_title="Game" disp_all="True" disp_posn="True" field_format="%s" field_type="str" xalignment="0.0"/>
<col col_name="hand" col_title="Hand" disp_all="False" disp_posn="False" field_format="%s" field_type="str" xalignment="0.0"/>
<col col_name="plposition" col_title="Posn" disp_all="False" disp_posn="False" field_format="%s" field_type="str" xalignment="1.0"/>
<col col_name="pname" col_title="Name" disp_all="False" disp_posn="False" field_format="%s" field_type="str" xalignment="0.0"/>
<col col_name="n" col_title="Hds" disp_all="True" disp_posn="True" field_format="%1.0f" field_type="str" xalignment="1.0"/>
<col col_name="avgseats" col_title="Seats" disp_all="False" disp_posn="False" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="vpip" col_title="VPIP" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="pfr" col_title="PFR" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="pf3" col_title="PF3" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="aggfac" col_title="AggFac" disp_all="True" disp_posn="True" field_format="%2.2f" field_type="str" xalignment="1.0"/>
<col col_name="aggfrq" col_title="AggFreq" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="conbet" col_title="ContBet" disp_all="False" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="rfi" col_title="RFI" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="steals" col_title="Steals" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="saw_f" col_title="Saw_F" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="sawsd" col_title="SawSD" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="wtsdwsf" col_title="WtSDwsF" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="wmsd" col_title="W$SD" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="flafq" col_title="FlAFq" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="tuafq" col_title="TuAFq" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="rvafq" col_title="RvAFq" disp_all="True" disp_posn="True" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="pofafq" col_title="PoFAFq" disp_all="False" disp_posn="False" field_format="%3.1f" field_type="str" xalignment="1.0"/>
<col col_name="net" col_title="Net($)" disp_all="True" disp_posn="True" field_format="%6.2f" field_type="cash" xalignment="1.0"/>
<col col_name="bbper100" col_title="bb/100" disp_all="True" disp_posn="True" field_format="%4.2f" field_type="str" xalignment="1.0"/>
<col col_name="rake" col_title="Rake($)" disp_all="True" disp_posn="True" field_format="%6.2f" field_type="cash" xalignment="1.0"/>
<col col_name="bb100xr" col_title="bbxr/100" disp_all="True" disp_posn="True" field_format="%4.2f" field_type="str" xalignment="1.0"/>
<col col_name="variance" col_title="Variance" disp_all="True" disp_posn="True" field_format="%5.2f" field_type="str" xalignment="1.0"/>
</gui_cash_stats>
<supported_databases>
<!-- <database db_name="fpdb" db_server="mysql" db_ip="localhost" db_user="fpdb" db_pass="YOUR MYSQL PASSWORD"></database> -->
<database db_ip="localhost" db_server="sqlite" db_name="fpdb.db3" db_user="fpdb" db_pass="fpdb"/>

View File

@ -1397,6 +1397,7 @@ class Sql:
sum(hc.foldToStreet4CBChance) AS f_cb_opp_4,
sum(hc.foldToStreet4CBDone) AS f_cb_4,
sum(hc.totalProfit) AS net,
sum(gt.bigblind) AS bigblind,
sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1,
sum(hc.street1CheckCallRaiseDone) AS ccr_1,
sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2,
@ -1425,6 +1426,7 @@ class Sql:
INNER JOIN HudCache hc ON ( hc.PlayerId = hp.PlayerId+0
AND hc.gametypeId+0 = h.gametypeId+0)
INNER JOIN Players p ON (p.id = hp.PlayerId+0)
INNER JOIN Gametypes gt ON (gt.id = hc.gametypeId)
WHERE h.id = %s
AND hc.styleKey > %s
/* styleKey is currently 'd' (for date) followed by a yyyymmdd
@ -1496,6 +1498,7 @@ class Sql:
sum(hc.foldToStreet4CBChance) AS f_cb_opp_4,
sum(hc.foldToStreet4CBDone) AS f_cb_4,
sum(hc.totalProfit) AS net,
sum(gt.bigblind) AS bigblind,
sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1,
sum(hc.street1CheckCallRaiseDone) AS ccr_1,
sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2,
@ -1523,6 +1526,7 @@ class Sql:
INNER JOIN HandsPlayers hp ON (hp.handId = h.id)
INNER JOIN HudCache hc ON (hc.playerId = hp.playerId)
INNER JOIN Players p ON (p.id = hc.playerId)
INNER JOIN Gametypes gt ON (gt.id = hc.gametypeId)
WHERE h.id = %s
AND ( /* 2 separate parts for hero and opponents */
( hp.playerId != %s
@ -1622,6 +1626,7 @@ class Sql:
cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
cast(hp2.totalProfit as <signed>integer) AS net,
cast(gt.bigblind as <signed>integer) AS bigblind,
cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
@ -1651,6 +1656,7 @@ class Sql:
INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */
INNER JOIN HandsPlayers hp2 ON (hp2.playerId+0 = hp.playerId+0 AND (hp2.handId = h2.id+0)) /* other hands by these players */
INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
WHERE hp.handId = %s
/* check activeseats once this data returned (don't want to do that here as it might
assume a session ended just because the number of seats dipped for a few hands)
@ -1724,6 +1730,7 @@ class Sql:
cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
cast(hp2.totalProfit as <signed>integer) AS net,
cast(gt.bigblind as <signed>integer) AS bigblind,
cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
@ -1754,6 +1761,7 @@ class Sql:
INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0
AND hp2.handId = h2.id) /* other hands by these players */
INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
WHERE h.id = %s
/* check activeseats once this data returned (don't want to do that here as it might
assume a session ended just because the number of seats dipped for a few hands)
@ -1827,6 +1835,7 @@ class Sql:
cast(hp2.foldToStreet4CBChance as <signed>integer) AS f_cb_opp_4,
cast(hp2.foldToStreet4CBDone as <signed>integer) AS f_cb_4,
cast(hp2.totalProfit as <signed>integer) AS net,
cast(gt.bigblind as <signed>integer) AS bigblind,
cast(hp2.street1CheckCallRaiseChance as <signed>integer) AS ccr_opp_1,
cast(hp2.street1CheckCallRaiseDone as <signed>integer) AS ccr_1,
cast(hp2.street2CheckCallRaiseChance as <signed>integer) AS ccr_opp_2,
@ -1857,6 +1866,7 @@ class Sql:
INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0
AND hp2.handId = h2.id) /* other hands by these players */
INNER JOIN Players p ON (p.id = hp2.PlayerId+0)
INNER JOIN Gametypes gt ON (gt.id = h2.gametypeId)
WHERE h.id = %s
/* check activeseats once this data returned (don't want to do that here as it might
assume a session ended just because the number of seats dipped for a few hands)

View File

@ -48,7 +48,7 @@
# 6 For each stat you make add a line to the __main__ function to test it.
# Standard Library modules
#import sys
import sys
# pyGTK modules
import pygtk
@ -60,6 +60,10 @@ import Configuration
import Database
import Charset
import logging
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
log = logging.getLogger("db")
re_Places = re.compile("_[0-9]$")
re_Percent = re.compile("%$")
@ -79,12 +83,23 @@ def do_stat(stat_dict, player = 24, stat = 'vpip'):
else:
base = stat[0:-2]
places = int(stat[-1:])
result = eval("%(stat)s(stat_dict, %(player)d)" % {'stat': base, 'player': player})
result = (0.0, '0.0', 'notset=0', 'notset=0', '0', 'not set')
try:
result = eval("%(stat)s(stat_dict, %(player)d)" % {'stat': base, 'player': player})
except:
pass #
log.info("exception getting stat "+base+" for player "+str(player)+str(sys.exc_info()))
log.debug("result = %s" % str(result) )
match = re_Percent.search(result[1])
if match is None:
result = (result[0], "%.*f" % (places, result[0]), result[2], result[3], result[4], result[5])
else:
result = (result[0], "%.*f%%" % (places, 100*result[0]), result[2], result[3], result[4], result[5])
try:
if match is None:
result = (result[0], "%.*f" % (places, result[0]), result[2], result[3], result[4], result[5])
else:
result = (result[0], "%.*f%%" % (places, 100*result[0]), result[2], result[3], result[4], result[5])
except:
log.info( "error: %s" % str(sys.exc_info()))
raise
return result
# OK, for reference the tuple returned by the stat is:
@ -198,7 +213,7 @@ def wmsd(stat_dict, player):
)
def profit100(stat_dict, player):
""" Profit won per 100 hands (no decimal places)."""
""" Profit won per 100 hands."""
stat = 0.0
try:
stat = float(stat_dict[player]['net'])/float(stat_dict[player]['n'])
@ -212,13 +227,57 @@ def profit100(stat_dict, player):
except:
print "exception calcing p/100: 100 * %d / %d" % (stat_dict[player]['net'], stat_dict[player]['n'])
return (stat,
'%.0f' % (0),
'p=%.0f' % (0),
'p/100=%.0f' % (0),
'%.0f' % (0.0),
'p=%.0f' % (0.0),
'p/100=%.0f' % (0.0),
'(%d/%d)' % (0, 0),
'profit/100hands'
)
def bbper100(stat_dict, player):
""" big blinds won per 100 hands."""
stat = 0.0
try:
stat = 100.0 * float(stat_dict[player]['net']) / float(stat_dict[player]['bigblind'])
return (stat,
'%5.3f' % (stat),
'bb100=%5.3f' % (stat),
'bb100=%5.3f' % (stat),
'(%d,%d)' % (100*stat_dict[player]['net'],stat_dict[player]['bigblind']),
'big blinds/100 hands'
)
except:
log.info("exception calcing bb/100: "+str(stat_dict[player]))
return (stat,
'%.0f' % (0),
'bb100=%.0f' % (0),
'bb100=%.0f' % (0),
'(%f)' % (0),
'big blinds/100 hands'
)
def BBper100(stat_dict, player):
""" Big Bets won per 100 hands."""
stat = 0.0
try:
stat = 50 * float(stat_dict[player]['net']) / float(stat_dict[player]['bigblind'])
return (stat,
'%5.3f' % (stat),
'BB100=%5.3f' % (stat),
'BB100=%5.3f' % (stat),
'(%d,%d)' % (100*stat_dict[player]['net'],2*stat_dict[player]['bigblind']),
'Big Bets/100 hands'
)
except:
log.info("exception calcing BB/100: "+str(stat_dict[player]))
return (stat,
'%.0f' % (0.0),
'BB100=%.0f' % (0.0),
'BB100=%.0f' % (0.0),
'(%f)' % (0.0),
'Big Bets/100 hands'
)
def saw_f(stat_dict, player):
""" Saw flop/4th."""
try:
@ -782,13 +841,27 @@ def ffreq4(stat_dict, player):
)
if __name__== "__main__":
statlist = dir()
misslist = [ "Configuration", "Database", "Charset", "codecs", "encoder"
, "do_stat", "do_tip", "GInitiallyUnowned", "gtk", "pygtk"
, "re", "re_Percent", "re_Places"
]
statlist = [ x for x in statlist if x not in dir(sys) ]
statlist = [ x for x in statlist if x not in dir(codecs) ]
statlist = [ x for x in statlist if x not in misslist ]
#print "statlist is", statlist
c = Configuration.Config()
#TODO: restore the below code. somehow it creates a version 119 DB but commenting this out makes it print a stat list
#db_connection = Database.Database(c)
#h = db_connection.get_last_hand()
#stat_dict = db_connection.get_stats_from_hand(h, "ring")
db_connection = Database.Database(c)
h = db_connection.get_last_hand()
stat_dict = db_connection.get_stats_from_hand(h, "ring")
#for player in stat_dict.keys():
for player in stat_dict.keys():
print "Example stats, player =", player, "hand =", h, ":"
for attr in statlist:
print " ", do_stat(stat_dict, player=player, stat=attr)
break
#print "player = ", player, do_stat(stat_dict, player = player, stat = 'vpip')
#print "player = ", player, do_stat(stat_dict, player = player, stat = 'pfr')
#print "player = ", player, do_stat(stat_dict, player = player, stat = 'wtsd')
@ -820,11 +893,7 @@ if __name__== "__main__":
print "\n\nLegal stats:"
print "(add _0 to name to display with 0 decimal places, _1 to display with 1, etc)\n"
for attr in dir():
if attr.startswith('__'): continue
if attr in ("Configuration", "Database", "GInitiallyUnowned", "gtk", "pygtk",
"player", "c", "db_connection", "do_stat", "do_tip", "stat_dict",
"h", "re", "re_Percent", "re_Places"): continue
for attr in statlist:
print "%-14s %s" % (attr, eval("%s.__doc__" % (attr)))
# print " <pu_stat pu_stat_name = \"%s\"> </pu_stat>" % (attr)
print