Fixed problem with unreliable fav_seat placement.
Eliminated special query to get actual seat by incorporating in to stat_dict query. Provided for graceful skipping of hands when there is an error in a query in the read_stdin() thread. Left intermediate prints for use of others.
This commit is contained in:
parent
2ebb026543
commit
f1530860d2
|
@ -165,19 +165,11 @@ class Database:
|
|||
c = self.connection.cursor()
|
||||
|
||||
if aggregate:
|
||||
query = 'get_stats_from_hand'
|
||||
subs = (hand, hand)
|
||||
else:
|
||||
query = 'get_stats_from_hand_aggregated'
|
||||
subs = (hand, hand, hand)
|
||||
|
||||
# get the players in the hand and their seats
|
||||
c.execute(self.sql.query['get_players_from_hand'], (hand, ))
|
||||
names = {}
|
||||
seats = {}
|
||||
for row in c.fetchall():
|
||||
names[row[0]] = row[2]
|
||||
seats[row[0]] = row[1]
|
||||
else:
|
||||
query = 'get_stats_from_hand'
|
||||
subs = (hand, hand)
|
||||
|
||||
# now get the stats
|
||||
c.execute(self.sql.query[query], subs)
|
||||
|
@ -187,9 +179,6 @@ class Database:
|
|||
t_dict = {}
|
||||
for name, val in zip(colnames, row):
|
||||
t_dict[name] = val
|
||||
# print t_dict
|
||||
t_dict['screen_name'] = names[t_dict['player_id']]
|
||||
t_dict['seat'] = seats[t_dict['player_id']]
|
||||
stat_dict[t_dict['player_id']] = t_dict
|
||||
return stat_dict
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class HUD_main(object):
|
|||
|
||||
self.hud_dict[table_name] = Hud.Hud(self, table, max, poker_game, self.config, self.db_connection)
|
||||
self.hud_dict[table_name].tablehudlabel = newlabel
|
||||
self.hud_dict[table_name].create(new_hand_id, self.config)
|
||||
self.hud_dict[table_name].create(new_hand_id, self.config, stat_dict)
|
||||
for m in self.hud_dict[table_name].aux_windows:
|
||||
m.update_data(new_hand_id, self.db_connection)
|
||||
m.update_gui(new_hand_id)
|
||||
|
@ -141,9 +141,15 @@ class HUD_main(object):
|
|||
break # this thread is not always killed immediately with gtk.main_quit()
|
||||
|
||||
# get basic info about the new hand from the db
|
||||
(table_name, max, poker_game) = self.db_connection.get_table_name(new_hand_id)
|
||||
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id)
|
||||
|
||||
# if there is a db error, complain, skip hand, and proceed
|
||||
try:
|
||||
(table_name, max, poker_game) = self.db_connection.get_table_name(new_hand_id)
|
||||
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id)
|
||||
except:
|
||||
print "skipping ", new_hand_id
|
||||
sys.stderr.write("Database error in hand %d. Skipping.\n" % int(new_hand_id))
|
||||
continue
|
||||
|
||||
# find out if this hand is from a tournament
|
||||
mat_obj = tourny_finder.search(table_name)
|
||||
if mat_obj:
|
||||
|
@ -161,7 +167,7 @@ class HUD_main(object):
|
|||
aw.update_data(new_hand_id, self.db_connection)
|
||||
self.update_HUD(new_hand_id, temp_key, self.config, stat_dict)
|
||||
|
||||
# Or create a new hud
|
||||
# Or create a new HUD
|
||||
else:
|
||||
if is_tournament:
|
||||
tablewindow = Tables.discover_tournament_table(self.config, tour_number, tab_number)
|
||||
|
@ -171,7 +177,7 @@ class HUD_main(object):
|
|||
if tablewindow == None:
|
||||
if is_tournament:
|
||||
table_name = tour_number + " " + tab_number
|
||||
sys.stderr.write("table name "+table_name+" not found\n")
|
||||
sys.stderr.write("table name "+table_name+" not found, skipping.\n")
|
||||
else:
|
||||
self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, is_tournament, stat_dict)
|
||||
|
||||
|
|
|
@ -201,31 +201,43 @@ class Hud:
|
|||
self.config.save()
|
||||
|
||||
def adj_seats(self, hand, config):
|
||||
|
||||
adj = range(0, self.max + 1) # default seat adjustments = no adjustment
|
||||
# does the user have a fav_seat?
|
||||
try:
|
||||
sys.stderr.write("site = %s, max = %d, fav seat = %d\n" % (self.table.site, self.max, config.supported_sites[self.table.site].layout[self.max].fav_seat))
|
||||
if int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0:
|
||||
fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat
|
||||
# db_connection = Database.Database(config, self.db_name, 'temp')
|
||||
actual_seat = self.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
|
||||
# db_connection.close_connection()
|
||||
sys.stderr.write("found fav seat = %d\n" % fav_seat)
|
||||
# actual_seat = self.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
|
||||
actual_seat = self.get_actual_seat(config.supported_sites[self.table.site].screen_name)
|
||||
sys.stderr.write("found actual seat = %d\n" % actual_seat)
|
||||
for i in range(0, self.max + 1):
|
||||
j = actual_seat + i
|
||||
if j > self.max: j = j - self.max
|
||||
adj[j] = fav_seat + i
|
||||
if adj[j] > self.max: adj[j] = adj[j] - self.max
|
||||
except:
|
||||
pass
|
||||
except Exception, inst:
|
||||
sys.stderr.write("exception in adj!!!\n\n")
|
||||
sys.stderr.write("error is %s" % inst) # __str__ allows args to printed directly
|
||||
return adj
|
||||
|
||||
def create(self, hand, config):
|
||||
def get_actual_seat(self, name):
|
||||
for key in self.stat_dict.keys():
|
||||
if self.stat_dict[key]['screen_name'] == name:
|
||||
return self.stat_dict[key]['seat']
|
||||
sys.stderr.write("Error finding actual seat.\n")
|
||||
|
||||
def create(self, hand, config, stat_dict):
|
||||
# update this hud, to the stats and players as of "hand"
|
||||
# hand is the hand id of the most recent hand played at this table
|
||||
#
|
||||
# this method also manages the creating and destruction of stat
|
||||
# windows via calls to the Stat_Window class
|
||||
|
||||
self.stat_dict = stat_dict
|
||||
sys.stderr.write("------------------------------------------------------------\nCreating hud from hand %s\n" % hand)
|
||||
adj = self.adj_seats(hand, config)
|
||||
sys.stderr.write("adj = %s\n" % adj)
|
||||
loc = self.config.get_locations(self.table.site, self.max)
|
||||
|
||||
# create the stat windows
|
||||
|
@ -234,6 +246,7 @@ class Hud:
|
|||
if i in self.stat_windows:
|
||||
self.stat_windows[i].relocate(x, y)
|
||||
else:
|
||||
sys.stderr.write("actual seat = %d, x = %d, y= %d\n" % (i, x, y))
|
||||
self.stat_windows[i] = Stat_Window(game = config.supported_games[self.poker_game],
|
||||
parent = self,
|
||||
table = self.table,
|
||||
|
@ -292,9 +305,6 @@ class Hud:
|
|||
tip = stat_dict[s]['screen_name'] + "\n" + number[5] + "\n" + \
|
||||
number[3] + ", " + number[4]
|
||||
Stats.do_tip(self.stat_windows[stat_dict[s]['seat']].e_box[r][c], tip)
|
||||
# for m in self.aux_windows:
|
||||
# m.update_data(hand)
|
||||
# m.update_gui(hand)
|
||||
|
||||
def topify_window(self, window):
|
||||
"""Set the specified gtk window to stayontop in MS Windows."""
|
||||
|
|
|
@ -173,6 +173,8 @@ class Sql:
|
|||
|
||||
self.query['get_stats_from_hand'] = """
|
||||
SELECT HudCache.playerId AS player_id,
|
||||
seatNo AS seat,
|
||||
name AS screen_name,
|
||||
sum(HDs) AS n,
|
||||
sum(street0VPI) AS vpip,
|
||||
sum(street0Aggr) AS pfr,
|
||||
|
@ -233,6 +235,7 @@ class Sql:
|
|||
INNER JOIN HandsPlayers ON (HandsPlayers.handId = %s)
|
||||
INNER JOIN HudCache ON ( HudCache.PlayerId = HandsPlayers.PlayerId+0
|
||||
AND HudCache.gametypeId+0 = Hands.gametypeId+0)
|
||||
INNER JOIN Players ON (Players.id = HandsPlayers.PlayerId+0)
|
||||
WHERE Hands.id = %s
|
||||
GROUP BY HudCache.PlayerId
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user