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:
Ray 2009-02-23 21:33:23 -05:00
parent 2ebb026543
commit f1530860d2
4 changed files with 38 additions and 30 deletions

View File

@ -165,19 +165,11 @@ class Database:
c = self.connection.cursor() c = self.connection.cursor()
if aggregate: if aggregate:
query = 'get_stats_from_hand'
subs = (hand, hand)
else:
query = 'get_stats_from_hand_aggregated' query = 'get_stats_from_hand_aggregated'
subs = (hand, hand, hand) subs = (hand, hand, hand)
else:
# get the players in the hand and their seats query = 'get_stats_from_hand'
c.execute(self.sql.query['get_players_from_hand'], (hand, )) subs = (hand, hand)
names = {}
seats = {}
for row in c.fetchall():
names[row[0]] = row[2]
seats[row[0]] = row[1]
# now get the stats # now get the stats
c.execute(self.sql.query[query], subs) c.execute(self.sql.query[query], subs)
@ -187,9 +179,6 @@ class Database:
t_dict = {} t_dict = {}
for name, val in zip(colnames, row): for name, val in zip(colnames, row):
t_dict[name] = val 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 stat_dict[t_dict['player_id']] = t_dict
return stat_dict return stat_dict

View File

@ -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] = Hud.Hud(self, table, max, poker_game, self.config, self.db_connection)
self.hud_dict[table_name].tablehudlabel = newlabel 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: for m in self.hud_dict[table_name].aux_windows:
m.update_data(new_hand_id, self.db_connection) m.update_data(new_hand_id, self.db_connection)
m.update_gui(new_hand_id) m.update_gui(new_hand_id)
@ -141,8 +141,14 @@ class HUD_main(object):
break # this thread is not always killed immediately with gtk.main_quit() break # this thread is not always killed immediately with gtk.main_quit()
# get basic info about the new hand from the db # get basic info about the new hand from the db
(table_name, max, poker_game) = self.db_connection.get_table_name(new_hand_id) # if there is a db error, complain, skip hand, and proceed
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id) 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 # find out if this hand is from a tournament
mat_obj = tourny_finder.search(table_name) mat_obj = tourny_finder.search(table_name)
@ -161,7 +167,7 @@ class HUD_main(object):
aw.update_data(new_hand_id, self.db_connection) aw.update_data(new_hand_id, self.db_connection)
self.update_HUD(new_hand_id, temp_key, self.config, stat_dict) self.update_HUD(new_hand_id, temp_key, self.config, stat_dict)
# Or create a new hud # Or create a new HUD
else: else:
if is_tournament: if is_tournament:
tablewindow = Tables.discover_tournament_table(self.config, tour_number, tab_number) tablewindow = Tables.discover_tournament_table(self.config, tour_number, tab_number)
@ -171,7 +177,7 @@ class HUD_main(object):
if tablewindow == None: if tablewindow == None:
if is_tournament: if is_tournament:
table_name = tour_number + " " + tab_number 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: else:
self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, is_tournament, stat_dict) self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, is_tournament, stat_dict)

View File

@ -201,31 +201,43 @@ class Hud:
self.config.save() self.config.save()
def adj_seats(self, hand, config): def adj_seats(self, hand, config):
adj = range(0, self.max + 1) # default seat adjustments = no adjustment adj = range(0, self.max + 1) # default seat adjustments = no adjustment
# does the user have a fav_seat? # does the user have a fav_seat?
try: 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: 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 fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat
# db_connection = Database.Database(config, self.db_name, 'temp') 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.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
# db_connection.close_connection() 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): for i in range(0, self.max + 1):
j = actual_seat + i j = actual_seat + i
if j > self.max: j = j - self.max if j > self.max: j = j - self.max
adj[j] = fav_seat + i adj[j] = fav_seat + i
if adj[j] > self.max: adj[j] = adj[j] - self.max if adj[j] > self.max: adj[j] = adj[j] - self.max
except: except Exception, inst:
pass sys.stderr.write("exception in adj!!!\n\n")
sys.stderr.write("error is %s" % inst) # __str__ allows args to printed directly
return adj 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" # 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 # hand is the hand id of the most recent hand played at this table
# #
# this method also manages the creating and destruction of stat # this method also manages the creating and destruction of stat
# windows via calls to the Stat_Window class # 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) adj = self.adj_seats(hand, config)
sys.stderr.write("adj = %s\n" % adj)
loc = self.config.get_locations(self.table.site, self.max) loc = self.config.get_locations(self.table.site, self.max)
# create the stat windows # create the stat windows
@ -234,6 +246,7 @@ class Hud:
if i in self.stat_windows: if i in self.stat_windows:
self.stat_windows[i].relocate(x, y) self.stat_windows[i].relocate(x, y)
else: 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], self.stat_windows[i] = Stat_Window(game = config.supported_games[self.poker_game],
parent = self, parent = self,
table = self.table, table = self.table,
@ -292,9 +305,6 @@ class Hud:
tip = stat_dict[s]['screen_name'] + "\n" + number[5] + "\n" + \ tip = stat_dict[s]['screen_name'] + "\n" + number[5] + "\n" + \
number[3] + ", " + number[4] number[3] + ", " + number[4]
Stats.do_tip(self.stat_windows[stat_dict[s]['seat']].e_box[r][c], tip) 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): def topify_window(self, window):
"""Set the specified gtk window to stayontop in MS Windows.""" """Set the specified gtk window to stayontop in MS Windows."""

View File

@ -173,6 +173,8 @@ class Sql:
self.query['get_stats_from_hand'] = """ self.query['get_stats_from_hand'] = """
SELECT HudCache.playerId AS player_id, SELECT HudCache.playerId AS player_id,
seatNo AS seat,
name AS screen_name,
sum(HDs) AS n, sum(HDs) AS n,
sum(street0VPI) AS vpip, sum(street0VPI) AS vpip,
sum(street0Aggr) AS pfr, sum(street0Aggr) AS pfr,
@ -233,6 +235,7 @@ class Sql:
INNER JOIN HandsPlayers ON (HandsPlayers.handId = %s) INNER JOIN HandsPlayers ON (HandsPlayers.handId = %s)
INNER JOIN HudCache ON ( HudCache.PlayerId = HandsPlayers.PlayerId+0 INNER JOIN HudCache ON ( HudCache.PlayerId = HandsPlayers.PlayerId+0
AND HudCache.gametypeId+0 = Hands.gametypeId+0) AND HudCache.gametypeId+0 = Hands.gametypeId+0)
INNER JOIN Players ON (Players.id = HandsPlayers.PlayerId+0)
WHERE Hands.id = %s WHERE Hands.id = %s
GROUP BY HudCache.PlayerId GROUP BY HudCache.PlayerId
""" """