From 036729b8c25d5054efcda3009db3e678ebe561e3 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 11 Nov 2008 09:50:20 -0500 Subject: [PATCH] Support tournaments --- pyfpdb/Database.py | 14 +++++++++----- pyfpdb/HUD_main.py | 27 ++++++++++++++++----------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 4039b256..dbe36622 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -142,12 +142,17 @@ class Database: cards[s_dict['seat_number']] = s_dict return (cards) - def get_stats_from_hand(self, hand, player_id = False): + def get_stats_from_hand(self, hand, aggregate = False): c = self.connection.cursor() - if not player_id: player_id = "%" + 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, player_id)) c.execute(self.sql.query['get_players_from_hand'], (hand, )) names = {} seats = {} @@ -156,8 +161,7 @@ class Database: seats[row[0]] = row[1] # now get the stats -# c.execute(self.sql.query['get_stats_from_hand'], (hand, hand, player_id)) - c.execute(self.sql.query['get_stats_from_hand'], (hand, hand)) + c.execute(self.sql.query[query], subs) colnames = [desc[0] for desc in c.description] stat_dict = {} for row in c.fetchall(): diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index f54fa9af..e869fac6 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -92,7 +92,8 @@ def read_stdin(): # This is the thread function global hud_dict db_connection = Database.Database(config, db_name, 'temp') -# tourny_finder = re.compile('(\d+) (\d+)') + tourny_finder = re.compile('(\d+) (\d+)') + print tourny_finder while True: # wait for a new hand number on stdin new_hand_id = sys.stdin.readline() @@ -110,11 +111,14 @@ def read_stdin(): # This is the thread function # find out if this hand is from a tournament is_tournament = False -# (t_number, s_number) = (0, 0) -# mat_obj = tourny_finder(table_name) + (tour_number, tab_number) = (0, 0) + mat_obj = tourny_finder.search(table_name) # if len(mat_obj.groups) == 2: -# is_tournament = True -# (t_number, s_number) = mat_obj.group(1, 2) + if mat_obj: + print "found tournament", + is_tournament = True + (tour_number, tab_number) = mat_obj.group(1, 2) + print " number = %s, table = %s" % (tour_number, tab_number) stat_dict = db_connection.get_stats_from_hand(new_hand_id) @@ -122,16 +126,17 @@ def read_stdin(): # This is the thread function if hud_dict.has_key(table_name): update_HUD(new_hand_id, table_name, config, stat_dict) # if a hud for this TOURNAMENT table exists, just update it -# elif hud_dict.has_key(t_number): -# update_HUD(new_hand_id, t_number, config, stat_dict) -# otherwise create a new hud + elif hud_dict.has_key(tour_number): + update_HUD(new_hand_id, tour_number, config, stat_dict) +# otherwise create a new hud else: if is_tournament: - tablewindow = Tables.discover_tournament_table(config, t_number, s_number) + tablewindow = Tables.discover_tournament_table(config, tour_number, tab_number) + print tablewindow if tablewindow == None: - sys.stderr.write("table name "+table_name+" not found\n") + sys.stderr.write("tournament %s, table %s not found\n" % (tour_number, tab_number)) else: - create_HUD(new_hand_id, tablewindow, db_name, t_number, max, poker_game, db_connection, config, stat_dict) + create_HUD(new_hand_id, tablewindow, db_name, tour_number, max, poker_game, db_connection, config, stat_dict) else: tablewindow = Tables.discover_table_by_name(config, table_name) if tablewindow == None: