allow separate hud options on each table and add aggregate options to main table menu

This commit is contained in:
sqlcoder 2009-09-27 21:23:00 +01:00
parent 7f47a753db
commit d6414d211b
2 changed files with 99 additions and 75 deletions

View File

@ -57,36 +57,46 @@ import Tables
import Hud import Hud
# To add to config: # To add to config:
aggregate_stats = {"ring": False, "tour": False} # uses agg_bb_mult #aggregate_stats = {"ring": False, "tour": False} # uses agg_bb_mult *** this var now replaced by def_hud_params list
hud_style = 'A' # A=All-time #hud_style = 'A' # A=All-time *** this var now replaced by def_hud_params list
# S=Session # S=Session
# T=timed (last n days - set hud_days to required value) # T=timed (last n days - set hud_days to required value)
# Future values may also include: # Future values may also include:
# H=Hands (last n hands) # H=Hands (last n hands)
hud_days = 90 # Max number of days from each player to use for hud stats #hud_days = 90 # Max number of days from each player to use for hud stats *** this var now replaced by def_hud_params list
agg_bb_mult = 100 # 1 = no aggregation. When aggregating stats across levels larger blinds #agg_bb_mult = 100 # 1 = no aggregation. When aggregating stats across levels larger blinds *** this var now replaced by def_hud_params list
# must be < (agg_bb_mult * smaller blinds) to be aggregated # must be < (agg_bb_mult * smaller blinds) to be aggregated
# ie. 100 will aggregate almost everything, 2 will probably agg just the # ie. 100 will aggregate almost everything, 2 will probably agg just the
# next higher and lower levels into the current one, try 3/10/30/100 # next higher and lower levels into the current one, try 3/10/30/100
hud_session_gap = 30 # Gap (minutes) between hands that indicates a change of session #hud_session_gap = 30 # Gap (minutes) between hands that indicates a change of session
# (hands every 2 mins for 1 hour = one session, if followed # (hands every 2 mins for 1 hour = one session, if followed
# by a 40 minute gap and then more hands on same table that is # by a 40 minute gap and then more hands on same table that is
# 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 # New list to hold all HUD params
, 'aggregate_tour' : False # - Set aggregate_ring and/or aggregate_tour to True is you want to include stats from other blind levels in the HUD display
, 'hud_style' : 'A' # - If aggregation is used, the value of agg_bb_mult determines how what levels are included, e.g.
, 'hud_days ' : 90 # if agg_bb_mult is 100, almost all levels are included in all HUD displays
, 'agg_bb_mult' : 100 # if agg_bb_mult is 2.1, levels from half to double the current blind level are included in the HUD
, 'hud_session_gap' : 30 # - Set hud_style to A to see stats for all-time
# second set of variables for hero # Set hud_style to S to only see stats for current session (currently this shows stats for the last 24 hours)
# Set hud_style to T to only see stats for the last N days (uses value in hud_days)
# - Set hud_days to N to see stats for the last N days in the HUD (only applies if hud_style is T)
def_hud_params = { # Settings for all players apart from program owner ('hero')
'aggregate_ring' : False
, 'aggregate_tour' : True
, 'hud_style' : 'A'
, 'hud_days' : 90
, 'agg_bb_mult' : 1 # 1 means no aggregation
# , 'hud_session_gap' : 30 not currently used
# Second set of variables for hero - these settings only apply to the program owner
, 'h_aggregate_ring' : False , 'h_aggregate_ring' : False
, 'h_aggreagte_tour' : False , 'h_aggreagte_tour' : True
, 'h_hud_style' : 'A' , 'h_hud_style' : 'A'
, 'h_hud_days ' : 90 , 'h_hud_days' : 90
, 'h_agg_bb_mult' : 100 , 'h_agg_bb_mult' : 1 # 1 means no aggregation
, 'h_hud_session_gap' : 30 # , 'h_hud_session_gap' : 30 not currently used
} }
@ -183,7 +193,6 @@ class HUD_main(object):
# if it is required. # if it is required.
try: try:
self.db_connection = Database.Database(self.config) self.db_connection = Database.Database(self.config)
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 # get hero's screen names and player ids
@ -205,11 +214,6 @@ class HUD_main(object):
# 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, site_id) = 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, self.hud_params, self.hero_ids)
#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)
@ -237,6 +241,16 @@ class HUD_main(object):
# Update an existing HUD # Update an existing HUD
if temp_key in self.hud_dict: if temp_key in self.hud_dict:
try:
# get stats using hud's specific params
self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] )
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, self.hud_dict[temp_key].hud_params, self.hero_ids)
except:
err = traceback.extract_tb(sys.exc_info()[2])[-1]
print "db get_stats error: skipping "+str(new_hand_id)+" "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
if new_hand_id: # new_hand_id is none if we had an error prior to the store
sys.stderr.write("Database get_stats error %s in hand %d. Skipping.\n" % (err, int(new_hand_id)))
continue
self.hud_dict[temp_key].stat_dict = stat_dict self.hud_dict[temp_key].stat_dict = stat_dict
self.hud_dict[temp_key].cards = cards self.hud_dict[temp_key].cards = cards
[aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[temp_key].aux_windows] [aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[temp_key].aux_windows]
@ -244,6 +258,16 @@ class HUD_main(object):
# Or create a new HUD # Or create a new HUD
else: else:
try:
# get stats using default params
self.db_connection.init_hud_stat_vars( self.hud_params['hud_days'] )
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, self.hud_params, self.hero_ids)
except:
err = traceback.extract_tb(sys.exc_info()[2])[-1]
print "db get_stats error: skipping "+str(new_hand_id)+" "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
if new_hand_id: # new_hand_id is none if we had an error prior to the store
sys.stderr.write("Database get_stats error %s in hand %d. Skipping.\n" % (err, int(new_hand_id)))
continue
if type == "tour": if type == "tour":
tablewindow = Tables.discover_tournament_table(self.config, tour_number, tab_number) tablewindow = Tables.discover_tournament_table(self.config, tour_number, tab_number)
else: else:

View File

@ -144,6 +144,47 @@ class Hud:
repositem = gtk.MenuItem('Reposition StatWindows') repositem = gtk.MenuItem('Reposition StatWindows')
menu.append(repositem) menu.append(repositem)
repositem.connect("activate", self.reposition_windows) repositem.connect("activate", self.reposition_windows)
aggitem = gtk.MenuItem('Show Stats')
menu.append(aggitem)
aggMenu = gtk.Menu()
aggitem.set_submenu(aggMenu)
# set agg_bb_mult to 1 to stop aggregation
item = gtk.MenuItem('For This Blind Level')
item.ms = 1
aggMenu.append(item)
item.connect("activate", self.set_aggregation)
setattr(self, 'showStatsMenuItem1', item)
#
item = gtk.MenuItem('For Multiple Blind Levels')
aggMenu.append(item)
setattr(self, 'showStatsMenuItem2', item)
#
item = gtk.MenuItem('0.5 to 2.0 x Current Blinds')
item.ms = 2.01
aggMenu.append(item)
item.connect("activate", self.set_aggregation)
setattr(self, 'showStatsMenuItem3', item)
#
item = gtk.MenuItem('0.33 to 3.0 x Current Blinds')
item.ms = 3.01
aggMenu.append(item)
item.connect("activate", self.set_aggregation)
setattr(self, 'showStatsMenuItem4', item)
#
item = gtk.MenuItem('0.1 to 10 x Current Blinds')
item.ms = 10.01
aggMenu.append(item)
item.connect("activate", self.set_aggregation)
setattr(self, 'showStatsMenuItem5', item)
#
item = gtk.MenuItem('All Levels')
item.ms = 10000
aggMenu.append(item)
item.connect("activate", self.set_aggregation)
setattr(self, 'showStatsMenuItem6', item)
eventbox.connect_object("button-press-event", self.on_button_press, menu)
debugitem = gtk.MenuItem('Debug StatWindows') debugitem = gtk.MenuItem('Debug StatWindows')
menu.append(debugitem) menu.append(debugitem)
@ -177,9 +218,18 @@ class Hud:
self.create(*self.creation_attrs) self.create(*self.creation_attrs)
self.update(self.hand, self.config) self.update(self.hand, self.config)
except Exception, e: except Exception, e:
print "Expcetion:",str(e) print "Exception:",str(e)
pass pass
def set_aggregation(self, widget):
# try setting these to true all the time, and set the multiplier to 1 to turn agg off:
self.hud_params['h_aggregate_ring'] = True
self.hud_params['h_aggregate_tour'] = True
if self.hud_params['agg_bb_mult'] != widget.ms:
print 'set_aggregation', widget.ms
self.hud_params['agg_bb_mult'] = widget.ms
def update_table_position(self): def update_table_position(self):
if os.name == 'nt': if os.name == 'nt':
if not win32gui.IsWindow(self.table.number): if not win32gui.IsWindow(self.table.number):
@ -632,56 +682,6 @@ class Popup_window:
window.window.set_transient_for(self.table.gdkhandle) window.window.set_transient_for(self.table.gdkhandle)
# 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()