Merge branch 'master' into siteneutral
Conflicts: pyfpdb/fpdb_import.py pyfpdb/fpdb_parse_logic.py pyfpdb/fpdb_simple.py
This commit is contained in:
commit
0b3b7f66d6
|
@ -48,7 +48,7 @@ class Layout:
|
||||||
self.height = int( node.getAttribute('height') )
|
self.height = int( node.getAttribute('height') )
|
||||||
|
|
||||||
self.location = []
|
self.location = []
|
||||||
self.location = map(lambda x: None, range(self.max+1)) # there must be a better way to do this?
|
self.location = map(lambda x: None, range(self.max+1)) # fill array with max seats+1 empty entries
|
||||||
|
|
||||||
for location_node in node.getElementsByTagName('location'):
|
for location_node in node.getElementsByTagName('location'):
|
||||||
if location_node.getAttribute('seat') != "":
|
if location_node.getAttribute('seat') != "":
|
||||||
|
@ -239,13 +239,14 @@ class Tv:
|
||||||
(self.combinedStealFold, self.combined2B3B, self.combinedPostflop) )
|
(self.combinedStealFold, self.combined2B3B, self.combinedPostflop) )
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self, file = None):
|
def __init__(self, file = None, dbname = 'fpdb'):
|
||||||
|
|
||||||
# "file" is a path to an xml file with the fpdb/HUD configuration
|
# "file" is a path to an xml file with the fpdb/HUD configuration
|
||||||
# we check the existence of "file" and try to recover if it doesn't exist
|
# we check the existence of "file" and try to recover if it doesn't exist
|
||||||
|
self.dbname = dbname
|
||||||
|
|
||||||
self.default_config_path = self.get_default_config_path()
|
self.default_config_path = self.get_default_config_path()
|
||||||
if not file == None: # configuration file path has been passed
|
if file != None: # configuration file path has been passed
|
||||||
if not os.path.exists(file):
|
if not os.path.exists(file):
|
||||||
print "Configuration file %s not found. Using defaults." % (file)
|
print "Configuration file %s not found. Using defaults." % (file)
|
||||||
sys.stderr.write("Configuration file %s not found. Using defaults." % (file))
|
sys.stderr.write("Configuration file %s not found. Using defaults." % (file))
|
||||||
|
@ -256,7 +257,7 @@ class Config:
|
||||||
|
|
||||||
if file == None: # no config file in the normal places
|
if file == None: # no config file in the normal places
|
||||||
file = self.find_example_config() #Look for an example file to edit
|
file = self.find_example_config() #Look for an example file to edit
|
||||||
if not file == None:
|
if file != None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if file == None: # that didn't work either, just die
|
if file == None: # that didn't work either, just die
|
||||||
|
@ -323,7 +324,7 @@ class Config:
|
||||||
tv = Tv(node = tv_node)
|
tv = Tv(node = tv_node)
|
||||||
self.tv = tv
|
self.tv = tv
|
||||||
|
|
||||||
db = self.get_db_parameters('fpdb')
|
db = self.get_db_parameters()
|
||||||
if db['db-password'] == 'YOUR MYSQL PASSWORD':
|
if db['db-password'] == 'YOUR MYSQL PASSWORD':
|
||||||
df_file = self.find_default_conf()
|
df_file = self.find_default_conf()
|
||||||
if df_file == None: # this is bad
|
if df_file == None: # this is bad
|
||||||
|
@ -426,7 +427,7 @@ class Config:
|
||||||
return location_node
|
return location_node
|
||||||
|
|
||||||
def save(self, file = None):
|
def save(self, file = None):
|
||||||
if not file == None:
|
if file != None:
|
||||||
f = open(file, 'w')
|
f = open(file, 'w')
|
||||||
self.doc.writexml(f)
|
self.doc.writexml(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -463,9 +464,9 @@ class Config:
|
||||||
else:
|
else:
|
||||||
self.aux_windows[aux_name].layout[max].location[i] = ( locations[i][0], locations[i][1] )
|
self.aux_windows[aux_name].layout[max].location[i] = ( locations[i][0], locations[i][1] )
|
||||||
|
|
||||||
def get_db_parameters(self, name = None):
|
def get_db_parameters(self):
|
||||||
if name == None: name = 'fpdb'
|
|
||||||
db = {}
|
db = {}
|
||||||
|
name = self.dbname
|
||||||
try: db['db-databaseName'] = name
|
try: db['db-databaseName'] = name
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
|
@ -491,18 +492,18 @@ class Config:
|
||||||
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None,
|
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None,
|
||||||
db_pass = None, db_server = None, db_type = None):
|
db_pass = None, db_server = None, db_type = None):
|
||||||
db_node = self.get_db_node(db_name)
|
db_node = self.get_db_node(db_name)
|
||||||
if not db_node == None:
|
if db_node != None:
|
||||||
if not db_ip == None: db_node.setAttribute("db_ip", db_ip)
|
if db_ip != None: db_node.setAttribute("db_ip", db_ip)
|
||||||
if not db_user == None: db_node.setAttribute("db_user", db_user)
|
if db_user != None: db_node.setAttribute("db_user", db_user)
|
||||||
if not db_pass == None: db_node.setAttribute("db_pass", db_pass)
|
if db_pass != None: db_node.setAttribute("db_pass", db_pass)
|
||||||
if not db_server == None: db_node.setAttribute("db_server", db_server)
|
if db_server != None: db_node.setAttribute("db_server", db_server)
|
||||||
if not db_type == None: db_node.setAttribute("db_type", db_type)
|
if db_type != None: db_node.setAttribute("db_type", db_type)
|
||||||
if self.supported_databases.has_key(db_name):
|
if self.supported_databases.has_key(db_name):
|
||||||
if not db_ip == None: self.supported_databases[db_name].dp_ip = db_ip
|
if db_ip != None: self.supported_databases[db_name].dp_ip = db_ip
|
||||||
if not db_user == None: self.supported_databases[db_name].dp_user = db_user
|
if db_user != None: self.supported_databases[db_name].dp_user = db_user
|
||||||
if not db_pass == None: self.supported_databases[db_name].dp_pass = db_pass
|
if db_pass != None: self.supported_databases[db_name].dp_pass = db_pass
|
||||||
if not db_server == None: self.supported_databases[db_name].dp_server = db_server
|
if db_server != None: self.supported_databases[db_name].dp_server = db_server
|
||||||
if not db_type == None: self.supported_databases[db_name].dp_type = db_type
|
if db_type != None: self.supported_databases[db_name].dp_type = db_type
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_tv_parameters(self):
|
def get_tv_parameters(self):
|
||||||
|
@ -630,19 +631,19 @@ class Config:
|
||||||
font = None, font_size = None):
|
font = None, font_size = None):
|
||||||
"""Sets the specified site parameters for the specified site."""
|
"""Sets the specified site parameters for the specified site."""
|
||||||
site_node = self.get_site_node(site_name)
|
site_node = self.get_site_node(site_name)
|
||||||
if not db_node == None:
|
if db_node != None:
|
||||||
if not converter == None: site_node.setAttribute("converter", converter)
|
if converter != None: site_node.setAttribute("converter", converter)
|
||||||
if not decoder == None: site_node.setAttribute("decoder", decoder)
|
if decoder != None: site_node.setAttribute("decoder", decoder)
|
||||||
if not hudbgcolor == None: site_node.setAttribute("hudbgcolor", hudbgcolor)
|
if hudbgcolor != None: site_node.setAttribute("hudbgcolor", hudbgcolor)
|
||||||
if not hudfgcolor == None: site_node.setAttribute("hudfgcolor", hudfgcolor)
|
if hudfgcolor != None: site_node.setAttribute("hudfgcolor", hudfgcolor)
|
||||||
if not hudopacity == None: site_node.setAttribute("hudopacity", hudopacity)
|
if hudopacity != None: site_node.setAttribute("hudopacity", hudopacity)
|
||||||
if not screen_name == None: site_node.setAttribute("screen_name", screen_name)
|
if screen_name != None: site_node.setAttribute("screen_name", screen_name)
|
||||||
if not site_path == None: site_node.setAttribute("site_path", site_path)
|
if site_path != None: site_node.setAttribute("site_path", site_path)
|
||||||
if not table_finder == None: site_node.setAttribute("table_finder", table_finder)
|
if table_finder != None: site_node.setAttribute("table_finder", table_finder)
|
||||||
if not HH_path == None: site_node.setAttribute("HH_path", HH_path)
|
if HH_path != None: site_node.setAttribute("HH_path", HH_path)
|
||||||
if not enabled == None: site_node.setAttribute("enabled", enabled)
|
if enabled != None: site_node.setAttribute("enabled", enabled)
|
||||||
if not font == None: site_node.setAttribute("font", font)
|
if font != None: site_node.setAttribute("font", font)
|
||||||
if not font_size == None: site_node.setAttribute("font_size", font_size)
|
if font_size != None: site_node.setAttribute("font_size", font_size)
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_aux_windows(self):
|
def get_aux_windows(self):
|
||||||
|
|
|
@ -68,13 +68,13 @@ class GuiGraphViewer (threading.Thread):
|
||||||
if len(result) == 1:
|
if len(result) == 1:
|
||||||
playerids.append(result[0][0])
|
playerids.append(result[0][0])
|
||||||
|
|
||||||
if sitenos == []:
|
if not sitenos:
|
||||||
#Should probably pop up here.
|
#Should probably pop up here.
|
||||||
print "No sites selected - defaulting to PokerStars"
|
print "No sites selected - defaulting to PokerStars"
|
||||||
sitenos = [2]
|
sitenos = [2]
|
||||||
|
|
||||||
|
|
||||||
if playerids == []:
|
if not playerids:
|
||||||
print "No player ids found"
|
print "No player ids found"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ class HUD_main(object):
|
||||||
|
|
||||||
gtk.gdk.threads_enter()
|
gtk.gdk.threads_enter()
|
||||||
try:
|
try:
|
||||||
newlabel = gtk.Label(table.site + " - " + table_name)
|
newlabel = gtk.Label("%s - %s" % (table.site, table_name))
|
||||||
self.vb.add(newlabel)
|
self.vb.add(newlabel)
|
||||||
newlabel.show()
|
newlabel.show()
|
||||||
self.main_window.resize_children()
|
self.main_window.resize_children()
|
||||||
|
@ -110,8 +110,8 @@ 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].stat_dict = stat_dict
|
self.hud_dict[table_name].stat_dict = stat_dict
|
||||||
self.hud_dict[table_name].cards = cards
|
self.hud_dict[table_name].cards = cards
|
||||||
for aw in self.hud_dict[table_name].aux_windows:
|
|
||||||
aw.update_data(new_hand_id, self.db_connection)
|
[aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[table_name].aux_windows]
|
||||||
gobject.idle_add(idle_func)
|
gobject.idle_add(idle_func)
|
||||||
|
|
||||||
def update_HUD(self, new_hand_id, table_name, config):
|
def update_HUD(self, new_hand_id, table_name, config):
|
||||||
|
|
|
@ -174,11 +174,10 @@ class Hud:
|
||||||
self.main_window.move(x, y)
|
self.main_window.move(x, y)
|
||||||
adj = self.adj_seats(self.hand, self.config)
|
adj = self.adj_seats(self.hand, self.config)
|
||||||
loc = self.config.get_locations(self.table.site, self.max)
|
loc = self.config.get_locations(self.table.site, self.max)
|
||||||
for i, w in enumerate(self.stat_windows):
|
# TODO: is stat_windows getting converted somewhere from a list to a dict, for no good reason?
|
||||||
if not type(w) == int: # how do we get pure ints in this list??
|
for i, w in enumerate(self.stat_windows.itervalues()):
|
||||||
(x, y) = loc[adj[i]]
|
(x, y) = loc[adj[i]]
|
||||||
w.relocate(x, y)
|
w.relocate(x, y)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def on_button_press(self, widget, event):
|
def on_button_press(self, widget, event):
|
||||||
|
@ -415,8 +414,9 @@ class Stat_Window:
|
||||||
self.window.set_transient_for(parent.main_window)
|
self.window.set_transient_for(parent.main_window)
|
||||||
self.window.set_focus_on_map(False)
|
self.window.set_focus_on_map(False)
|
||||||
|
|
||||||
self.grid = gtk.Table(rows = game.rows, columns = game.cols, homogeneous = False)
|
grid = gtk.Table(rows = game.rows, columns = game.cols, homogeneous = False)
|
||||||
self.window.add(self.grid)
|
self.grid = grid
|
||||||
|
self.window.add(grid)
|
||||||
self.window.modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
|
self.window.modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
|
||||||
|
|
||||||
self.e_box = []
|
self.e_box = []
|
||||||
|
@ -440,10 +440,10 @@ class Stat_Window:
|
||||||
|
|
||||||
Stats.do_tip(e_box[r][c], 'stuff')
|
Stats.do_tip(e_box[r][c], 'stuff')
|
||||||
if usegtkframes:
|
if usegtkframes:
|
||||||
self.grid.attach(self.frame[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
|
grid.attach(self.frame[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
|
||||||
self.frame[r][c].add(e_box[r][c])
|
self.frame[r][c].add(e_box[r][c])
|
||||||
else:
|
else:
|
||||||
self.grid.attach(e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
|
grid.attach(e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
|
||||||
label[r].append( gtk.Label('xxx') )
|
label[r].append( gtk.Label('xxx') )
|
||||||
|
|
||||||
if usegtkframes:
|
if usegtkframes:
|
||||||
|
|
|
@ -39,15 +39,19 @@ import Database
|
||||||
class Aux_Window:
|
class Aux_Window:
|
||||||
def __init__(self, hud, params, config):
|
def __init__(self, hud, params, config):
|
||||||
self.hud = hud
|
self.hud = hud
|
||||||
|
self.params = params
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def update_data(self, *parms):
|
def update_data(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update_gui(self, *parms):
|
def update_gui(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create(self, *parms):
|
def create(self, *args):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def relocate(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def save_layout(self, *args):
|
def save_layout(self, *args):
|
||||||
|
@ -321,6 +325,7 @@ class Flop_Mucked(Aux_Window):
|
||||||
self.config = config # configuration object for this aux window to use
|
self.config = config # configuration object for this aux window to use
|
||||||
self.params = params # dict aux params from config
|
self.params = params # dict aux params from config
|
||||||
self.positions = {} # dict of window positions
|
self.positions = {} # dict of window positions
|
||||||
|
# self.rel_positions = {} # dict of window positions, relative to the table origin
|
||||||
self.displayed_cards = False
|
self.displayed_cards = False
|
||||||
self.timer_on = False # bool = Ture if the timeout for removing the cards is on
|
self.timer_on = False # bool = Ture if the timeout for removing the cards is on
|
||||||
self.card_images = self.get_card_images()
|
self.card_images = self.get_card_images()
|
||||||
|
@ -350,6 +355,7 @@ class Flop_Mucked(Aux_Window):
|
||||||
self.seen_cards[i] = gtk.image_new_from_pixbuf(self.card_images[('B', 'H')])
|
self.seen_cards[i] = gtk.image_new_from_pixbuf(self.card_images[('B', 'H')])
|
||||||
self.eb[i].add(self.seen_cards[i])
|
self.eb[i].add(self.seen_cards[i])
|
||||||
self.positions[i] = (int(x) + self.hud.table.x, int(y) + self.hud.table.y)
|
self.positions[i] = (int(x) + self.hud.table.x, int(y) + self.hud.table.y)
|
||||||
|
# self.rel_positions[i] = (int(x), int(y))
|
||||||
self.m_windows[i].move(self.positions[i][0], self.positions[i][1])
|
self.m_windows[i].move(self.positions[i][0], self.positions[i][1])
|
||||||
self.m_windows[i].set_opacity(float(self.params['opacity']))
|
self.m_windows[i].set_opacity(float(self.params['opacity']))
|
||||||
self.m_windows[i].show_all()
|
self.m_windows[i].show_all()
|
||||||
|
@ -434,6 +440,7 @@ class Flop_Mucked(Aux_Window):
|
||||||
|
|
||||||
def configure_event_cb(self, widget, event, i, *args):
|
def configure_event_cb(self, widget, event, i, *args):
|
||||||
self.positions[i] = widget.get_position()
|
self.positions[i] = widget.get_position()
|
||||||
|
# self.rel_positions[i] = (self.positions[i][0] - self.hud.table.x, self.positions[i][1] - self.hud.table.y)
|
||||||
|
|
||||||
def expose_all(self):
|
def expose_all(self):
|
||||||
for (i, cards) in self.hud.cards.iteritems():
|
for (i, cards) in self.hud.cards.iteritems():
|
||||||
|
|
|
@ -219,7 +219,7 @@ def discover_nt(c):
|
||||||
else:
|
else:
|
||||||
tw.site = "Unknown"
|
tw.site = "Unknown"
|
||||||
sys.stderr.write("Found unknown table = %s" % tw.title)
|
sys.stderr.write("Found unknown table = %s" % tw.title)
|
||||||
if not tw.site == "Unknown":
|
if tw.site != "Unknown":
|
||||||
eval("%s(tw)" % c.supported_sites[tw.site].decoder)
|
eval("%s(tw)" % c.supported_sites[tw.site].decoder)
|
||||||
else:
|
else:
|
||||||
tw.name = "Unknown"
|
tw.name = "Unknown"
|
||||||
|
|
|
@ -23,6 +23,8 @@ from optparse import OptionParser
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
parser.add_option("-x", "--errorsToConsole", action="store_true",
|
parser.add_option("-x", "--errorsToConsole", action="store_true",
|
||||||
help="If passed error output will go to the console rather than .")
|
help="If passed error output will go to the console rather than .")
|
||||||
|
parser.add_option("-d", "--databaseName", dest="dbname", default="fpdb",
|
||||||
|
help="Overrides the default database name")
|
||||||
(options, sys.argv) = parser.parse_args()
|
(options, sys.argv) = parser.parse_args()
|
||||||
|
|
||||||
if not options.errorsToConsole:
|
if not options.errorsToConsole:
|
||||||
|
@ -371,7 +373,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.threads=[]
|
self.threads=[]
|
||||||
self.db=None
|
self.db=None
|
||||||
self.config = Configuration.Config()
|
self.config = Configuration.Config(dbname=options.dbname)
|
||||||
self.load_profile()
|
self.load_profile()
|
||||||
|
|
||||||
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||||
|
|
|
@ -68,12 +68,10 @@ class Importer:
|
||||||
self.pos_in_file = {} # dict to remember how far we have read in the file
|
self.pos_in_file = {} # dict to remember how far we have read in the file
|
||||||
#Set defaults
|
#Set defaults
|
||||||
self.callHud = self.config.get_import_parameters().get("callFpdbHud")
|
self.callHud = self.config.get_import_parameters().get("callFpdbHud")
|
||||||
if 'minPrint' not in self.settings:
|
|
||||||
#TODO: Is this value in the xml file?
|
self.settings.setdefault("minPrint", 30)
|
||||||
self.settings['minPrint'] = 30
|
self.settings.setdefault("handCount", 0)
|
||||||
if 'handCount' not in self.settings:
|
|
||||||
#TODO: Is this value in the xml file?
|
|
||||||
self.settings['handCount'] = 0
|
|
||||||
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
||||||
self.fdb.do_connect(self.config)
|
self.fdb.do_connect(self.config)
|
||||||
|
|
||||||
|
@ -281,7 +279,7 @@ class Importer:
|
||||||
starttime = time()
|
starttime = time()
|
||||||
last_read_hand = 0
|
last_read_hand = 0
|
||||||
loc = 0
|
loc = 0
|
||||||
if (file=="stdin"):
|
if file == "stdin":
|
||||||
inputFile = sys.stdin
|
inputFile = sys.stdin
|
||||||
else:
|
else:
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
|
@ -340,7 +338,7 @@ class Importer:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handsId = fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db
|
handsId = fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db
|
||||||
,self.fdb.cursor, self.siteIds[site], category, hand, self.config)
|
,self.fdb.cursor, site, category, hand, self.config)
|
||||||
self.fdb.db.commit()
|
self.fdb.db.commit()
|
||||||
|
|
||||||
stored += 1
|
stored += 1
|
||||||
|
@ -363,16 +361,17 @@ class Importer:
|
||||||
|
|
||||||
self.fdb.db.rollback()
|
self.fdb.db.rollback()
|
||||||
|
|
||||||
if (self.settings['failOnError']):
|
if self.settings['failOnError']:
|
||||||
self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
|
self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
|
||||||
raise
|
raise
|
||||||
if (self.settings['minPrint']!=0):
|
|
||||||
if ((stored+duplicates+errors)%self.settings['minPrint']==0):
|
if self.settings['minPrint']:
|
||||||
|
if not ((stored+duplicates+errors) % self.settings['minPrint']):
|
||||||
print "stored:", stored, "duplicates:", duplicates, "errors:", errors
|
print "stored:", stored, "duplicates:", duplicates, "errors:", errors
|
||||||
|
|
||||||
if (self.settings['handCount']!=0):
|
if self.settings['handCount']:
|
||||||
if ((stored+duplicates+errors) >= self.settings['handCount']):
|
if ((stored+duplicates+errors) >= self.settings['handCount']):
|
||||||
if (not self.settings['quiet']):
|
if not self.settings['quiet']:
|
||||||
print "quitting due to reaching the amount of hands to be imported"
|
print "quitting due to reaching the amount of hands to be imported"
|
||||||
print "Total stored:", stored, "duplicates:", duplicates, "errors:", errors, " time:", (time() - starttime)
|
print "Total stored:", stored, "duplicates:", duplicates, "errors:", errors, " time:", (time() - starttime)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -380,9 +379,9 @@ class Importer:
|
||||||
ttime = time() - starttime
|
ttime = time() - starttime
|
||||||
print "\rTotal stored:", stored, "duplicates:", duplicates, "errors:", errors, " time:", ttime
|
print "\rTotal stored:", stored, "duplicates:", duplicates, "errors:", errors, " time:", ttime
|
||||||
|
|
||||||
if stored==0:
|
if not stored:
|
||||||
if duplicates>0:
|
if duplicates:
|
||||||
for line_no in range(len(self.lines)):
|
for line_no in xrange(len(self.lines)):
|
||||||
if self.lines[line_no].find("Game #")!=-1:
|
if self.lines[line_no].find("Game #")!=-1:
|
||||||
final_game_line=self.lines[line_no]
|
final_game_line=self.lines[line_no]
|
||||||
handsId=fpdb_simple.parseSiteHandNo(final_game_line)
|
handsId=fpdb_simple.parseSiteHandNo(final_game_line)
|
||||||
|
|
|
@ -384,18 +384,13 @@ def getLastInsertId(backend, conn, cursor):
|
||||||
|
|
||||||
#returns an array of the total money paid. intending to add rebuys/addons here
|
#returns an array of the total money paid. intending to add rebuys/addons here
|
||||||
def calcPayin(count, buyin, fee):
|
def calcPayin(count, buyin, fee):
|
||||||
result=[]
|
return [buyin + fee for i in xrange(count)]
|
||||||
for i in xrange(count):
|
|
||||||
result.append (buyin+fee)
|
|
||||||
return result
|
|
||||||
#end def calcPayin
|
#end def calcPayin
|
||||||
|
|
||||||
def checkPositions(positions):
|
def checkPositions(positions):
|
||||||
""" verify positions are valid """
|
""" verify positions are valid """
|
||||||
for p in positions:
|
if any(not (p == "B" or p == "S" or (p >= 0 and p <= 9)) for p in positions):
|
||||||
if not (p == "B" or p == "S" or (p >= 0 and p <= 9)):
|
|
||||||
raise FpdbError("invalid position '"+p+"' found in checkPositions")
|
raise FpdbError("invalid position '"+p+"' found in checkPositions")
|
||||||
|
|
||||||
### RHH modified to allow for "position 9" here (pos==9 is when you're a dead hand before the BB
|
### RHH modified to allow for "position 9" here (pos==9 is when you're a dead hand before the BB
|
||||||
### eric - position 8 could be valid - if only one blind is posted, but there's still 10 people, ie a sitout is present, and the small is dead...
|
### eric - position 8 could be valid - if only one blind is posted, but there's still 10 people, ie a sitout is present, and the small is dead...
|
||||||
|
|
||||||
|
@ -495,12 +490,13 @@ def convertBlindBet(actionTypes, actionAmounts):
|
||||||
blinds=[]
|
blinds=[]
|
||||||
bets=[]
|
bets=[]
|
||||||
for k in xrange(len(actionTypes[i][j])):
|
for k in xrange(len(actionTypes[i][j])):
|
||||||
if (actionTypes[i][j][k]=="blind"):
|
if actionTypes[i][j][k] == "blind":
|
||||||
blinds.append((i,j,k))
|
blinds.append((i,j,k))
|
||||||
|
|
||||||
if (len(blinds)>0 and actionTypes[i][j][k]=="bet"):
|
if blinds and actionTypes[i][j][k] == "bet":
|
||||||
|
# if (len(blinds)>0 and actionTypes[i][j][k]=="bet"):
|
||||||
bets.append((i,j,k))
|
bets.append((i,j,k))
|
||||||
if (len(bets)==1):
|
if len(bets) == 1:
|
||||||
blind_amount=actionAmounts[blinds[0][0]][blinds[0][1]][blinds[0][2]]
|
blind_amount=actionAmounts[blinds[0][0]][blinds[0][1]][blinds[0][2]]
|
||||||
bet_amount=actionAmounts[bets[0][0]][bets[0][1]][bets[0][2]]
|
bet_amount=actionAmounts[bets[0][0]][bets[0][1]][bets[0][2]]
|
||||||
actionAmounts[bets[0][0]][bets[0][1]][bets[0][2]]=bet_amount-blind_amount
|
actionAmounts[bets[0][0]][bets[0][1]][bets[0][2]]=bet_amount-blind_amount
|
||||||
|
@ -615,84 +611,80 @@ def filterAnteBlindFold(hand):
|
||||||
#end def filterAnteFold
|
#end def filterAnteFold
|
||||||
|
|
||||||
def stripEOLspaces(str):
|
def stripEOLspaces(str):
|
||||||
if str[-1] == ' ':
|
return str.rstrip()
|
||||||
str = str[:-1]
|
|
||||||
if str[-1] == ' ':
|
|
||||||
str = str[:-1]
|
|
||||||
return str
|
|
||||||
|
|
||||||
#removes useless lines as well as trailing spaces
|
#removes useless lines as well as trailing spaces
|
||||||
def filterCrap(hand, isTourney):
|
def filterCrap(hand, isTourney):
|
||||||
#remove two trailing spaces at end of line
|
#remove two trailing spaces at end of line
|
||||||
hand = [stripEOLspaces(line) for line in hand]
|
hand = [line.rstrip() for line in hand]
|
||||||
|
|
||||||
#print "hand after trailing space removal in filterCrap:",hand
|
#print "hand after trailing space removal in filterCrap:",hand
|
||||||
#general variable position word filter/string filter
|
#general variable position word filter/string filter
|
||||||
for i in xrange (len(hand)):
|
for i in xrange (len(hand)):
|
||||||
if (hand[i].startswith("Board [")):
|
if hand[i].startswith("Board ["):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].find(" out of hand ")!=-1):
|
elif hand[i].find(" out of hand ")!=-1:
|
||||||
hand[i]=hand[i][:-56]
|
hand[i]=hand[i][:-56]
|
||||||
elif (hand[i].find("($0 in chips)") != -1):
|
elif "($0 in chips)" in hand[i]:
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i]=="*** HOLE CARDS ***"):
|
elif hand[i]=="*** HOLE CARDS ***":
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("has been disconnected")):
|
elif hand[i].endswith("has been disconnected"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("has requested TIME")):
|
elif hand[i].endswith("has requested TIME"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("has returned")):
|
elif hand[i].endswith("has returned"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("will be allowed to play after the button")):
|
elif hand[i].endswith("will be allowed to play after the button"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("has timed out")):
|
elif hand[i].endswith("has timed out"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("has timed out while disconnected")):
|
elif hand[i].endswith("has timed out while disconnected"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("has timed out while being disconnected")):
|
elif hand[i].endswith("has timed out while being disconnected"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("is connected")):
|
elif hand[i].endswith("is connected"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("is disconnected")):
|
elif hand[i].endswith("is disconnected"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].find(" is low with [")!=-1):
|
elif hand[i].find(" is low with [")!=-1:
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith(" mucks")):
|
elif (hand[i].endswith(" mucks")):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith(": mucks hand")):
|
elif hand[i].endswith(": mucks hand"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i]=="No low hand qualified"):
|
elif hand[i] == "No low hand qualified":
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i]=="Pair on board - a double bet is allowed"):
|
elif hand[i] == "Pair on board - a double bet is allowed":
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].find(" shows ")!=-1 and hand[i].find("[")==-1):
|
elif " shows " in hand[i] and "[" not in hand[i]:
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].startswith("The button is in seat #")):
|
elif hand[i].startswith("The button is in seat #"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
#above is alphabetic, reorder below if bored
|
#above is alphabetic, reorder below if bored
|
||||||
elif (hand[i].startswith("Time has expired")):
|
elif hand[i].startswith("Time has expired"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("has reconnected")):
|
elif hand[i].endswith("has reconnected"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("seconds left to act")):
|
elif hand[i].endswith("seconds left to act"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("seconds to reconnect")):
|
elif hand[i].endswith("seconds to reconnect"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("was removed from the table for failing to post")):
|
elif hand[i].endswith("was removed from the table for failing to post"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].find("joins the table at seat ")!=-1):
|
elif "joins the table at seat " in hand[i]:
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("leaves the table")):
|
elif (hand[i].endswith("leaves the table")):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].find("is high with ")!=-1):
|
elif "is high with " in hand[i]:
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("doesn't show hand")):
|
elif hand[i].endswith("doesn't show hand"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith("is being treated as all-in")):
|
elif hand[i].endswith("is being treated as all-in"):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].find(" adds $")!=-1):
|
elif " adds $" in hand[i]:
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i]=="Betting is capped"):
|
elif hand[i] == "Betting is capped":
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].find(" said, \"")!=-1):
|
elif (hand[i].find(" said, \"")!=-1):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
|
@ -700,7 +692,8 @@ def filterCrap(hand, isTourney):
|
||||||
if isTourney and not hand[i] == False:
|
if isTourney and not hand[i] == False:
|
||||||
if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))):
|
if (hand[i].endswith(" is sitting out") and (not hand[i].startswith("Seat "))):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith(": sits out")):
|
elif hand[i]:
|
||||||
|
if (hand[i].endswith(": sits out")):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
elif (hand[i].endswith(" is sitting out")):
|
elif (hand[i].endswith(" is sitting out")):
|
||||||
hand[i] = False
|
hand[i] = False
|
||||||
|
@ -714,11 +707,11 @@ def filterCrap(hand, isTourney):
|
||||||
#takes a poker float (including , for thousand seperator and converts it to an int
|
#takes a poker float (including , for thousand seperator and converts it to an int
|
||||||
def float2int(string):
|
def float2int(string):
|
||||||
pos = string.find(",")
|
pos = string.find(",")
|
||||||
if (pos!=-1): #remove , the thousand seperator
|
if pos != -1: #remove , the thousand seperator
|
||||||
string = "%s%s" % (string[0:pos], string[pos+1:])
|
string = "%s%s" % (string[0:pos], string[pos+1:])
|
||||||
|
|
||||||
pos = string.find(".")
|
pos = string.find(".")
|
||||||
if (pos!=-1): #remove decimal point
|
if pos != -1: #remove decimal point
|
||||||
string = "%s%s" % (string[0:pos], string[pos+1:])
|
string = "%s%s" % (string[0:pos], string[pos+1:])
|
||||||
|
|
||||||
result = int(string)
|
result = int(string)
|
||||||
|
@ -741,7 +734,8 @@ def isActionLine(line):
|
||||||
elif (line.startswith("Uncalled bet")):
|
elif (line.startswith("Uncalled bet")):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return len( [ x for x in ActionLines if x in line]) > 0
|
return any(x for x in ActionLines if x in line)
|
||||||
|
# return bool([ x for x in ActionLines if x in line])
|
||||||
# ret = any(True for searchstr in ActionLines if searchstr in line)
|
# ret = any(True for searchstr in ActionLines if searchstr in line)
|
||||||
# ret = len( [ x for x in ActionLines if line.find(x) > -1] ) > 0
|
# ret = len( [ x for x in ActionLines if line.find(x) > -1] ) > 0
|
||||||
# ret = any(searchstr in line for searchstr in ActionLines)
|
# ret = any(searchstr in line for searchstr in ActionLines)
|
||||||
|
@ -771,7 +765,7 @@ WinLines = ( "wins the pot", "ties for the ", "wins side pot", "wins the low mai
|
||||||
"wins the high pot", "wins the high side pot", "wins the main pot", "wins the side pot", "collected" )
|
"wins the high pot", "wins the high side pot", "wins the main pot", "wins the side pot", "collected" )
|
||||||
#returns boolean whether the passed line is a win line
|
#returns boolean whether the passed line is a win line
|
||||||
def isWinLine(line):
|
def isWinLine(line):
|
||||||
return len( [ x for x in WinLines if x in line ] ) > 0
|
return any(x for x in WinLines if x in line)
|
||||||
#end def isWinLine
|
#end def isWinLine
|
||||||
|
|
||||||
#returns the amount of cash/chips put into the put in the given action line
|
#returns the amount of cash/chips put into the put in the given action line
|
||||||
|
@ -833,7 +827,7 @@ def parseActionLine(base, isTourney, line, street, playerIDs, names, action_type
|
||||||
if actionNos[street][player][count]>=nextActionNo:
|
if actionNos[street][player][count]>=nextActionNo:
|
||||||
nextActionNo=actionNos[street][player][count]+1
|
nextActionNo=actionNos[street][player][count]+1
|
||||||
|
|
||||||
line, allIn=goesAllInOnThisLine(line)
|
(line, allIn) = goesAllInOnThisLine(line)
|
||||||
atype = parseActionType(line)
|
atype = parseActionType(line)
|
||||||
playerno = recognisePlayerNo(line, names, atype)
|
playerno = recognisePlayerNo(line, names, atype)
|
||||||
amount = parseActionAmount(line, atype, isTourney)
|
amount = parseActionAmount(line, atype, isTourney)
|
||||||
|
@ -859,6 +853,12 @@ def goesAllInOnThisLine(line):
|
||||||
#end def goesAllInOnThisLine
|
#end def goesAllInOnThisLine
|
||||||
|
|
||||||
#returns the action type code (see table design) of the given action line
|
#returns the action type code (see table design) of the given action line
|
||||||
|
ActionTypes = { 'calls':"call", 'brings in for':"blind", 'completes it to':"bet", ' posts $':"blind",
|
||||||
|
' posts a dead ' : "blind", ' posts the small blind of $':"blind", ': posts big blind ':"blind",
|
||||||
|
' posts the big blind of $':"blind", ': posts small & big blinds $':"blind",
|
||||||
|
': posts small blind $':"blind",
|
||||||
|
' bets' : "bet", ' raises' : "bet"
|
||||||
|
}
|
||||||
def parseActionType(line):
|
def parseActionType(line):
|
||||||
if (line.startswith("Uncalled bet")):
|
if (line.startswith("Uncalled bet")):
|
||||||
return "unbet"
|
return "unbet"
|
||||||
|
@ -866,33 +866,10 @@ def parseActionType(line):
|
||||||
return "fold"
|
return "fold"
|
||||||
elif (line.endswith(" checks")):
|
elif (line.endswith(" checks")):
|
||||||
return "check"
|
return "check"
|
||||||
elif (line.find("calls")!=-1):
|
|
||||||
return "call"
|
|
||||||
elif (line.find("brings in for")!=-1):
|
|
||||||
return "blind"
|
|
||||||
elif (line.find("completes it to")!=-1):
|
|
||||||
return "bet"
|
|
||||||
#todo: what if someone completes instead of bringing in?
|
|
||||||
elif (line.find(" posts $")!=-1):
|
|
||||||
return "blind"
|
|
||||||
elif (line.find(" posts a dead ")!=-1):
|
|
||||||
return "blind"
|
|
||||||
elif (line.find(": posts small blind ")!=-1):
|
|
||||||
return "blind"
|
|
||||||
elif (line.find(" posts the small blind of $")!=-1):
|
|
||||||
return "blind"
|
|
||||||
elif (line.find(": posts big blind ")!=-1):
|
|
||||||
return "blind"
|
|
||||||
elif (line.find(" posts the big blind of $")!=-1):
|
|
||||||
return "blind"
|
|
||||||
elif (line.find(": posts small & big blinds $")!=-1):
|
|
||||||
return "blind"
|
|
||||||
#todo: seperately record voluntary blind payments made to join table out of turn
|
|
||||||
elif (line.find("bets")!=-1):
|
|
||||||
return "bet"
|
|
||||||
elif (line.find("raises")!=-1):
|
|
||||||
return "bet"
|
|
||||||
else:
|
else:
|
||||||
|
for x in ActionTypes:
|
||||||
|
if x in line:
|
||||||
|
return ActionTypes[x]
|
||||||
raise FpdbError ("failed to recognise actiontype in parseActionLine in: "+line)
|
raise FpdbError ("failed to recognise actiontype in parseActionLine in: "+line)
|
||||||
#end def parseActionType
|
#end def parseActionType
|
||||||
|
|
||||||
|
@ -1025,12 +1002,12 @@ def parseFee(topline):
|
||||||
def parseHandStartTime(topline):
|
def parseHandStartTime(topline):
|
||||||
#convert x:13:35 to 0x:13:35
|
#convert x:13:35 to 0x:13:35
|
||||||
counter=0
|
counter=0
|
||||||
while (True):
|
while counter < 10:
|
||||||
pos=topline.find(" "+str(counter)+":")
|
pos = topline.find(" %d:" % counter)
|
||||||
if (pos!=-1):
|
if pos != -1:
|
||||||
topline=topline[0:pos+1]+"0"+topline[pos+1:]
|
topline = "%s0%s" % (topline[0:pos+1], topline[pos+1:])
|
||||||
|
break
|
||||||
counter += 1
|
counter += 1
|
||||||
if counter==10: break
|
|
||||||
|
|
||||||
isUTC=False
|
isUTC=False
|
||||||
if topline.find("UTC")!=-1:
|
if topline.find("UTC")!=-1:
|
||||||
|
@ -1058,60 +1035,54 @@ def parseHandStartTime(topline):
|
||||||
#end def parseHandStartTime
|
#end def parseHandStartTime
|
||||||
|
|
||||||
#parses the names out of the given lines and returns them as an array
|
#parses the names out of the given lines and returns them as an array
|
||||||
|
def findName(line):
|
||||||
|
pos1 = line.find(":") + 2
|
||||||
|
pos2 = line.rfind("(") - 1
|
||||||
|
return unicode(line[pos1:pos2], "latin-1")
|
||||||
|
|
||||||
def parseNames(lines):
|
def parseNames(lines):
|
||||||
result = []
|
return [findName(line) for line in lines]
|
||||||
for i in xrange (len(lines)):
|
|
||||||
pos1=lines[i].find(":")+2
|
|
||||||
pos2=lines[i].rfind("(")-1
|
|
||||||
tmp=lines[i][pos1:pos2]
|
|
||||||
#print "parseNames, tmp original:",tmp
|
|
||||||
tmp=unicode(tmp,"latin-1")
|
|
||||||
#print "parseNames, tmp after unicode latin-1 conversion:",tmp
|
|
||||||
result.append(tmp)
|
|
||||||
return result
|
|
||||||
#end def parseNames
|
#end def parseNames
|
||||||
|
|
||||||
def parsePositions(hand, names):
|
def parsePositions(hand, names):
|
||||||
positions = map(lambda x: -1, names)
|
positions = [-1 for i in names]
|
||||||
|
sb, bb = -1, -1
|
||||||
|
|
||||||
#find blinds
|
#find blinds
|
||||||
sb,bb=-1,-1
|
for line in hand:
|
||||||
for i in xrange (len(hand)):
|
if sb == -1 and "small blind" in line and "dead small blind" not in line:
|
||||||
if (sb==-1 and hand[i].find("small blind")!=-1 and hand[i].find("dead small blind")==-1):
|
sb = line
|
||||||
sb=hand[i]
|
if bb == -1 and "big blind" in line and "dead big blind" not in line:
|
||||||
#print "sb:",sb
|
bb = line
|
||||||
if (bb==-1 and hand[i].find("big blind")!=-1 and hand[i].find("dead big blind")==-1):
|
|
||||||
bb=hand[i]
|
|
||||||
#print "bb:",bb
|
|
||||||
|
|
||||||
#identify blinds
|
#identify blinds
|
||||||
#print "parsePositions before recognising sb/bb. names:",names
|
#print "parsePositions before recognising sb/bb. names:",names
|
||||||
sbExists = True
|
sbExists = True
|
||||||
if (sb!=-1):
|
if sb != -1:
|
||||||
sb = recognisePlayerNo(sb, names, "bet")
|
sb = recognisePlayerNo(sb, names, "bet")
|
||||||
else:
|
else:
|
||||||
sbExists = False
|
sbExists = False
|
||||||
if (bb!=-1):
|
if bb != -1:
|
||||||
bb = recognisePlayerNo(bb, names, "bet")
|
bb = recognisePlayerNo(bb, names, "bet")
|
||||||
|
|
||||||
# print "sb = ", sb, "bb = ", bb
|
# print "sb = ", sb, "bb = ", bb
|
||||||
if bb == sb:
|
if bb == sb: # if big and small are same, then don't duplicate the small
|
||||||
sbExists = False
|
sbExists = False
|
||||||
sb = -1
|
sb = -1
|
||||||
|
|
||||||
#write blinds into array
|
#write blinds into array
|
||||||
if (sbExists):
|
if sbExists:
|
||||||
positions[sb]="S"
|
positions[sb]="S"
|
||||||
positions[bb]="B"
|
positions[bb]="B"
|
||||||
|
|
||||||
|
|
||||||
#fill up rest of array
|
#fill up rest of array
|
||||||
if (sbExists):
|
if sbExists:
|
||||||
arraypos = sb-1
|
arraypos = sb-1
|
||||||
else:
|
else:
|
||||||
arraypos = bb-1
|
arraypos = bb-1
|
||||||
|
|
||||||
distFromBtn=0
|
distFromBtn=0
|
||||||
while (arraypos>=0 and arraypos != bb):
|
while arraypos >= 0 and arraypos != bb:
|
||||||
#print "parsePositions first while, arraypos:",arraypos,"positions:",positions
|
#print "parsePositions first while, arraypos:",arraypos,"positions:",positions
|
||||||
positions[arraypos] = distFromBtn
|
positions[arraypos] = distFromBtn
|
||||||
arraypos -= 1
|
arraypos -= 1
|
||||||
|
@ -1139,8 +1110,7 @@ def parsePositions(hand, names):
|
||||||
arraypos-=1
|
arraypos-=1
|
||||||
distFromBtn+=1
|
distFromBtn+=1
|
||||||
|
|
||||||
for i in xrange (len(names)):
|
if any(p == -1 for p in positions):
|
||||||
if positions[i]==-1:
|
|
||||||
print "parsePositions names:",names
|
print "parsePositions names:",names
|
||||||
print "result:",positions
|
print "result:",positions
|
||||||
raise FpdbError ("failed to read positions")
|
raise FpdbError ("failed to read positions")
|
||||||
|
@ -1184,8 +1154,9 @@ def parseTourneyNo(topline):
|
||||||
#parses a win/collect line. manipulates the passed array winnings, no explicit return
|
#parses a win/collect line. manipulates the passed array winnings, no explicit return
|
||||||
def parseWinLine(line, names, winnings, isTourney):
|
def parseWinLine(line, names, winnings, isTourney):
|
||||||
#print "parseWinLine: line:",line
|
#print "parseWinLine: line:",line
|
||||||
for i in xrange(len(names)):
|
for i,n in enumerate(names):
|
||||||
if (line.startswith(names[i].encode("latin-1"))): #found a winner
|
n = n.encode("latin-1")
|
||||||
|
if line.startswith(n):
|
||||||
if isTourney:
|
if isTourney:
|
||||||
pos1 = line.rfind("collected ") + 10
|
pos1 = line.rfind("collected ") + 10
|
||||||
pos2 = line.find(" ", pos1)
|
pos2 = line.find(" ", pos1)
|
||||||
|
@ -1335,21 +1306,49 @@ def recogniseTourneyTypeId(cursor, siteId, buyin, fee, knockout, rebuyOrAddon):
|
||||||
#end def recogniseTourneyTypeId
|
#end def recogniseTourneyTypeId
|
||||||
|
|
||||||
#returns the SQL ids of the names given in an array
|
#returns the SQL ids of the names given in an array
|
||||||
|
# TODO: if someone gets industrious, they should make the parts that use the output of this function deal with a dict
|
||||||
|
# { playername: id } instead of depending on it's relation to the positions list
|
||||||
|
# then this can be reduced in complexity a bit
|
||||||
|
|
||||||
def recognisePlayerIDs(cursor, names, site_id):
|
def recognisePlayerIDs(cursor, names, site_id):
|
||||||
result = []
|
cursor.execute("SELECT name,id FROM Players WHERE name='%s'" % "' OR name='".join(names)) # get all playerids by the names passed in
|
||||||
for i in xrange(len(names)):
|
ids = dict(cursor.fetchall()) # convert to dict
|
||||||
cursor.execute ("SELECT id FROM Players WHERE name=%s", (names[i],))
|
if len(ids) != len(names):
|
||||||
tmp=cursor.fetchall()
|
notfound = [n for n in names if n not in ids] # make list of names not in database
|
||||||
if (len(tmp)==0): #new player
|
if notfound: # insert them into database
|
||||||
cursor.execute ("INSERT INTO Players (name, siteId) VALUES (%s, %s)", (names[i], site_id))
|
cursor.executemany("INSERT INTO Players (name, siteId) VALUES (%s, "+str(site_id)+")", (notfound))
|
||||||
#print "Number of players rows inserted: %d" % cursor.rowcount
|
cursor.execute("SELECT name,id FROM Players WHERE name='%s'" % "' OR name='".join(notfound)) # get their new ids
|
||||||
cursor.execute ("SELECT id FROM Players WHERE name=%s", (names[i],))
|
tmp = dict(cursor.fetchall())
|
||||||
tmp=cursor.fetchall()
|
for n in tmp: # put them all into the same dict
|
||||||
#print "recognisePlayerIDs, names[i]:",names[i],"tmp:",tmp
|
ids[n] = tmp[n]
|
||||||
result.append(tmp[0][0])
|
|
||||||
return result
|
# return them in the SAME ORDER that they came in in the names argument, rather than the order they came out of the DB
|
||||||
|
return [ids[n] for n in names]
|
||||||
#end def recognisePlayerIDs
|
#end def recognisePlayerIDs
|
||||||
|
|
||||||
|
|
||||||
|
# Here's a version that would work if it wasn't for the fact that it needs to have the output in the same order as input
|
||||||
|
# this version could also be improved upon using list comprehensions, etc
|
||||||
|
|
||||||
|
#def recognisePlayerIDs(cursor, names, site_id):
|
||||||
|
# result = []
|
||||||
|
# notfound = []
|
||||||
|
# cursor.execute("SELECT name,id FROM Players WHERE name='%s'" % "' OR name='".join(names))
|
||||||
|
# tmp = dict(cursor.fetchall())
|
||||||
|
# for n in names:
|
||||||
|
# if n not in tmp:
|
||||||
|
# notfound.append(n)
|
||||||
|
# else:
|
||||||
|
# result.append(tmp[n])
|
||||||
|
# if notfound:
|
||||||
|
# cursor.executemany("INSERT INTO Players (name, siteId) VALUES (%s, "+str(site_id)+")", (notfound))
|
||||||
|
# cursor.execute("SELECT id FROM Players WHERE name='%s'" % "' OR name='".join(notfound))
|
||||||
|
# tmp = cursor.fetchall()
|
||||||
|
# for n in tmp:
|
||||||
|
# result.append(n[0])
|
||||||
|
#
|
||||||
|
# return result
|
||||||
|
|
||||||
#recognises the name in the given line and returns its array position in the given array
|
#recognises the name in the given line and returns its array position in the given array
|
||||||
def recognisePlayerNo(line, names, atype):
|
def recognisePlayerNo(line, names, atype):
|
||||||
#print "recogniseplayerno, names:",names
|
#print "recogniseplayerno, names:",names
|
||||||
|
@ -2161,7 +2160,7 @@ def storeHudCache(cursor, base, category, gametypeId, playerIds, hudImportData):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
row=[]
|
row=[]
|
||||||
|
|
||||||
if (len(row)==0):
|
if not row:
|
||||||
#print "new huddata row"
|
#print "new huddata row"
|
||||||
doInsert=True
|
doInsert=True
|
||||||
row=[]
|
row=[]
|
||||||
|
@ -2174,9 +2173,11 @@ def storeHudCache(cursor, base, category, gametypeId, playerIds, hudImportData):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
doInsert=False
|
doInsert=False
|
||||||
|
# This is making a copy of the original list, although i really don't see any reason it's being done?
|
||||||
newrow=[]
|
newrow=[]
|
||||||
for i in xrange(len(row)):
|
newrow.extend(row)
|
||||||
newrow.append(row[i])
|
# for i in xrange(len(row)):
|
||||||
|
# newrow.append(row[i])
|
||||||
row=newrow
|
row=newrow
|
||||||
|
|
||||||
if base=="hold":
|
if base=="hold":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user