start changes to allow different hud choices for hero and opponents
This commit is contained in:
parent
3d301718ae
commit
ea74862a5a
|
@ -406,10 +406,19 @@ class Database:
|
||||||
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||||
print "***Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
print "***Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||||
|
|
||||||
def get_stats_from_hand(self, hand, aggregate = False, hud_style = 'A', agg_bb_mult = 100):
|
def get_stats_from_hand( self, hand
|
||||||
|
, hud_params = {'aggregate_tour':False, 'aggregate_ring':False, 'hud_style':'A', 'agg_bb_mult':100}
|
||||||
|
, hero_ids = {}
|
||||||
|
):
|
||||||
|
aggregate = hud_params['aggregate_tour'] if type == "tour" else hud_params['aggregate_ring']
|
||||||
|
hud_style = hud_params['hud_style']
|
||||||
|
agg_bb_mult = hud_params['agg_bb_mult']
|
||||||
|
stat_dict = {}
|
||||||
|
|
||||||
if hud_style == 'S':
|
if hud_style == 'S':
|
||||||
|
|
||||||
return( self.get_stats_from_hand_session(hand) )
|
self.get_stats_from_hand_session(hand, stat_dict)
|
||||||
|
return stat_dict
|
||||||
|
|
||||||
else: # hud_style == A
|
else: # hud_style == A
|
||||||
|
|
||||||
|
@ -433,7 +442,6 @@ class Database:
|
||||||
# now get the stats
|
# now get the stats
|
||||||
c.execute(self.sql.query[query], subs)
|
c.execute(self.sql.query[query], subs)
|
||||||
colnames = [desc[0] for desc in c.description]
|
colnames = [desc[0] for desc in c.description]
|
||||||
stat_dict = {}
|
|
||||||
for row in c.fetchall():
|
for row in c.fetchall():
|
||||||
t_dict = {}
|
t_dict = {}
|
||||||
for name, val in zip(colnames, row):
|
for name, val in zip(colnames, row):
|
||||||
|
@ -444,7 +452,7 @@ class Database:
|
||||||
return stat_dict
|
return stat_dict
|
||||||
|
|
||||||
# uses query on handsplayers instead of hudcache to get stats on just this session
|
# uses query on handsplayers instead of hudcache to get stats on just this session
|
||||||
def get_stats_from_hand_session(self, hand):
|
def get_stats_from_hand_session(self, hand, stat_dict):
|
||||||
|
|
||||||
query = self.sql.query['get_stats_from_hand_session']
|
query = self.sql.query['get_stats_from_hand_session']
|
||||||
if self.db_server == 'mysql':
|
if self.db_server == 'mysql':
|
||||||
|
@ -459,15 +467,13 @@ class Database:
|
||||||
#print "sess_stats: subs =", subs, "subs[0] =", subs[0]
|
#print "sess_stats: subs =", subs, "subs[0] =", subs[0]
|
||||||
c.execute(query, subs)
|
c.execute(query, subs)
|
||||||
colnames = [desc[0] for desc in c.description]
|
colnames = [desc[0] for desc in c.description]
|
||||||
n,stat_dict = 0,{}
|
n = 0
|
||||||
|
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
while row:
|
|
||||||
if colnames[0].lower() == 'player_id':
|
if colnames[0].lower() == 'player_id':
|
||||||
playerid = row[0]
|
playerid = row[0]
|
||||||
else:
|
|
||||||
log.error("ERROR: query %s result does not have player_id as first column" % (query,))
|
|
||||||
break
|
|
||||||
|
|
||||||
|
while row:
|
||||||
for name, val in zip(colnames, row):
|
for name, val in zip(colnames, row):
|
||||||
if not playerid in stat_dict:
|
if not playerid in stat_dict:
|
||||||
stat_dict[playerid] = {}
|
stat_dict[playerid] = {}
|
||||||
|
@ -477,13 +483,16 @@ class Database:
|
||||||
elif name.lower() not in ('hand_id', 'player_id', 'seat', 'screen_name', 'seats'):
|
elif name.lower() not in ('hand_id', 'player_id', 'seat', 'screen_name', 'seats'):
|
||||||
stat_dict[playerid][name.lower()] += val
|
stat_dict[playerid][name.lower()] += val
|
||||||
n += 1
|
n += 1
|
||||||
if n >= 4000: break # todo: don't think this is needed so set nice and high
|
if n >= 10000: break # todo: don't think this is needed so set nice and high
|
||||||
# for now - comment out or remove?
|
# for now - comment out or remove?
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
|
else:
|
||||||
|
log.error("ERROR: query %s result does not have player_id as first column" % (query,))
|
||||||
|
|
||||||
#print " %d rows fetched, len(stat_dict) = %d" % (n, len(stat_dict))
|
#print " %d rows fetched, len(stat_dict) = %d" % (n, len(stat_dict))
|
||||||
|
|
||||||
#print "session stat_dict =", stat_dict
|
#print "session stat_dict =", stat_dict
|
||||||
return stat_dict
|
#return stat_dict
|
||||||
|
|
||||||
def get_player_id(self, config, site, player_name):
|
def get_player_id(self, config, site, player_name):
|
||||||
c = self.connection.cursor()
|
c = self.connection.cursor()
|
||||||
|
|
|
@ -74,6 +74,22 @@ hud_session_gap = 30 # Gap (minutes) between hands that indicates a change of s
|
||||||
# a new session)
|
# a new session)
|
||||||
#hud_hands = 0 # Max number of hands from each player to use for hud stats (not used)
|
#hud_hands = 0 # Max number of hands from each player to use for hud stats (not used)
|
||||||
|
|
||||||
|
def_hud_params = { 'aggregate_ring' : False
|
||||||
|
, 'aggregate_tour' : False
|
||||||
|
, 'hud_style' : 'A'
|
||||||
|
, 'hud_days ' : 90
|
||||||
|
, 'agg_bb_mult' : 100
|
||||||
|
, 'hud_session_gap' : 30
|
||||||
|
# second set of variables for hero
|
||||||
|
, 'h_aggregate_ring' : False
|
||||||
|
, 'h_aggreagte_tour' : False
|
||||||
|
, 'h_hud_style' : 'A'
|
||||||
|
, 'h_hud_days ' : 90
|
||||||
|
, 'h_agg_bb_mult' : 100
|
||||||
|
, 'h_hud_session_gap' : 30
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class HUD_main(object):
|
class HUD_main(object):
|
||||||
"""A main() object to own both the read_stdin thread and the gui."""
|
"""A main() object to own both the read_stdin thread and the gui."""
|
||||||
# This class mainly provides state for controlling the multiple HUDs.
|
# This class mainly provides state for controlling the multiple HUDs.
|
||||||
|
@ -82,6 +98,7 @@ class HUD_main(object):
|
||||||
self.db_name = db_name
|
self.db_name = db_name
|
||||||
self.config = Configuration.Config(file=options.config, dbname=options.dbname)
|
self.config = Configuration.Config(file=options.config, dbname=options.dbname)
|
||||||
self.hud_dict = {}
|
self.hud_dict = {}
|
||||||
|
self.hud_params = def_hud_params
|
||||||
|
|
||||||
# a thread to read stdin
|
# a thread to read stdin
|
||||||
gobject.threads_init() # this is required
|
gobject.threads_init() # this is required
|
||||||
|
@ -164,10 +181,20 @@ class HUD_main(object):
|
||||||
# be passed to HUDs for use in the gui thread. HUD objects should not
|
# be passed to HUDs for use in the gui thread. HUD objects should not
|
||||||
# need their own access to the database, but should open their own
|
# need their own access to the database, but should open their own
|
||||||
# if it is required.
|
# if it is required.
|
||||||
|
try:
|
||||||
self.db_connection = Database.Database(self.config, self.db_name, 'temp')
|
self.db_connection = Database.Database(self.config, self.db_name, 'temp')
|
||||||
self.db_connection.init_hud_stat_vars(hud_days)
|
self.db_connection.init_hud_stat_vars(hud_days)
|
||||||
tourny_finder = re.compile('(\d+) (\d+)')
|
tourny_finder = re.compile('(\d+) (\d+)')
|
||||||
|
|
||||||
|
# get hero's screen names and player ids
|
||||||
|
self.hero, self.hero_ids = {}, {}
|
||||||
|
for site in self.config.get_supported_sites():
|
||||||
|
result = self.db_connection.get_site_id(site)
|
||||||
|
if result:
|
||||||
|
site_id = result[0][0]
|
||||||
|
self.hero[site_id] = self.config.supported_sites[site].screen_name
|
||||||
|
self.hero_ids[site_id] = self.db_connection.get_player_id(self.config, site, self.hero[site_id])
|
||||||
|
|
||||||
while 1: # wait for a new hand number on stdin
|
while 1: # wait for a new hand number on stdin
|
||||||
new_hand_id = sys.stdin.readline()
|
new_hand_id = sys.stdin.readline()
|
||||||
new_hand_id = string.rstrip(new_hand_id)
|
new_hand_id = string.rstrip(new_hand_id)
|
||||||
|
@ -177,9 +204,12 @@ class HUD_main(object):
|
||||||
# get basic info about the new hand from the db
|
# get basic info about the new hand from the db
|
||||||
# if there is a db error, complain, skip hand, and proceed
|
# if there is a db error, complain, skip hand, and proceed
|
||||||
try:
|
try:
|
||||||
(table_name, max, poker_game, type) = self.db_connection.get_table_name(new_hand_id)
|
(table_name, max, poker_game, type, site_id) = self.db_connection.get_table_name(new_hand_id)
|
||||||
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, aggregate_stats[type]
|
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, self.hud_params, self.hero_ids)
|
||||||
,hud_style, agg_bb_mult)
|
#self.hud_params['aggregate_tour'] if type = "tour"
|
||||||
|
# else self.hud_params['aggregate_ring'],
|
||||||
|
#hud_style,
|
||||||
|
#agg_bb_mult)
|
||||||
|
|
||||||
cards = self.db_connection.get_cards(new_hand_id)
|
cards = self.db_connection.get_cards(new_hand_id)
|
||||||
comm_cards = self.db_connection.get_common_cards(new_hand_id)
|
comm_cards = self.db_connection.get_common_cards(new_hand_id)
|
||||||
|
@ -226,6 +256,9 @@ class HUD_main(object):
|
||||||
else:
|
else:
|
||||||
self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, stat_dict, cards)
|
self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, stat_dict, cards)
|
||||||
self.db_connection.connection.rollback()
|
self.db_connection.connection.rollback()
|
||||||
|
except:
|
||||||
|
err = traceback.extract_tb(sys.exc_info()[2])[-1]
|
||||||
|
print "***Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
|
||||||
|
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ class Hud:
|
||||||
self.stacked = True
|
self.stacked = True
|
||||||
self.site = table.site
|
self.site = table.site
|
||||||
self.mw_created = False
|
self.mw_created = False
|
||||||
|
self.hud_params = parent.hud_params
|
||||||
|
|
||||||
self.stat_windows = {}
|
self.stat_windows = {}
|
||||||
self.popup_windows = {}
|
self.popup_windows = {}
|
||||||
|
@ -218,7 +219,11 @@ class Hud:
|
||||||
# heap dead, burnt bodies, blood 'n guts, veins between my teeth
|
# heap dead, burnt bodies, blood 'n guts, veins between my teeth
|
||||||
for s in self.stat_windows.itervalues():
|
for s in self.stat_windows.itervalues():
|
||||||
s.kill_popups()
|
s.kill_popups()
|
||||||
|
try:
|
||||||
|
# throws "invalid window handle" in WinXP (sometimes?)
|
||||||
s.window.destroy()
|
s.window.destroy()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
self.stat_windows = {}
|
self.stat_windows = {}
|
||||||
# also kill any aux windows
|
# also kill any aux windows
|
||||||
for aux in self.aux_windows:
|
for aux in self.aux_windows:
|
||||||
|
@ -623,6 +628,56 @@ class Popup_window:
|
||||||
# window.present()
|
# window.present()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class HUD_Params:
|
||||||
|
|
||||||
|
def __init__(self, hud):
|
||||||
|
self.aggregate_stats = hud.def_aggregate_stats
|
||||||
|
self.hud_style = hud.def_hud_style
|
||||||
|
self.hud_days = hud.def_hud_days
|
||||||
|
self.agg_bb_mult = hud.def_agg_bb_mult
|
||||||
|
self.hud_session_gap = hud.def_hud_session_gap
|
||||||
|
|
||||||
|
self.h_aggregate_stats = hud.def_h_aggregate_stats
|
||||||
|
self.h_hud_style = hud.def_h_hud_style
|
||||||
|
self.h_hud_days = hud.def_h_hud_days
|
||||||
|
self.h_agg_bb_mult = hud.def_h_agg_bb_mult
|
||||||
|
self.h_hud_session_gap = hud.def_h_hud_session_gap
|
||||||
|
|
||||||
|
def set_aggregate_stats(self, agg):
|
||||||
|
self.aggregate_stats = agg
|
||||||
|
def set_hud_style(self, style):
|
||||||
|
self.hud_style = style
|
||||||
|
def set_hud_days(self, days):
|
||||||
|
self.hud_days = days
|
||||||
|
def set_agg_bb_mult(self, mult):
|
||||||
|
self.agg_bb_mult = mult
|
||||||
|
def set_hud_session_gap(self, gap):
|
||||||
|
self.hud_session_gap = gap
|
||||||
|
|
||||||
|
def set_aggregate_stats(self, agg):
|
||||||
|
self.aggregate_stats = agg
|
||||||
|
def set_hud_style(self, style):
|
||||||
|
self.hud_style = style
|
||||||
|
def set_hud_days(self, days):
|
||||||
|
self.hud_days = days
|
||||||
|
def set_agg_bb_mult(self, mult):
|
||||||
|
self.agg_bb_mult = mult
|
||||||
|
def set_hud_session_gap(self, gap):
|
||||||
|
self.hud_session_gap = gap
|
||||||
|
|
||||||
|
def get_aggregate_stats(self):
|
||||||
|
return self.aggregate_stats
|
||||||
|
def get_hud_style(self):
|
||||||
|
return self.hud_style
|
||||||
|
def get_hud_days(self):
|
||||||
|
return self.hud_days
|
||||||
|
def get_agg_bb_mult(self):
|
||||||
|
return self.agg_bb_mult
|
||||||
|
def get_hud_session_gap(self):
|
||||||
|
return self.hud_session_gap
|
||||||
|
|
||||||
|
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
main_window = gtk.Window()
|
main_window = gtk.Window()
|
||||||
main_window.connect("destroy", destroy)
|
main_window.connect("destroy", destroy)
|
||||||
|
|
|
@ -1581,10 +1581,11 @@ class Sql:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.query['get_table_name'] = """
|
self.query['get_table_name'] = """
|
||||||
select tableName, maxSeats, category, type
|
select h.tableName, h.maxSeats, gt.category, gt.type, gt.siteId
|
||||||
from Hands,Gametypes
|
from Hands h
|
||||||
where Hands.id = %s
|
,Gametypes gt
|
||||||
and Gametypes.id = Hands.gametypeId
|
where h.id = %s
|
||||||
|
and gt.id = h.gametypeId
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.query['get_actual_seat'] = """
|
self.query['get_actual_seat'] = """
|
||||||
|
|
|
@ -248,7 +248,7 @@ class ttracker_main(object):
|
||||||
# get basic info about the new hand from the db
|
# get basic info about the new hand from the db
|
||||||
# if there is a db error, complain, skip hand, and proceed
|
# if there is a db error, complain, skip hand, and proceed
|
||||||
try:
|
try:
|
||||||
(table_name, max, poker_game, type) = self.db_connection.get_table_name(new_hand_id)
|
(table_name, max, poker_game, type, site_id) = self.db_connection.get_table_name(new_hand_id)
|
||||||
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, aggregate_stats[type]
|
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, aggregate_stats[type]
|
||||||
,hud_style, agg_bb_mult)
|
,hud_style, agg_bb_mult)
|
||||||
|
|
||||||
|
|
|
@ -549,7 +549,7 @@ class Importer:
|
||||||
if self.callHud:
|
if self.callHud:
|
||||||
#print "call to HUD here. handsId:",handsId
|
#print "call to HUD here. handsId:",handsId
|
||||||
#pipe the Hands.id out to the HUD
|
#pipe the Hands.id out to the HUD
|
||||||
#print "sending hand to hud", handsId, "pipe =", self.caller.pipe_to_hud
|
print "sending hand to hud", handsId, "pipe =", self.caller.pipe_to_hud
|
||||||
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)
|
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)
|
||||||
except Exceptions.DuplicateError:
|
except Exceptions.DuplicateError:
|
||||||
duplicates += 1
|
duplicates += 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user