diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index dbdf159f..3fa5cc1d 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -37,20 +37,79 @@ from xml.dom.minidom import Node import logging, logging.config import ConfigParser -try: # local path - logging.config.fileConfig(os.path.join(sys.path[0],"logging.conf")) -except ConfigParser.NoSectionError: # debian package path - logging.config.fileConfig('/usr/share/python-fpdb/logging.conf') +############################################################################## +# Functions for finding config files and setting up logging +# Also used in other modules that use logging. + +def get_default_config_path(): + """Returns the path where the fpdb config file _should_ be stored.""" + if os.name == 'posix': + config_path = os.path.join(os.path.expanduser("~"), '.fpdb') + elif os.name == 'nt': + config_path = os.path.join(os.environ["APPDATA"], 'fpdb') + else: config_path = False + return config_path + +def get_exec_path(): + """Returns the path to the fpdb.(py|exe) file we are executing""" + if hasattr(sys, "frozen"): # compiled by py2exe + return os.path.dirname(sys.executable) + else: + return os.path.dirname(sys.path[0]) + +def get_config(file_name, fallback = True): + """Looks in cwd and in self.default_config_path for a config file.""" + config_path = os.path.join(get_exec_path(), file_name) + if os.path.exists(config_path): # there is a file in the cwd + return config_path # so we use it + else: # no file in the cwd, look where it should be in the first place + config_path = os.path.join(get_default_config_path(), file_name) + if os.path.exists(config_path): + return config_path + +# No file found + if not fallback: + return False + +# OK, fall back to the .example file, should be in the start dir + if os.path.exists(file_name + ".example"): + try: + shutil.copyfile(file_name + ".example", file_name) + print "No %s found, using %s.example.\n" % (file_name, file_name) + print "A %s file has been created. You will probably have to edit it." % file_name + sys.stderr.write("No %s found, using %s.example.\n" % (file_name, file_name) ) + except: + print "No %s found, cannot fall back. Exiting.\n" % file_name + sys.stderr.write("No %s found, cannot fall back. Exiting.\n" % file_name) + sys.exit() + return file_name + +def get_logger(file_name, config = "config", fallback = False): + conf = get_config(file_name, fallback = fallback) + if conf: + try: + logging.config.fileConfig(conf) + log = logging.getLogger(config) + log.debug("%s logger initialised" % config) + return log + except: + pass + + log = logging.basicConfig() + log = logging.getLogger() + log.debug("config logger initialised") + return log + +# find a logging.conf file and set up logging +log = get_logger("logging.conf") -log = logging.getLogger("config") -log.debug("config logger initialised") ######################################################################## # application wide consts APPLICATION_NAME_SHORT = 'fpdb' APPLICATION_VERSION = 'xx.xx.xx' -DIR_SELF = os.path.dirname(os.path.abspath(__file__)) +DIR_SELF = os.path.dirname(get_exec_path()) #TODO: imo no good idea to place 'database' in parent dir DIR_DATABASES = os.path.join(os.path.dirname(DIR_SELF), 'database') @@ -302,16 +361,16 @@ class HudUI: self.node = node self.label = node.getAttribute('label') # + self.hud_style = node.getAttribute('stat_range') + self.hud_days = node.getAttribute('stat_days') self.aggregate_ring = string_to_bool(node.getAttribute('aggregate_ring_game_stats')) self.aggregate_tour = string_to_bool(node.getAttribute('aggregate_tourney_stats')) - self.hud_style = node.getAttribute('stat_aggregation_range') - self.hud_days = node.getAttribute('aggregation_days') self.agg_bb_mult = node.getAttribute('aggregation_level_multiplier') # - self.h_aggregate_ring = string_to_bool(node.getAttribute('aggregate_hero_ring_game_stats')) - self.h_aggregate_tour = string_to_bool(node.getAttribute('aggregate_hero_tourney_stats')) - self.h_hud_style = node.getAttribute('hero_stat_aggregation_range') - self.h_hud_days = node.getAttribute('hero_aggregation_days') + self.h_hud_style = node.getAttribute('hero_stat_range') + self.h_hud_days = node.getAttribute('hero_stat_days') + self.h_aggregate_ring = string_to_bool(node.getAttribute('aggregate_hero_ring_game_stats')) + self.h_aggregate_tour = string_to_bool(node.getAttribute('aggregate_hero_tourney_stats')) self.h_agg_bb_mult = node.getAttribute('hero_aggregation_level_multiplier') @@ -335,7 +394,7 @@ class Config: # "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 - self.default_config_path = self.get_default_config_path() +# self.default_config_path = self.get_default_config_path() if file is not None: # config file path passed in file = os.path.expanduser(file) if not os.path.exists(file): @@ -343,28 +402,12 @@ class Config: sys.stderr.write("Configuration file %s not found. Using defaults." % (file)) file = None - if file is None: # configuration file path not passed or invalid - file = self.find_config() #Look for a config file in the normal places - - if file is None: # no config file in the normal places - file = self.find_example_config() #Look for an example file to edit - - if file is None: # that didn't work either, just die - print "No HUD_config_xml found after looking in current directory and "+self.default_config_path+"\nExiting" - sys.stderr.write("No HUD_config_xml found after looking in current directory and "+self.default_config_path+"\nExiting") - print "press enter to continue" - sys.stdin.readline() - sys.exit() + if file is None: file = get_config("HUD_config.xml") # Parse even if there was no real config file found and we are using the example # If using the example, we'll edit it later -# sc 2009/10/04 Example already copied to main filename, is this ok? log.info("Reading configuration file %s" % file) - if os.sep in file: - print "\nReading configuration file %s\n" % file - else: - print "\nReading configuration file %s" % file - print "in %s\n" % os.getcwd() + print "\nReading configuration file %s\n" % file try: doc = xml.dom.minidom.parse(file) except: @@ -460,28 +503,6 @@ class Config: def set_hhArchiveBase(self, path): self.imp.node.setAttribute("hhArchiveBase", path) - def find_config(self): - """Looks in cwd and in self.default_config_path for a config file.""" - if os.path.exists('HUD_config.xml'): # there is a HUD_config in the cwd - file = 'HUD_config.xml' # so we use it - else: # no HUD_config in the cwd, look where it should be in the first place - config_path = os.path.join(self.default_config_path, 'HUD_config.xml') - if os.path.exists(config_path): - file = config_path - else: - file = None - return file - - def get_default_config_path(self): - """Returns the path where the fpdb config file _should_ be stored.""" - if os.name == 'posix': - config_path = os.path.join(os.path.expanduser("~"), '.fpdb') - elif os.name == 'nt': - config_path = os.path.join(os.environ["APPDATA"], 'fpdb') - else: config_path = None - return config_path - - def find_default_conf(self): if os.name == 'posix': config_path = os.path.join(os.path.expanduser("~"), '.fpdb', 'default.conf') @@ -495,30 +516,6 @@ class Config: file = None return file - def read_default_conf(self, file): - parms = {} - with open(file, "r") as fh: - for line in fh: - line = string.strip(line) - (key, value) = line.split('=') - parms[key] = value - return parms - - def find_example_config(self): - if os.path.exists('HUD_config.xml.example'): # there is a HUD_config in the cwd - file = 'HUD_config.xml' # so we use it - try: - shutil.copyfile(file+'.example', file) - except: - file = '' - print "No HUD_config.xml found, using HUD_config.xml.example.\n", \ - "A HUD_config.xml has been created. You will probably have to edit it." - sys.stderr.write("No HUD_config.xml found, using HUD_config.xml.example.\n" + \ - "A HUD_config.xml has been created. You will probably have to edit it.") - else: - file = None - return file - def get_site_node(self, site): for site_node in self.doc.getElementsByTagName("site"): if site_node.getAttribute("site_name") == site: @@ -948,3 +945,7 @@ if __name__== "__main__": print c.get_game_parameters(game) print "start up path = ", c.execution_path("") + + from xml.dom.ext import PrettyPrint + for site_node in c.doc.getElementsByTagName("site"): + PrettyPrint(site_node, stream=sys.stdout, encoding="utf-8") diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 61b91729..07b7a4d4 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -45,16 +45,7 @@ import Card import Tourney from Exceptions import * -import logging, logging.config -import ConfigParser - -try: # local path - logging.config.fileConfig(os.path.join(sys.path[0],"logging.conf")) -except ConfigParser.NoSectionError: # debian package path - logging.config.fileConfig('/usr/share/python-fpdb/logging.conf') - -log = logging.getLogger('db') - +log = Configuration.get_logger("logging.conf") class Database: @@ -441,16 +432,14 @@ class Database: print "*** Database Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1]) def get_stats_from_hand( self, hand, type # type is "ring" or "tour" - , hud_params = {'aggregate_tour':False, 'aggregate_ring':False, 'hud_style':'A', 'hud_days':30, 'agg_bb_mult':100 - ,'h_aggregate_tour':False, 'h_aggregate_ring':False, 'h_hud_style':'S', 'h_hud_days':30, 'h_agg_bb_mult':100} + , hud_params = {'hud_style':'A', 'agg_bb_mult':1000 + ,'h_hud_style':'S', 'h_agg_bb_mult':1000} , hero_id = -1 ): - aggregate = hud_params['aggregate_tour'] if type == "tour" else hud_params['aggregate_ring'] hud_style = hud_params['hud_style'] - agg_bb_mult = hud_params['agg_bb_mult'] if aggregate else 1 - h_aggregate = hud_params['h_aggregate_tour'] if type == "tour" else hud_params['h_aggregate_ring'] + agg_bb_mult = hud_params['agg_bb_mult'] h_hud_style = hud_params['h_hud_style'] - h_agg_bb_mult = hud_params['h_agg_bb_mult'] if h_aggregate else 1 + h_agg_bb_mult = hud_params['h_agg_bb_mult'] stat_dict = {} if hud_style == 'S' or h_hud_style == 'S': @@ -477,13 +466,8 @@ class Database: #elif h_hud_style == 'H': # h_stylekey = date_nhands_ago needs array by player here ... - #if aggregate: always use aggregate query now: use agg_bb_mult of 1 for no aggregation: query = 'get_stats_from_hand_aggregated' subs = (hand, hero_id, stylekey, agg_bb_mult, agg_bb_mult, hero_id, h_stylekey, h_agg_bb_mult, h_agg_bb_mult) - #print "agg query subs:", subs - #else: - # query = 'get_stats_from_hand' - # subs = (hand, stylekey) #print "get stats: hud style =", hud_style, "query =", query, "subs =", subs c = self.connection.cursor() @@ -1393,6 +1377,12 @@ class Database: pids[p], pdata[p]['startCash'], pdata[p]['seatNo'], + pdata[p]['winnings'], + pdata[p]['street0VPI'], + pdata[p]['street1Seen'], + pdata[p]['street2Seen'], + pdata[p]['street3Seen'], + pdata[p]['street4Seen'], pdata[p]['street0Aggr'], pdata[p]['street1Aggr'], pdata[p]['street2Aggr'], @@ -1405,6 +1395,12 @@ class Database: playerId, startCash, seatNo, + winnings, + street0VPI, + street1Seen, + street2Seen, + street3Seen, + street4Seen, street0Aggr, street1Aggr, street2Aggr, @@ -1413,7 +1409,8 @@ class Database: ) VALUES ( %s, %s, %s, %s, %s, - %s, %s, %s, %s + %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s )""" # position, @@ -1423,16 +1420,10 @@ class Database: # card3, # card4, # startCards, -# winnings, # rake, # totalProfit, -# street0VPI, # street0_3BChance, # street0_3BDone, -# street1Seen, -# street2Seen, -# street3Seen, -# street4Seen, # sawShowdown, # otherRaisedStreet1, # otherRaisedStreet2, @@ -2683,13 +2674,11 @@ class HandToWrite: if __name__=="__main__": c = Configuration.Config() - db_connection = Database(c, 'fpdb', 'holdem') # mysql fpdb holdem + db_connection = Database(c) # mysql fpdb holdem # db_connection = Database(c, 'fpdb-p', 'test') # mysql fpdb holdem # db_connection = Database(c, 'PTrackSv2', 'razz') # mysql razz # db_connection = Database(c, 'ptracks', 'razz') # postgres print "database connection object = ", db_connection.connection - print "database type = ", db_connection.type - db_connection.recreate_tables() h = db_connection.get_last_hand() @@ -2703,18 +2692,12 @@ if __name__=="__main__": for p in stat_dict.keys(): print p, " ", stat_dict[p] - #print "nutOmatics stats:" - #stat_dict = db_connection.get_stats_from_hand(h, "ring") - #for p in stat_dict.keys(): - # print p, " ", stat_dict[p] - print "cards =", db_connection.get_cards(u'1') db_connection.close_connection print "press enter to continue" sys.stdin.readline() - #Code borrowed from http://push.cx/2008/caching-dictionaries-in-python-vs-ruby class LambdaDict(dict): def __init__(self, l): diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index 56b0d489..43220c4b 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -18,6 +18,13 @@ #fpdb modules import Card +DEBUG = True + +if DEBUG: + import pprint + pp = pprint.PrettyPrinter(indent=4) + + class DerivedStats(): def __init__(self, hand): self.hand = hand @@ -30,13 +37,19 @@ class DerivedStats(): for player in hand.players: self.handsplayers[player[1]] = {} #Init vars that may not be used, but still need to be inserted. + # All stud street4 need this when importing holdem + self.handsplayers[player[1]]['winnings'] = 0 + self.handsplayers[player[1]]['street4Seen'] = False self.handsplayers[player[1]]['street4Aggr'] = False self.assembleHands(self.hand) self.assembleHandsPlayers(self.hand) - - print "hands =", self.hands - print "handsplayers =", self.handsplayers + + if DEBUG: + print "Hands:" + pp.pprint(self.hands) + print "HandsPlayers:" + pp.pprint(self.handsplayers) def getHands(self): return self.hands @@ -85,703 +98,25 @@ class DerivedStats(): # commentTs DATETIME def assembleHandsPlayers(self, hand): + #street0VPI/vpip already called in Hand #hand.players = [[seat, name, chips],[seat, name, chips]] for player in hand.players: self.handsplayers[player[1]]['seatNo'] = player[0] self.handsplayers[player[1]]['startCash'] = player[2] + # Winnings is a non-negative value of money collected from the pot, which already includes the + # rake taken out. hand.collectees is Decimal, database requires cents + for player in hand.collectees: + self.handsplayers[player]['winnings'] = int(100 * hand.collectees[player]) + + for i, street in enumerate(hand.actionStreets[2:]): + self.seen(self.hand, i+1) + for i, street in enumerate(hand.actionStreets[1:]): self.aggr(self.hand, i) def assembleHudCache(self, hand): -# # def generateHudCacheData(player_ids, base, category, action_types, allIns, actionTypeByNo -# # ,winnings, totalWinnings, positions, actionTypes, actionAmounts, antes): -# #"""calculates data for the HUD during import. IMPORTANT: if you change this method make -# # sure to also change the following storage method and table_viewer.prepare_data if necessary -# #""" -# #print "generateHudCacheData, len(player_ids)=", len(player_ids) -# #setup subarrays of the result dictionary. -# street0VPI=[] -# street0Aggr=[] -# street0_3BChance=[] -# street0_3BDone=[] -# street1Seen=[] -# street2Seen=[] -# street3Seen=[] -# street4Seen=[] -# sawShowdown=[] -# street1Aggr=[] -# street2Aggr=[] -# street3Aggr=[] -# street4Aggr=[] -# otherRaisedStreet1=[] -# otherRaisedStreet2=[] -# otherRaisedStreet3=[] -# otherRaisedStreet4=[] -# foldToOtherRaisedStreet1=[] -# foldToOtherRaisedStreet2=[] -# foldToOtherRaisedStreet3=[] -# foldToOtherRaisedStreet4=[] -# wonWhenSeenStreet1=[] -# -# wonAtSD=[] -# stealAttemptChance=[] -# stealAttempted=[] -# hudDataPositions=[] -# -# street0Calls=[] -# street1Calls=[] -# street2Calls=[] -# street3Calls=[] -# street4Calls=[] -# street0Bets=[] -# street1Bets=[] -# street2Bets=[] -# street3Bets=[] -# street4Bets=[] -# #street0Raises=[] -# #street1Raises=[] -# #street2Raises=[] -# #street3Raises=[] -# #street4Raises=[] -# -# # Summary figures for hand table: -# result={} -# result['playersVpi']=0 -# result['playersAtStreet1']=0 -# result['playersAtStreet2']=0 -# result['playersAtStreet3']=0 -# result['playersAtStreet4']=0 -# result['playersAtShowdown']=0 -# result['street0Raises']=0 -# result['street1Raises']=0 -# result['street2Raises']=0 -# result['street3Raises']=0 -# result['street4Raises']=0 -# result['street1Pot']=0 -# result['street2Pot']=0 -# result['street3Pot']=0 -# result['street4Pot']=0 -# result['showdownPot']=0 -# -# firstPfRaiseByNo=-1 -# firstPfRaiserId=-1 -# firstPfRaiserNo=-1 -# firstPfCallByNo=-1 -# firstPfCallerId=-1 -# -# for i, action in enumerate(actionTypeByNo[0]): -# if action[1] == "bet": -# firstPfRaiseByNo = i -# firstPfRaiserId = action[0] -# for j, pid in enumerate(player_ids): -# if pid == firstPfRaiserId: -# firstPfRaiserNo = j -# break -# break -# for i, action in enumerate(actionTypeByNo[0]): -# if action[1] == "call": -# firstPfCallByNo = i -# firstPfCallerId = action[0] -# break -# firstPlayId = firstPfCallerId -# if firstPfRaiseByNo <> -1: -# if firstPfRaiseByNo < firstPfCallByNo or firstPfCallByNo == -1: -# firstPlayId = firstPfRaiserId -# -# -# cutoffId=-1 -# buttonId=-1 -# sbId=-1 -# bbId=-1 -# if base=="hold": -# for player, pos in enumerate(positions): -# if pos == 1: -# cutoffId = player_ids[player] -# if pos == 0: -# buttonId = player_ids[player] -# if pos == 'S': -# sbId = player_ids[player] -# if pos == 'B': -# bbId = player_ids[player] -# -# someoneStole=False -# -# #run a loop for each player preparing the actual values that will be commited to SQL -# for player in xrange(len(player_ids)): -# #set default values -# myStreet0VPI=False -# myStreet0Aggr=False -# myStreet0_3BChance=False -# myStreet0_3BDone=False -# myStreet1Seen=False -# myStreet2Seen=False -# myStreet3Seen=False -# myStreet4Seen=False -# mySawShowdown=False -# myStreet1Aggr=False -# myStreet2Aggr=False -# myStreet3Aggr=False -# myStreet4Aggr=False -# myOtherRaisedStreet1=False -# myOtherRaisedStreet2=False -# myOtherRaisedStreet3=False -# myOtherRaisedStreet4=False -# myFoldToOtherRaisedStreet1=False -# myFoldToOtherRaisedStreet2=False -# myFoldToOtherRaisedStreet3=False -# myFoldToOtherRaisedStreet4=False -# myWonWhenSeenStreet1=0.0 -# myWonAtSD=0.0 -# myStealAttemptChance=False -# myStealAttempted=False -# myStreet0Calls=0 -# myStreet1Calls=0 -# myStreet2Calls=0 -# myStreet3Calls=0 -# myStreet4Calls=0 -# myStreet0Bets=0 -# myStreet1Bets=0 -# myStreet2Bets=0 -# myStreet3Bets=0 -# myStreet4Bets=0 -# #myStreet0Raises=0 -# #myStreet1Raises=0 -# #myStreet2Raises=0 -# #myStreet3Raises=0 -# #myStreet4Raises=0 -# -# #calculate VPIP and PFR -# street=0 -# heroPfRaiseCount=0 -# for currentAction in action_types[street][player]: # finally individual actions -# if currentAction == "bet": -# myStreet0Aggr = True -# if currentAction == "bet" or currentAction == "call": -# myStreet0VPI = True -# -# if myStreet0VPI: -# result['playersVpi'] += 1 -# myStreet0Calls = action_types[street][player].count('call') -# myStreet0Bets = action_types[street][player].count('bet') -# # street0Raises = action_types[street][player].count('raise') bet count includes raises for now -# result['street0Raises'] += myStreet0Bets -# -# #PF3BChance and PF3B -# pfFold=-1 -# pfRaise=-1 -# if firstPfRaiseByNo != -1: -# for i, actionType in enumerate(actionTypeByNo[0]): -# if actionType[0] == player_ids[player]: -# if actionType[1] == "bet" and pfRaise == -1 and i > firstPfRaiseByNo: -# pfRaise = i -# if actionType[1] == "fold" and pfFold == -1: -# pfFold = i -# if pfFold == -1 or pfFold > firstPfRaiseByNo: -# myStreet0_3BChance = True -# if pfRaise > firstPfRaiseByNo: -# myStreet0_3BDone = True -# -# #steal calculations -# if base=="hold": -# if len(player_ids)>=3: # no point otherwise # was 5, use 3 to match pokertracker definition -# if positions[player]==1: -# if firstPfRaiserId==player_ids[player] \ -# and (firstPfCallByNo==-1 or firstPfCallByNo>firstPfRaiseByNo): -# myStealAttempted=True -# myStealAttemptChance=True -# if firstPlayId==cutoffId or firstPlayId==buttonId or firstPlayId==sbId or firstPlayId==bbId or firstPlayId==-1: -# myStealAttemptChance=True -# if positions[player]==0: -# if firstPfRaiserId==player_ids[player] \ -# and (firstPfCallByNo==-1 or firstPfCallByNo>firstPfRaiseByNo): -# myStealAttempted=True -# myStealAttemptChance=True -# if firstPlayId==buttonId or firstPlayId==sbId or firstPlayId==bbId or firstPlayId==-1: -# myStealAttemptChance=True -# if positions[player]=='S': -# if firstPfRaiserId==player_ids[player] \ -# and (firstPfCallByNo==-1 or firstPfCallByNo>firstPfRaiseByNo): -# myStealAttempted=True -# myStealAttemptChance=True -# if firstPlayId==sbId or firstPlayId==bbId or firstPlayId==-1: -# myStealAttemptChance=True -# if positions[player]=='B': -# pass -# -# if myStealAttempted: -# someoneStole=True -# -# -# #calculate saw* values -# isAllIn = False -# if any(i for i in allIns[0][player]): -# isAllIn = True -# if (len(action_types[1][player])>0 or isAllIn): -# myStreet1Seen = True -# -# if any(i for i in allIns[1][player]): -# isAllIn = True -# if (len(action_types[2][player])>0 or isAllIn): -# myStreet2Seen = True -# -# if any(i for i in allIns[2][player]): -# isAllIn = True -# if (len(action_types[3][player])>0 or isAllIn): -# myStreet3Seen = True -# -# #print "base:", base -# if base=="hold": -# mySawShowdown = True -# if any(actiontype == "fold" for actiontype in action_types[3][player]): -# mySawShowdown = False -# else: -# #print "in else" -# if any(i for i in allIns[3][player]): -# isAllIn = True -# if (len(action_types[4][player])>0 or isAllIn): -# #print "in if" -# myStreet4Seen = True -# -# mySawShowdown = True -# if any(actiontype == "fold" for actiontype in action_types[4][player]): -# mySawShowdown = False -# -# if myStreet1Seen: -# result['playersAtStreet1'] += 1 -# if myStreet2Seen: -# result['playersAtStreet2'] += 1 -# if myStreet3Seen: -# result['playersAtStreet3'] += 1 -# if myStreet4Seen: -# result['playersAtStreet4'] += 1 -# if mySawShowdown: -# result['playersAtShowdown'] += 1 -# -# #flop stuff -# street=1 -# if myStreet1Seen: -# if any(actiontype == "bet" for actiontype in action_types[street][player]): -# myStreet1Aggr = True -# -# myStreet1Calls = action_types[street][player].count('call') -# myStreet1Bets = action_types[street][player].count('bet') -# # street1Raises = action_types[street][player].count('raise') bet count includes raises for now -# result['street1Raises'] += myStreet1Bets -# -# for otherPlayer in xrange(len(player_ids)): -# if player==otherPlayer: -# pass -# else: -# for countOther in xrange(len(action_types[street][otherPlayer])): -# if action_types[street][otherPlayer][countOther]=="bet": -# myOtherRaisedStreet1=True -# for countOtherFold in xrange(len(action_types[street][player])): -# if action_types[street][player][countOtherFold]=="fold": -# myFoldToOtherRaisedStreet1=True -# -# #turn stuff - copy of flop with different vars -# street=2 -# if myStreet2Seen: -# if any(actiontype == "bet" for actiontype in action_types[street][player]): -# myStreet2Aggr = True -# -# myStreet2Calls = action_types[street][player].count('call') -# myStreet2Bets = action_types[street][player].count('bet') -# # street2Raises = action_types[street][player].count('raise') bet count includes raises for now -# result['street2Raises'] += myStreet2Bets -# -# for otherPlayer in xrange(len(player_ids)): -# if player==otherPlayer: -# pass -# else: -# for countOther in xrange(len(action_types[street][otherPlayer])): -# if action_types[street][otherPlayer][countOther]=="bet": -# myOtherRaisedStreet2=True -# for countOtherFold in xrange(len(action_types[street][player])): -# if action_types[street][player][countOtherFold]=="fold": -# myFoldToOtherRaisedStreet2=True -# -# #river stuff - copy of flop with different vars -# street=3 -# if myStreet3Seen: -# if any(actiontype == "bet" for actiontype in action_types[street][player]): -# myStreet3Aggr = True -# -# myStreet3Calls = action_types[street][player].count('call') -# myStreet3Bets = action_types[street][player].count('bet') -# # street3Raises = action_types[street][player].count('raise') bet count includes raises for now -# result['street3Raises'] += myStreet3Bets -# -# for otherPlayer in xrange(len(player_ids)): -# if player==otherPlayer: -# pass -# else: -# for countOther in xrange(len(action_types[street][otherPlayer])): -# if action_types[street][otherPlayer][countOther]=="bet": -# myOtherRaisedStreet3=True -# for countOtherFold in xrange(len(action_types[street][player])): -# if action_types[street][player][countOtherFold]=="fold": -# myFoldToOtherRaisedStreet3=True -# -# #stud river stuff - copy of flop with different vars -# street=4 -# if myStreet4Seen: -# if any(actiontype == "bet" for actiontype in action_types[street][player]): -# myStreet4Aggr=True -# -# myStreet4Calls = action_types[street][player].count('call') -# myStreet4Bets = action_types[street][player].count('bet') -# # street4Raises = action_types[street][player].count('raise') bet count includes raises for now -# result['street4Raises'] += myStreet4Bets -# -# for otherPlayer in xrange(len(player_ids)): -# if player==otherPlayer: -# pass -# else: -# for countOther in xrange(len(action_types[street][otherPlayer])): -# if action_types[street][otherPlayer][countOther]=="bet": -# myOtherRaisedStreet4=True -# for countOtherFold in xrange(len(action_types[street][player])): -# if action_types[street][player][countOtherFold]=="fold": -# myFoldToOtherRaisedStreet4=True -# -# if winnings[player] != 0: -# if myStreet1Seen: -# myWonWhenSeenStreet1 = winnings[player] / float(totalWinnings) -# if mySawShowdown: -# myWonAtSD=myWonWhenSeenStreet1 -# -# #add each value to the appropriate array -# street0VPI.append(myStreet0VPI) -# street0Aggr.append(myStreet0Aggr) -# street0_3BChance.append(myStreet0_3BChance) -# street0_3BDone.append(myStreet0_3BDone) -# street1Seen.append(myStreet1Seen) -# street2Seen.append(myStreet2Seen) -# street3Seen.append(myStreet3Seen) -# street4Seen.append(myStreet4Seen) -# sawShowdown.append(mySawShowdown) -# street1Aggr.append(myStreet1Aggr) -# street2Aggr.append(myStreet2Aggr) -# street3Aggr.append(myStreet3Aggr) -# street4Aggr.append(myStreet4Aggr) -# otherRaisedStreet1.append(myOtherRaisedStreet1) -# otherRaisedStreet2.append(myOtherRaisedStreet2) -# otherRaisedStreet3.append(myOtherRaisedStreet3) -# otherRaisedStreet4.append(myOtherRaisedStreet4) -# foldToOtherRaisedStreet1.append(myFoldToOtherRaisedStreet1) -# foldToOtherRaisedStreet2.append(myFoldToOtherRaisedStreet2) -# foldToOtherRaisedStreet3.append(myFoldToOtherRaisedStreet3) -# foldToOtherRaisedStreet4.append(myFoldToOtherRaisedStreet4) -# wonWhenSeenStreet1.append(myWonWhenSeenStreet1) -# wonAtSD.append(myWonAtSD) -# stealAttemptChance.append(myStealAttemptChance) -# stealAttempted.append(myStealAttempted) -# if base=="hold": -# pos=positions[player] -# if pos=='B': -# hudDataPositions.append('B') -# elif pos=='S': -# hudDataPositions.append('S') -# elif pos==0: -# hudDataPositions.append('D') -# elif pos==1: -# hudDataPositions.append('C') -# elif pos>=2 and pos<=4: -# hudDataPositions.append('M') -# elif pos>=5 and pos<=8: -# hudDataPositions.append('E') -# ### RHH Added this elif to handle being a dead hand before the BB (pos==9) -# elif pos==9: -# hudDataPositions.append('X') -# else: -# raise FpdbError("invalid position") -# elif base=="stud": -# #todo: stud positions and steals -# pass -# -# street0Calls.append(myStreet0Calls) -# street1Calls.append(myStreet1Calls) -# street2Calls.append(myStreet2Calls) -# street3Calls.append(myStreet3Calls) -# street4Calls.append(myStreet4Calls) -# street0Bets.append(myStreet0Bets) -# street1Bets.append(myStreet1Bets) -# street2Bets.append(myStreet2Bets) -# street3Bets.append(myStreet3Bets) -# street4Bets.append(myStreet4Bets) -# #street0Raises.append(myStreet0Raises) -# #street1Raises.append(myStreet1Raises) -# #street2Raises.append(myStreet2Raises) -# #street3Raises.append(myStreet3Raises) -# #street4Raises.append(myStreet4Raises) -# -# #add each array to the to-be-returned dictionary -# result['street0VPI']=street0VPI -# result['street0Aggr']=street0Aggr -# result['street0_3BChance']=street0_3BChance -# result['street0_3BDone']=street0_3BDone -# result['street1Seen']=street1Seen -# result['street2Seen']=street2Seen -# result['street3Seen']=street3Seen -# result['street4Seen']=street4Seen -# result['sawShowdown']=sawShowdown -# -# result['street1Aggr']=street1Aggr -# result['otherRaisedStreet1']=otherRaisedStreet1 -# result['foldToOtherRaisedStreet1']=foldToOtherRaisedStreet1 -# result['street2Aggr']=street2Aggr -# result['otherRaisedStreet2']=otherRaisedStreet2 -# result['foldToOtherRaisedStreet2']=foldToOtherRaisedStreet2 -# result['street3Aggr']=street3Aggr -# result['otherRaisedStreet3']=otherRaisedStreet3 -# result['foldToOtherRaisedStreet3']=foldToOtherRaisedStreet3 -# result['street4Aggr']=street4Aggr -# result['otherRaisedStreet4']=otherRaisedStreet4 -# result['foldToOtherRaisedStreet4']=foldToOtherRaisedStreet4 -# result['wonWhenSeenStreet1']=wonWhenSeenStreet1 -# result['wonAtSD']=wonAtSD -# result['stealAttemptChance']=stealAttemptChance -# result['stealAttempted']=stealAttempted -# result['street0Calls']=street0Calls -# result['street1Calls']=street1Calls -# result['street2Calls']=street2Calls -# result['street3Calls']=street3Calls -# result['street4Calls']=street4Calls -# result['street0Bets']=street0Bets -# result['street1Bets']=street1Bets -# result['street2Bets']=street2Bets -# result['street3Bets']=street3Bets -# result['street4Bets']=street4Bets -# #result['street0Raises']=street0Raises -# #result['street1Raises']=street1Raises -# #result['street2Raises']=street2Raises -# #result['street3Raises']=street3Raises -# #result['street4Raises']=street4Raises -# -# #now the various steal values -# foldBbToStealChance=[] -# foldedBbToSteal=[] -# foldSbToStealChance=[] -# foldedSbToSteal=[] -# for player in xrange(len(player_ids)): -# myFoldBbToStealChance=False -# myFoldedBbToSteal=False -# myFoldSbToStealChance=False -# myFoldedSbToSteal=False -# -# if base=="hold": -# if someoneStole and (positions[player]=='B' or positions[player]=='S') and firstPfRaiserId!=player_ids[player]: -# street=0 -# for count in xrange(len(action_types[street][player])):#individual actions -# if positions[player]=='B': -# myFoldBbToStealChance=True -# if action_types[street][player][count]=="fold": -# myFoldedBbToSteal=True -# if positions[player]=='S': -# myFoldSbToStealChance=True -# if action_types[street][player][count]=="fold": -# myFoldedSbToSteal=True -# -# -# foldBbToStealChance.append(myFoldBbToStealChance) -# foldedBbToSteal.append(myFoldedBbToSteal) -# foldSbToStealChance.append(myFoldSbToStealChance) -# foldedSbToSteal.append(myFoldedSbToSteal) -# result['foldBbToStealChance']=foldBbToStealChance -# result['foldedBbToSteal']=foldedBbToSteal -# result['foldSbToStealChance']=foldSbToStealChance -# result['foldedSbToSteal']=foldedSbToSteal -# -# #now CB -# street1CBChance=[] -# street1CBDone=[] -# didStreet1CB=[] -# for player in xrange(len(player_ids)): -# myStreet1CBChance=False -# myStreet1CBDone=False -# -# if street0VPI[player]: -# myStreet1CBChance=True -# if street1Aggr[player]: -# myStreet1CBDone=True -# didStreet1CB.append(player_ids[player]) -# -# street1CBChance.append(myStreet1CBChance) -# street1CBDone.append(myStreet1CBDone) -# result['street1CBChance']=street1CBChance -# result['street1CBDone']=street1CBDone -# -# #now 2B -# street2CBChance=[] -# street2CBDone=[] -# didStreet2CB=[] -# for player in xrange(len(player_ids)): -# myStreet2CBChance=False -# myStreet2CBDone=False -# -# if street1CBDone[player]: -# myStreet2CBChance=True -# if street2Aggr[player]: -# myStreet2CBDone=True -# didStreet2CB.append(player_ids[player]) -# -# street2CBChance.append(myStreet2CBChance) -# street2CBDone.append(myStreet2CBDone) -# result['street2CBChance']=street2CBChance -# result['street2CBDone']=street2CBDone -# -# #now 3B -# street3CBChance=[] -# street3CBDone=[] -# didStreet3CB=[] -# for player in xrange(len(player_ids)): -# myStreet3CBChance=False -# myStreet3CBDone=False -# -# if street2CBDone[player]: -# myStreet3CBChance=True -# if street3Aggr[player]: -# myStreet3CBDone=True -# didStreet3CB.append(player_ids[player]) -# -# street3CBChance.append(myStreet3CBChance) -# street3CBDone.append(myStreet3CBDone) -# result['street3CBChance']=street3CBChance -# result['street3CBDone']=street3CBDone -# -# #and 4B -# street4CBChance=[] -# street4CBDone=[] -# didStreet4CB=[] -# for player in xrange(len(player_ids)): -# myStreet4CBChance=False -# myStreet4CBDone=False -# -# if street3CBDone[player]: -# myStreet4CBChance=True -# if street4Aggr[player]: -# myStreet4CBDone=True -# didStreet4CB.append(player_ids[player]) -# -# street4CBChance.append(myStreet4CBChance) -# street4CBDone.append(myStreet4CBDone) -# result['street4CBChance']=street4CBChance -# result['street4CBDone']=street4CBDone -# -# -# result['position']=hudDataPositions -# -# foldToStreet1CBChance=[] -# foldToStreet1CBDone=[] -# foldToStreet2CBChance=[] -# foldToStreet2CBDone=[] -# foldToStreet3CBChance=[] -# foldToStreet3CBDone=[] -# foldToStreet4CBChance=[] -# foldToStreet4CBDone=[] -# -# for player in xrange(len(player_ids)): -# myFoldToStreet1CBChance=False -# myFoldToStreet1CBDone=False -# foldToStreet1CBChance.append(myFoldToStreet1CBChance) -# foldToStreet1CBDone.append(myFoldToStreet1CBDone) -# -# myFoldToStreet2CBChance=False -# myFoldToStreet2CBDone=False -# foldToStreet2CBChance.append(myFoldToStreet2CBChance) -# foldToStreet2CBDone.append(myFoldToStreet2CBDone) -# -# myFoldToStreet3CBChance=False -# myFoldToStreet3CBDone=False -# foldToStreet3CBChance.append(myFoldToStreet3CBChance) -# foldToStreet3CBDone.append(myFoldToStreet3CBDone) -# -# myFoldToStreet4CBChance=False -# myFoldToStreet4CBDone=False -# foldToStreet4CBChance.append(myFoldToStreet4CBChance) -# foldToStreet4CBDone.append(myFoldToStreet4CBDone) -# -# if len(didStreet1CB)>=1: -# generateFoldToCB(1, player_ids, didStreet1CB, street1CBDone, foldToStreet1CBChance, foldToStreet1CBDone, actionTypeByNo) -# -# if len(didStreet2CB)>=1: -# generateFoldToCB(2, player_ids, didStreet2CB, street2CBDone, foldToStreet2CBChance, foldToStreet2CBDone, actionTypeByNo) -# -# if len(didStreet3CB)>=1: -# generateFoldToCB(3, player_ids, didStreet3CB, street3CBDone, foldToStreet3CBChance, foldToStreet3CBDone, actionTypeByNo) -# -# if len(didStreet4CB)>=1: -# generateFoldToCB(4, player_ids, didStreet4CB, street4CBDone, foldToStreet4CBChance, foldToStreet4CBDone, actionTypeByNo) -# -# result['foldToStreet1CBChance']=foldToStreet1CBChance -# result['foldToStreet1CBDone']=foldToStreet1CBDone -# result['foldToStreet2CBChance']=foldToStreet2CBChance -# result['foldToStreet2CBDone']=foldToStreet2CBDone -# result['foldToStreet3CBChance']=foldToStreet3CBChance -# result['foldToStreet3CBDone']=foldToStreet3CBDone -# result['foldToStreet4CBChance']=foldToStreet4CBChance -# result['foldToStreet4CBDone']=foldToStreet4CBDone -# -# -# totalProfit=[] -# -# street1CheckCallRaiseChance=[] -# street1CheckCallRaiseDone=[] -# street2CheckCallRaiseChance=[] -# street2CheckCallRaiseDone=[] -# street3CheckCallRaiseChance=[] -# street3CheckCallRaiseDone=[] -# street4CheckCallRaiseChance=[] -# street4CheckCallRaiseDone=[] -# #print "b4 totprof calc, len(playerIds)=", len(player_ids) -# for pl in xrange(len(player_ids)): -# #print "pl=", pl -# myTotalProfit=winnings[pl] # still need to deduct other costs -# if antes: -# myTotalProfit=winnings[pl] - antes[pl] -# for i in xrange(len(actionTypes)): #iterate through streets -# #for j in xrange(len(actionTypes[i])): #iterate through names (using pl loop above) -# for k in xrange(len(actionTypes[i][pl])): #iterate through individual actions of that player on that street -# myTotalProfit -= actionAmounts[i][pl][k] -# -# myStreet1CheckCallRaiseChance=False -# myStreet1CheckCallRaiseDone=False -# myStreet2CheckCallRaiseChance=False -# myStreet2CheckCallRaiseDone=False -# myStreet3CheckCallRaiseChance=False -# myStreet3CheckCallRaiseDone=False -# myStreet4CheckCallRaiseChance=False -# myStreet4CheckCallRaiseDone=False -# -# #print "myTotalProfit=", myTotalProfit -# totalProfit.append(myTotalProfit) -# #print "totalProfit[]=", totalProfit -# -# street1CheckCallRaiseChance.append(myStreet1CheckCallRaiseChance) -# street1CheckCallRaiseDone.append(myStreet1CheckCallRaiseDone) -# street2CheckCallRaiseChance.append(myStreet2CheckCallRaiseChance) -# street2CheckCallRaiseDone.append(myStreet2CheckCallRaiseDone) -# street3CheckCallRaiseChance.append(myStreet3CheckCallRaiseChance) -# street3CheckCallRaiseDone.append(myStreet3CheckCallRaiseDone) -# street4CheckCallRaiseChance.append(myStreet4CheckCallRaiseChance) -# street4CheckCallRaiseDone.append(myStreet4CheckCallRaiseDone) -# -# result['totalProfit']=totalProfit -# #print "res[totalProfit]=", result['totalProfit'] -# -# result['street1CheckCallRaiseChance']=street1CheckCallRaiseChance -# result['street1CheckCallRaiseDone']=street1CheckCallRaiseDone -# result['street2CheckCallRaiseChance']=street2CheckCallRaiseChance -# result['street2CheckCallRaiseDone']=street2CheckCallRaiseDone -# result['street3CheckCallRaiseChance']=street3CheckCallRaiseChance -# result['street3CheckCallRaiseDone']=street3CheckCallRaiseDone -# result['street4CheckCallRaiseChance']=street4CheckCallRaiseChance -# result['street4CheckCallRaiseDone']=street4CheckCallRaiseDone -# return result -# #end def generateHudCacheData pass def vpip(self, hand): @@ -794,9 +129,9 @@ class DerivedStats(): for player in hand.players: if player[1] in vpipers: - self.handsplayers[player[1]]['vpip'] = True + self.handsplayers[player[1]]['street0VPI'] = True else: - self.handsplayers[player[1]]['vpip'] = False + self.handsplayers[player[1]]['street0VPI'] = False def playersAtStreetX(self, hand): """ playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4/draw1 */""" @@ -833,6 +168,17 @@ class DerivedStats(): self.hands['street3Raises'] = 0 # /* num big bets paid to see sd/street7 */ self.hands['street4Raises'] = 0 # /* num big bets paid to see showdown */ + def seen(self, hand, i): + pas = set() + for act in hand.actions[hand.actionStreets[i+1]]: + pas.add(act[0]) + + for player in hand.players: + if player[1] in pas: + self.handsplayers[player[1]]['street%sSeen' % i] = True + else: + self.handsplayers[player[1]]['street%sSeen' % i] = False + def aggr(self, hand, i): aggrers = set() for act in hand.actions[hand.actionStreets[i]]: diff --git a/pyfpdb/Exceptions.py b/pyfpdb/Exceptions.py index eaf5d798..f7e9fa54 100644 --- a/pyfpdb/Exceptions.py +++ b/pyfpdb/Exceptions.py @@ -9,8 +9,8 @@ class FpdbParseError(FpdbError): self.value = value self.hid = hid def __str__(self): - if hid: - return repr("HID:"+hid+", "+self.value) + if self.hid: + return repr("HID:"+self.hid+", "+self.value) else: return repr(self.value) diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index 8b5f1f05..53eac73f 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -544,7 +544,7 @@ class GuiPlayerStats (threading.Thread): # set flag in self.columns to show posn column [x for x in self.columns if x[0] == 'plposition'][0][1] = True else: - query = query.replace("", "'1'") + query = query.replace("", "gt.base") # unset flag in self.columns to hide posn column [x for x in self.columns if x[0] == 'plposition'][0][1] = False diff --git a/pyfpdb/HUD_config.xml.example b/pyfpdb/HUD_config.xml.example index 952a0dbf..b0f26c53 100644 --- a/pyfpdb/HUD_config.xml.example +++ b/pyfpdb/HUD_config.xml.example @@ -4,91 +4,95 @@ - [.0-9]+)" % subst, re.MULTILINE) self.re_PostBB = re.compile(r"^%(PLYR)s: posts big blind %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) self.re_Antes = re.compile(r"^%(PLYR)s: posts the ante %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) @@ -186,7 +186,7 @@ class PokerStars(HandHistoryConverter): # m = self.re_Button.search(hand.handText) # if m: info.update(m.groupdict()) # TODO : I rather like the idea of just having this dict as hand.info - logging.debug("readHandInfo: %s" % info) + log.debug("readHandInfo: %s" % info) for key in info: if key == 'DATETIME': #2008/11/12 10:00:48 CET [2008/11/12 4:00:48 ET] @@ -226,10 +226,10 @@ class PokerStars(HandHistoryConverter): if m: hand.buttonpos = int(m.group('BUTTON')) else: - logging.info('readButton: not found') + log.info('readButton: not found') def readPlayerStacks(self, hand): - logging.debug("readPlayerStacks") + log.debug("readPlayerStacks") m = self.re_PlayerInfo.finditer(hand.handText) players = [] for a in m: @@ -265,7 +265,7 @@ class PokerStars(HandHistoryConverter): hand.setCommunityCards(street, m.group('CARDS').split(' ')) def readAntes(self, hand): - logging.debug("reading antes") + log.debug("reading antes") m = self.re_Antes.finditer(hand.handText) for player in m: #~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE'))) diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index e8e93ed3..9c74e1f1 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -33,312 +33,295 @@ import re class Sql: - def __init__(self, game = 'holdem', type = 'fpdb', db_server = 'mysql'): + def __init__(self, game = 'holdem', db_server = 'mysql'): self.query = {} ###############################################################################3 # Support for the Free Poker DataBase = fpdb http://fpdb.sourceforge.net/ # - if type == 'fpdb': - ################################ - # List tables - ################################ - if db_server == 'mysql': - self.query['list_tables'] = """SHOW TABLES""" - elif db_server == 'postgresql': - self.query['list_tables'] = """SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'""" - elif db_server == 'sqlite': - self.query['list_tables'] = """SELECT name FROM sqlite_master - WHERE type='table' - ORDER BY name;""" + ################################ + # List tables + ################################ + if db_server == 'mysql': + self.query['list_tables'] = """SHOW TABLES""" + elif db_server == 'postgresql': + self.query['list_tables'] = """SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'""" + elif db_server == 'sqlite': + self.query['list_tables'] = """SELECT name FROM sqlite_master + WHERE type='table' + ORDER BY name;""" - ################################################################## - # Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax - ################################################################## + ################################################################## + # Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax + ################################################################## - self.query['drop_table'] = """DROP TABLE IF EXISTS """ + self.query['drop_table'] = """DROP TABLE IF EXISTS """ - ################################ - # Create Settings - ################################ - if db_server == 'mysql': - self.query['createSettingsTable'] = """CREATE TABLE Settings ( - version SMALLINT NOT NULL) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT NOT NULL)""" + ################################ + # Create Settings + ################################ + if db_server == 'mysql': + self.query['createSettingsTable'] = """CREATE TABLE Settings ( + version SMALLINT NOT NULL) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createSettingsTable'] = """CREATE TABLE Settings (version SMALLINT NOT NULL)""" - elif db_server == 'sqlite': - self.query['createSettingsTable'] = """CREATE TABLE Settings - (version INTEGER NOT NULL) """ + elif db_server == 'sqlite': + self.query['createSettingsTable'] = """CREATE TABLE Settings + (version INTEGER NOT NULL) """ - ################################ - # Create Sites - ################################ + ################################ + # Create Sites + ################################ - if db_server == 'mysql': - self.query['createSitesTable'] = """CREATE TABLE Sites ( - id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - name varchar(32) NOT NULL, - currency char(3) NOT NULL) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createSitesTable'] = """CREATE TABLE Sites ( - id SERIAL, PRIMARY KEY (id), - name varchar(32), - currency char(3))""" - elif db_server == 'sqlite': - self.query['createSitesTable'] = """CREATE TABLE Sites ( + if db_server == 'mysql': + self.query['createSitesTable'] = """CREATE TABLE Sites ( + id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + name varchar(32) NOT NULL, + currency char(3) NOT NULL) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createSitesTable'] = """CREATE TABLE Sites ( + id SERIAL, PRIMARY KEY (id), + name varchar(32), + currency char(3))""" + elif db_server == 'sqlite': + self.query['createSitesTable'] = """CREATE TABLE Sites ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + currency TEXT NOT NULL)""" + + + ################################ + # Create Gametypes + ################################ + + if db_server == 'mysql': + self.query['createGametypesTable'] = """CREATE TABLE Gametypes ( + id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), + type char(4) NOT NULL, + base char(4) NOT NULL, + category varchar(9) NOT NULL, + limitType char(2) NOT NULL, + hiLo char(1) NOT NULL, + smallBlind int, + bigBlind int, + smallBet int NOT NULL, + bigBet int NOT NULL) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createGametypesTable'] = """CREATE TABLE Gametypes ( + id SERIAL, PRIMARY KEY (id), + siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id), + type char(4), + base char(4), + category varchar(9), + limitType char(2), + hiLo char(1), + smallBlind int, + bigBlind int, + smallBet int, + bigBet int)""" + elif db_server == 'sqlite': + self.query['createGametypesTable'] = """CREATE TABLE GameTypes ( + id INTEGER PRIMARY KEY, + siteId INTEGER, + type TEXT, + base TEXT, + category TEXT, + limitType TEXT, + hiLo TEXT, + smallBlind INTEGER, + bigBlind INTEGER, + smallBet INTEGER, + bigBet INTEGER, + FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)""" + + + ################################ + # Create Players + ################################ + + if db_server == 'mysql': + self.query['createPlayersTable'] = """CREATE TABLE Players ( + id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + name VARCHAR(32) CHARACTER SET utf8 NOT NULL, + siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), + comment text, + commentTs DATETIME) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createPlayersTable'] = """CREATE TABLE Players ( + id SERIAL, PRIMARY KEY (id), + name VARCHAR(32), + siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id), + comment text, + commentTs timestamp without time zone)""" + elif db_server == 'sqlite': + self.query['createPlayersTable'] = """CREATE TABLE Players ( + id INTEGER PRIMARY KEY, + name TEXT, + siteId INTEGER, + comment TEXT, + commentTs REAL, + FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)""" + + + ################################ + # Create Autorates + ################################ + + if db_server == 'mysql': + self.query['createAutoratesTable'] = """CREATE TABLE Autorates ( + id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), + gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), + description varchar(50) NOT NULL, + shortDesc char(8) NOT NULL, + ratingTime DATETIME NOT NULL, + handCount int NOT NULL) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createAutoratesTable'] = """CREATE TABLE Autorates ( + id BIGSERIAL, PRIMARY KEY (id), + playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id), + gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), + description varchar(50), + shortDesc char(8), + ratingTime timestamp without time zone, + handCount int)""" + elif db_server == 'sqlite': + self.query['createAutoratesTable'] = """CREATE TABLE Autorates ( id INTEGER PRIMARY KEY, - name TEXT NOT NULL, - currency TEXT NOT NULL)""" + playerId INT, + gametypeId INT, + description TEXT, + shortDesc TEXT, + ratingTime REAL, + handCount int)""" - ################################ - # Create Gametypes - ################################ + ################################ + # Create Hands + ################################ - if db_server == 'mysql': - self.query['createGametypesTable'] = """CREATE TABLE Gametypes ( + if db_server == 'mysql': + self.query['createHandsTable'] = """CREATE TABLE Hands ( + id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + tableName VARCHAR(22) NOT NULL, + siteHandNo BIGINT NOT NULL, + gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), + handStart DATETIME NOT NULL, + importTime DATETIME NOT NULL, + seats TINYINT NOT NULL, + maxSeats TINYINT NOT NULL, + boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ + boardcard2 smallint, + boardcard3 smallint, + boardcard4 smallint, + boardcard5 smallint, + texture smallint, + playersVpi SMALLINT NOT NULL, /* num of players vpi */ + playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */ + playersAtStreet2 SMALLINT NOT NULL, + playersAtStreet3 SMALLINT NOT NULL, + playersAtStreet4 SMALLINT NOT NULL, + playersAtShowdown SMALLINT NOT NULL, + street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */ + street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */ + street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */ + street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */ + street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */ + street1Pot INT, /* pot size at flop/street4 */ + street2Pot INT, /* pot size at turn/street5 */ + street3Pot INT, /* pot size at river/street6 */ + street4Pot INT, /* pot size at sd/street7 */ + showdownPot INT, /* pot size at sd/street7 */ + comment TEXT, + commentTs DATETIME) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createHandsTable'] = """CREATE TABLE Hands ( + id BIGSERIAL, PRIMARY KEY (id), + tableName VARCHAR(22) NOT NULL, + siteHandNo BIGINT NOT NULL, + gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), + handStart timestamp without time zone NOT NULL, + importTime timestamp without time zone NOT NULL, + seats SMALLINT NOT NULL, + maxSeats SMALLINT NOT NULL, + boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ + boardcard2 smallint, + boardcard3 smallint, + boardcard4 smallint, + boardcard5 smallint, + texture smallint, + playersVpi SMALLINT NOT NULL, /* num of players vpi */ + playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */ + playersAtStreet2 SMALLINT NOT NULL, + playersAtStreet3 SMALLINT NOT NULL, + playersAtStreet4 SMALLINT NOT NULL, + playersAtShowdown SMALLINT NOT NULL, + street0Raises SMALLINT NOT NULL, /* num small bets paid to see flop/street4, including blind */ + street1Raises SMALLINT NOT NULL, /* num small bets paid to see turn/street5 */ + street2Raises SMALLINT NOT NULL, /* num big bets paid to see river/street6 */ + street3Raises SMALLINT NOT NULL, /* num big bets paid to see sd/street7 */ + street4Raises SMALLINT NOT NULL, /* num big bets paid to see showdown */ + street1Pot INT, /* pot size at flop/street4 */ + street2Pot INT, /* pot size at turn/street5 */ + street3Pot INT, /* pot size at river/street6 */ + street4Pot INT, /* pot size at sd/street7 */ + showdownPot INT, /* pot size at sd/street7 */ + comment TEXT, + commentTs timestamp without time zone)""" + elif db_server == 'sqlite': + self.query['createHandsTable'] = """CREATE TABLE Hands ( + id INTEGER PRIMARY KEY, + tableName TEXT(22) NOT NULL, + siteHandNo INT NOT NULL, + gametypeId INT NOT NULL, + handStart REAL NOT NULL, + importTime REAL NOT NULL, + seats INT NOT NULL, + maxSeats INT NOT NULL, + boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ + boardcard2 INT, + boardcard3 INT, + boardcard4 INT, + boardcard5 INT, + texture INT, + playersVpi INT NOT NULL, /* num of players vpi */ + playersAtStreet1 INT NOT NULL, /* num of players seeing flop/street4 */ + playersAtStreet2 INT NOT NULL, + playersAtStreet3 INT NOT NULL, + playersAtStreet4 INT NOT NULL, + playersAtShowdown INT NOT NULL, + street0Raises INT NOT NULL, /* num small bets paid to see flop/street4, including blind */ + street1Raises INT NOT NULL, /* num small bets paid to see turn/street5 */ + street2Raises INT NOT NULL, /* num big bets paid to see river/street6 */ + street3Raises INT NOT NULL, /* num big bets paid to see sd/street7 */ + street4Raises INT NOT NULL, /* num big bets paid to see showdown */ + street1Pot INT, /* pot size at flop/street4 */ + street2Pot INT, /* pot size at turn/street5 */ + street3Pot INT, /* pot size at river/street6 */ + street4Pot INT, /* pot size at sd/street7 */ + showdownPot INT, /* pot size at sd/street7 */ + comment TEXT, + commentTs REAL)""" + + + ################################ + # Create TourneyTypes + ################################ + + if db_server == 'mysql': + self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), - type char(4) NOT NULL, - base char(4) NOT NULL, - category varchar(9) NOT NULL, - limitType char(2) NOT NULL, - hiLo char(1) NOT NULL, - smallBlind int, - bigBlind int, - smallBet int NOT NULL, - bigBet int NOT NULL) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createGametypesTable'] = """CREATE TABLE Gametypes ( - id SERIAL, PRIMARY KEY (id), - siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id), - type char(4), - base char(4), - category varchar(9), - limitType char(2), - hiLo char(1), - smallBlind int, - bigBlind int, - smallBet int, - bigBet int)""" - elif db_server == 'sqlite': - self.query['createGametypesTable'] = """CREATE TABLE GameTypes ( - id INTEGER PRIMARY KEY, - siteId INTEGER, - type TEXT, - base TEXT, - category TEXT, - limitType TEXT, - hiLo TEXT, - smallBlind INTEGER, - bigBlind INTEGER, - smallBet INTEGER, - bigBet INTEGER, - FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)""" - - - ################################ - # Create Players - ################################ - - if db_server == 'mysql': - self.query['createPlayersTable'] = """CREATE TABLE Players ( - id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - name VARCHAR(32) CHARACTER SET utf8 NOT NULL, - siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), - comment text, - commentTs DATETIME) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createPlayersTable'] = """CREATE TABLE Players ( - id SERIAL, PRIMARY KEY (id), - name VARCHAR(32), - siteId INTEGER, FOREIGN KEY (siteId) REFERENCES Sites(id), - comment text, - commentTs timestamp without time zone)""" - elif db_server == 'sqlite': - self.query['createPlayersTable'] = """CREATE TABLE Players ( - id INTEGER PRIMARY KEY, - name TEXT, - siteId INTEGER, - comment TEXT, - commentTs REAL, - FOREIGN KEY(siteId) REFERENCES Sites(id) ON DELETE CASCADE)""" - - - ################################ - # Create Autorates - ################################ - - if db_server == 'mysql': - self.query['createAutoratesTable'] = """CREATE TABLE Autorates ( - id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), - gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), - description varchar(50) NOT NULL, - shortDesc char(8) NOT NULL, - ratingTime DATETIME NOT NULL, - handCount int NOT NULL) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createAutoratesTable'] = """CREATE TABLE Autorates ( - id BIGSERIAL, PRIMARY KEY (id), - playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id), - gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), - description varchar(50), - shortDesc char(8), - ratingTime timestamp without time zone, - handCount int)""" - elif db_server == 'sqlite': - self.query['createAutoratesTable'] = """CREATE TABLE Autorates ( - id INTEGER PRIMARY KEY, - playerId INT, - gametypeId INT, - description TEXT, - shortDesc TEXT, - ratingTime REAL, - handCount int)""" - - - ################################ - # Create Hands - ################################ - - if db_server == 'mysql': - self.query['createHandsTable'] = """CREATE TABLE Hands ( - id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - tableName VARCHAR(20) NOT NULL, - siteHandNo BIGINT NOT NULL, - gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), - handStart DATETIME NOT NULL, - importTime DATETIME NOT NULL, - seats TINYINT NOT NULL, - maxSeats TINYINT NOT NULL, - boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ - boardcard2 smallint, - boardcard3 smallint, - boardcard4 smallint, - boardcard5 smallint, - texture smallint, - playersVpi SMALLINT NOT NULL, /* num of players vpi */ - playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */ - playersAtStreet2 SMALLINT NOT NULL, - playersAtStreet3 SMALLINT NOT NULL, - playersAtStreet4 SMALLINT NOT NULL, - playersAtShowdown SMALLINT NOT NULL, - street0Raises TINYINT NOT NULL, /* num small bets paid to see flop/street4, including blind */ - street1Raises TINYINT NOT NULL, /* num small bets paid to see turn/street5 */ - street2Raises TINYINT NOT NULL, /* num big bets paid to see river/street6 */ - street3Raises TINYINT NOT NULL, /* num big bets paid to see sd/street7 */ - street4Raises TINYINT NOT NULL, /* num big bets paid to see showdown */ - street1Pot INT, /* pot size at flop/street4 */ - street2Pot INT, /* pot size at turn/street5 */ - street3Pot INT, /* pot size at river/street6 */ - street4Pot INT, /* pot size at sd/street7 */ - showdownPot INT, /* pot size at sd/street7 */ - comment TEXT, - commentTs DATETIME) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createHandsTable'] = """CREATE TABLE Hands ( - id BIGSERIAL, PRIMARY KEY (id), - tableName VARCHAR(20) NOT NULL, - siteHandNo BIGINT NOT NULL, - gametypeId INT NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), - handStart timestamp without time zone NOT NULL, - importTime timestamp without time zone NOT NULL, - seats SMALLINT NOT NULL, - maxSeats SMALLINT NOT NULL, - boardcard1 smallint, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ - boardcard2 smallint, - boardcard3 smallint, - boardcard4 smallint, - boardcard5 smallint, - texture smallint, - playersVpi SMALLINT NOT NULL, /* num of players vpi */ - playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4 */ - playersAtStreet2 SMALLINT NOT NULL, - playersAtStreet3 SMALLINT NOT NULL, - playersAtStreet4 SMALLINT NOT NULL, - playersAtShowdown SMALLINT NOT NULL, - street0Raises SMALLINT NOT NULL, /* num small bets paid to see flop/street4, including blind */ - street1Raises SMALLINT NOT NULL, /* num small bets paid to see turn/street5 */ - street2Raises SMALLINT NOT NULL, /* num big bets paid to see river/street6 */ - street3Raises SMALLINT NOT NULL, /* num big bets paid to see sd/street7 */ - street4Raises SMALLINT NOT NULL, /* num big bets paid to see showdown */ - street1Pot INT, /* pot size at flop/street4 */ - street2Pot INT, /* pot size at turn/street5 */ - street3Pot INT, /* pot size at river/street6 */ - street4Pot INT, /* pot size at sd/street7 */ - showdownPot INT, /* pot size at sd/street7 */ - comment TEXT, - commentTs timestamp without time zone)""" - elif db_server == 'sqlite': - self.query['createHandsTable'] = """CREATE TABLE Hands ( - id INTEGER PRIMARY KEY, - tableName TEXT(20) NOT NULL, - siteHandNo INT NOT NULL, - gametypeId INT NOT NULL, - handStart REAL NOT NULL, - importTime REAL NOT NULL, - seats INT NOT NULL, - maxSeats INT NOT NULL, - boardcard1 INT, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ - boardcard2 INT, - boardcard3 INT, - boardcard4 INT, - boardcard5 INT, - texture INT, - playersVpi INT NOT NULL, /* num of players vpi */ - playersAtStreet1 INT NOT NULL, /* num of players seeing flop/street4 */ - playersAtStreet2 INT NOT NULL, - playersAtStreet3 INT NOT NULL, - playersAtStreet4 INT NOT NULL, - playersAtShowdown INT NOT NULL, - street0Raises INT NOT NULL, /* num small bets paid to see flop/street4, including blind */ - street1Raises INT NOT NULL, /* num small bets paid to see turn/street5 */ - street2Raises INT NOT NULL, /* num big bets paid to see river/street6 */ - street3Raises INT NOT NULL, /* num big bets paid to see sd/street7 */ - street4Raises INT NOT NULL, /* num big bets paid to see showdown */ - street1Pot INT, /* pot size at flop/street4 */ - street2Pot INT, /* pot size at turn/street5 */ - street3Pot INT, /* pot size at river/street6 */ - street4Pot INT, /* pot size at sd/street7 */ - showdownPot INT, /* pot size at sd/street7 */ - comment TEXT, - commentTs REAL)""" - - - ################################ - # Create TourneyTypes - ################################ - - if db_server == 'mysql': - self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( - id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - siteId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), - buyin INT NOT NULL, - fee INT NOT NULL, - maxSeats INT NOT NULL DEFAULT -1, - knockout BOOLEAN NOT NULL DEFAULT False, - rebuyOrAddon BOOLEAN NOT NULL DEFAULT False, - speed varchar(10), - headsUp BOOLEAN NOT NULL DEFAULT False, - shootout BOOLEAN NOT NULL DEFAULT False, - matrix BOOLEAN NOT NULL DEFAULT False, - sng BOOLEAN NOT NULL DEFAULT False - ) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( - id SERIAL, PRIMARY KEY (id), - siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), buyin INT NOT NULL, fee INT NOT NULL, maxSeats INT NOT NULL DEFAULT -1, @@ -349,2863 +332,2891 @@ class Sql: shootout BOOLEAN NOT NULL DEFAULT False, matrix BOOLEAN NOT NULL DEFAULT False, sng BOOLEAN NOT NULL DEFAULT False - )""" - elif db_server == 'sqlite': - self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( - id INTEGER PRIMARY KEY, - siteId INT NOT NULL, - buyin INT NOT NULL, - fee INT NOT NULL, - maxSeats INT NOT NULL DEFAULT -1, - knockout BOOLEAN NOT NULL DEFAULT 0, - rebuyOrAddon BOOLEAN NOT NULL DEFAULT 0, - speed TEXT, - headsUp BOOLEAN NOT NULL DEFAULT 0, - shootout BOOLEAN NOT NULL DEFAULT 0, - matrix BOOLEAN NOT NULL DEFAULT 0, - sng BOOLEAN NOT NULL DEFAULT 0 - )""" + ) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( + id SERIAL, PRIMARY KEY (id), + siteId INT NOT NULL, FOREIGN KEY (siteId) REFERENCES Sites(id), + buyin INT NOT NULL, + fee INT NOT NULL, + maxSeats INT NOT NULL DEFAULT -1, + knockout BOOLEAN NOT NULL DEFAULT False, + rebuyOrAddon BOOLEAN NOT NULL DEFAULT False, + speed varchar(10), + headsUp BOOLEAN NOT NULL DEFAULT False, + shootout BOOLEAN NOT NULL DEFAULT False, + matrix BOOLEAN NOT NULL DEFAULT False, + sng BOOLEAN NOT NULL DEFAULT False + )""" + elif db_server == 'sqlite': + self.query['createTourneyTypesTable'] = """CREATE TABLE TourneyTypes ( + id INTEGER PRIMARY KEY, + siteId INT NOT NULL, + buyin INT NOT NULL, + fee INT NOT NULL, + maxSeats INT NOT NULL DEFAULT -1, + knockout BOOLEAN NOT NULL DEFAULT 0, + rebuyOrAddon BOOLEAN NOT NULL DEFAULT 0, + speed TEXT, + headsUp BOOLEAN NOT NULL DEFAULT 0, + shootout BOOLEAN NOT NULL DEFAULT 0, + matrix BOOLEAN NOT NULL DEFAULT 0, + sng BOOLEAN NOT NULL DEFAULT 0 + )""" - ################################ - # Create Tourneys - ################################ + ################################ + # Create Tourneys + ################################ - if db_server == 'mysql': - self.query['createTourneysTable'] = """CREATE TABLE Tourneys ( - id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), - siteTourneyNo BIGINT NOT NULL, - entries INT NOT NULL, - prizepool INT NOT NULL, - startTime DATETIME NOT NULL, - endTime DATETIME, - buyinChips INT, - tourneyName varchar(40), - matrixIdProcessed TINYINT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */ - rebuyChips INT DEFAULT 0, - addonChips INT DEFAULT 0, - rebuyAmount INT DEFAULT 0, - addonAmount INT DEFAULT 0, - totalRebuys INT DEFAULT 0, - totalAddons INT DEFAULT 0, - koBounty INT DEFAULT 0, - comment TEXT, - commentTs DATETIME) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createTourneysTable'] = """CREATE TABLE Tourneys ( - id SERIAL, PRIMARY KEY (id), - tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), - siteTourneyNo BIGINT, - entries INT, - prizepool INT, - startTime timestamp without time zone, - endTime timestamp without time zone, - buyinChips INT, - tourneyName varchar(40), - matrixIdProcessed SMALLINT DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */ - rebuyChips INT DEFAULT 0, - addonChips INT DEFAULT 0, - rebuyAmount INT DEFAULT 0, - addonAmount INT DEFAULT 0, - totalRebuys INT DEFAULT 0, - totalAddons INT DEFAULT 0, - koBounty INT DEFAULT 0, - comment TEXT, - commentTs timestamp without time zone)""" - elif db_server == 'sqlite': - self.query['createTourneysTable'] = """CREATE TABLE Tourneys ( - id INTEGER PRIMARY KEY, - tourneyTypeId INT DEFAULT 1, - siteTourneyNo INT, - entries INT, - prizepool INT, - startTime REAL, - endTime REAL, - buyinChips INT, - tourneyName TEXT, - matrixIdProcessed INT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */ - rebuyChips INT DEFAULT 0, - addonChips INT DEFAULT 0, - rebuyAmount INT DEFAULT 0, - addonAmount INT DEFAULT 0, - totalRebuys INT DEFAULT 0, - totalAddons INT DEFAULT 0, - koBounty INT DEFAULT 0, - comment TEXT, - commentTs REAL)""" - ################################ - # Create HandsPlayers - ################################ + if db_server == 'mysql': + self.query['createTourneysTable'] = """CREATE TABLE Tourneys ( + id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), + siteTourneyNo BIGINT NOT NULL, + entries INT NOT NULL, + prizepool INT NOT NULL, + startTime DATETIME NOT NULL, + endTime DATETIME, + buyinChips INT, + tourneyName varchar(40), + matrixIdProcessed TINYINT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */ + rebuyChips INT DEFAULT 0, + addonChips INT DEFAULT 0, + rebuyAmount INT DEFAULT 0, + addonAmount INT DEFAULT 0, + totalRebuys INT DEFAULT 0, + totalAddons INT DEFAULT 0, + koBounty INT DEFAULT 0, + comment TEXT, + commentTs DATETIME) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createTourneysTable'] = """CREATE TABLE Tourneys ( + id SERIAL, PRIMARY KEY (id), + tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), + siteTourneyNo BIGINT, + entries INT, + prizepool INT, + startTime timestamp without time zone, + endTime timestamp without time zone, + buyinChips INT, + tourneyName varchar(40), + matrixIdProcessed SMALLINT DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */ + rebuyChips INT DEFAULT 0, + addonChips INT DEFAULT 0, + rebuyAmount INT DEFAULT 0, + addonAmount INT DEFAULT 0, + totalRebuys INT DEFAULT 0, + totalAddons INT DEFAULT 0, + koBounty INT DEFAULT 0, + comment TEXT, + commentTs timestamp without time zone)""" + elif db_server == 'sqlite': + self.query['createTourneysTable'] = """CREATE TABLE Tourneys ( + id INTEGER PRIMARY KEY, + tourneyTypeId INT DEFAULT 1, + siteTourneyNo INT, + entries INT, + prizepool INT, + startTime REAL, + endTime REAL, + buyinChips INT, + tourneyName TEXT, + matrixIdProcessed INT UNSIGNED DEFAULT 0, /* Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn */ + rebuyChips INT DEFAULT 0, + addonChips INT DEFAULT 0, + rebuyAmount INT DEFAULT 0, + addonAmount INT DEFAULT 0, + totalRebuys INT DEFAULT 0, + totalAddons INT DEFAULT 0, + koBounty INT DEFAULT 0, + comment TEXT, + commentTs REAL)""" + ################################ + # Create HandsPlayers + ################################ - if db_server == 'mysql': - self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers ( - id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id), - playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), - startCash INT NOT NULL, - position CHAR(1), - seatNo SMALLINT NOT NULL, + if db_server == 'mysql': + self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers ( + id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + handId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id), + playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), + startCash INT NOT NULL, + position CHAR(1), + seatNo SMALLINT NOT NULL, + + card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ + card2 smallint NOT NULL, + card3 smallint, + card4 smallint, + card5 smallint, + card6 smallint, + card7 smallint, + startCards smallint, + + ante INT, + winnings int NOT NULL, + rake int NOT NULL, + totalProfit INT, + comment text, + commentTs DATETIME, + tourneysPlayersId BIGINT UNSIGNED, + tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), + + wonWhenSeenStreet1 FLOAT, + wonWhenSeenStreet2 FLOAT, + wonWhenSeenStreet3 FLOAT, + wonWhenSeenStreet4 FLOAT, + wonAtSD FLOAT, + + street0VPI BOOLEAN, + street0Aggr BOOLEAN, + street0_3BChance BOOLEAN, + street0_3BDone BOOLEAN, + street0_4BChance BOOLEAN, + street0_4BDone BOOLEAN, + other3BStreet0 BOOLEAN, + other4BStreet0 BOOLEAN, + + street1Seen BOOLEAN, + street2Seen BOOLEAN, + street3Seen BOOLEAN, + street4Seen BOOLEAN, + sawShowdown BOOLEAN, + + street1Aggr BOOLEAN, + street2Aggr BOOLEAN, + street3Aggr BOOLEAN, + street4Aggr BOOLEAN, + + otherRaisedStreet0 BOOLEAN, + otherRaisedStreet1 BOOLEAN, + otherRaisedStreet2 BOOLEAN, + otherRaisedStreet3 BOOLEAN, + otherRaisedStreet4 BOOLEAN, + foldToOtherRaisedStreet0 BOOLEAN, + foldToOtherRaisedStreet1 BOOLEAN, + foldToOtherRaisedStreet2 BOOLEAN, + foldToOtherRaisedStreet3 BOOLEAN, + foldToOtherRaisedStreet4 BOOLEAN, + + stealAttemptChance BOOLEAN, + stealAttempted BOOLEAN, + foldBbToStealChance BOOLEAN, + foldedBbToSteal BOOLEAN, + foldSbToStealChance BOOLEAN, + foldedSbToSteal BOOLEAN, + + street1CBChance BOOLEAN, + street1CBDone BOOLEAN, + street2CBChance BOOLEAN, + street2CBDone BOOLEAN, + street3CBChance BOOLEAN, + street3CBDone BOOLEAN, + street4CBChance BOOLEAN, + street4CBDone BOOLEAN, + + foldToStreet1CBChance BOOLEAN, + foldToStreet1CBDone BOOLEAN, + foldToStreet2CBChance BOOLEAN, + foldToStreet2CBDone BOOLEAN, + foldToStreet3CBChance BOOLEAN, + foldToStreet3CBDone BOOLEAN, + foldToStreet4CBChance BOOLEAN, + foldToStreet4CBDone BOOLEAN, + + street1CheckCallRaiseChance BOOLEAN, + street1CheckCallRaiseDone BOOLEAN, + street2CheckCallRaiseChance BOOLEAN, + street2CheckCallRaiseDone BOOLEAN, + street3CheckCallRaiseChance BOOLEAN, + street3CheckCallRaiseDone BOOLEAN, + street4CheckCallRaiseChance BOOLEAN, + street4CheckCallRaiseDone BOOLEAN, + + street0Calls TINYINT, + street1Calls TINYINT, + street2Calls TINYINT, + street3Calls TINYINT, + street4Calls TINYINT, + street0Bets TINYINT, + street1Bets TINYINT, + street2Bets TINYINT, + street3Bets TINYINT, + street4Bets TINYINT, + street0Raises TINYINT, + street1Raises TINYINT, + street2Raises TINYINT, + street3Raises TINYINT, + street4Raises TINYINT, + + actionString VARCHAR(15), + + FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id)) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers ( + id BIGSERIAL, PRIMARY KEY (id), + handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id), + playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), + startCash INT NOT NULL, + position CHAR(1), + seatNo SMALLINT NOT NULL, + + card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ + card2 smallint NOT NULL, + card3 smallint, + card4 smallint, + card5 smallint, + card6 smallint, + card7 smallint, + startCards smallint, + + ante INT, + winnings int NOT NULL, + rake int NOT NULL, + totalProfit INT, + comment text, + commentTs timestamp without time zone, + tourneysPlayersId BIGINT, + tourneyTypeId INT NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), + + wonWhenSeenStreet1 FLOAT, + wonWhenSeenStreet2 FLOAT, + wonWhenSeenStreet3 FLOAT, + wonWhenSeenStreet4 FLOAT, + wonAtSD FLOAT, + + street0VPI BOOLEAN, + street0Aggr BOOLEAN, + street0_3BChance BOOLEAN, + street0_3BDone BOOLEAN, + street0_4BChance BOOLEAN, + street0_4BDone BOOLEAN, + other3BStreet0 BOOLEAN, + other4BStreet0 BOOLEAN, + + street1Seen BOOLEAN, + street2Seen BOOLEAN, + street3Seen BOOLEAN, + street4Seen BOOLEAN, + sawShowdown BOOLEAN, + + street1Aggr BOOLEAN, + street2Aggr BOOLEAN, + street3Aggr BOOLEAN, + street4Aggr BOOLEAN, + + otherRaisedStreet0 BOOLEAN, + otherRaisedStreet1 BOOLEAN, + otherRaisedStreet2 BOOLEAN, + otherRaisedStreet3 BOOLEAN, + otherRaisedStreet4 BOOLEAN, + foldToOtherRaisedStreet0 BOOLEAN, + foldToOtherRaisedStreet1 BOOLEAN, + foldToOtherRaisedStreet2 BOOLEAN, + foldToOtherRaisedStreet3 BOOLEAN, + foldToOtherRaisedStreet4 BOOLEAN, + + stealAttemptChance BOOLEAN, + stealAttempted BOOLEAN, + foldBbToStealChance BOOLEAN, + foldedBbToSteal BOOLEAN, + foldSbToStealChance BOOLEAN, + foldedSbToSteal BOOLEAN, + + street1CBChance BOOLEAN, + street1CBDone BOOLEAN, + street2CBChance BOOLEAN, + street2CBDone BOOLEAN, + street3CBChance BOOLEAN, + street3CBDone BOOLEAN, + street4CBChance BOOLEAN, + street4CBDone BOOLEAN, + + foldToStreet1CBChance BOOLEAN, + foldToStreet1CBDone BOOLEAN, + foldToStreet2CBChance BOOLEAN, + foldToStreet2CBDone BOOLEAN, + foldToStreet3CBChance BOOLEAN, + foldToStreet3CBDone BOOLEAN, + foldToStreet4CBChance BOOLEAN, + foldToStreet4CBDone BOOLEAN, + + street1CheckCallRaiseChance BOOLEAN, + street1CheckCallRaiseDone BOOLEAN, + street2CheckCallRaiseChance BOOLEAN, + street2CheckCallRaiseDone BOOLEAN, + street3CheckCallRaiseChance BOOLEAN, + street3CheckCallRaiseDone BOOLEAN, + street4CheckCallRaiseChance BOOLEAN, + street4CheckCallRaiseDone BOOLEAN, + + street0Calls SMALLINT, + street1Calls SMALLINT, + street2Calls SMALLINT, + street3Calls SMALLINT, + street4Calls SMALLINT, + street0Bets SMALLINT, + street1Bets SMALLINT, + street2Bets SMALLINT, + street3Bets SMALLINT, + street4Bets SMALLINT, + street0Raises SMALLINT, + street1Raises SMALLINT, + street2Raises SMALLINT, + street3Raises SMALLINT, + street4Raises SMALLINT, + + actionString VARCHAR(15), + + FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))""" + elif db_server == 'sqlite': + self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers ( + id INTEGER PRIMARY KEY, + handId INT NOT NULL, + playerId INT NOT NULL, + startCash INT NOT NULL, + position TEXT, + seatNo INT NOT NULL, + + card1 INT NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ + card2 INT NOT NULL, + card3 INT, + card4 INT, + card5 INT, + card6 INT, + card7 INT, + startCards INT, + + ante INT, + winnings INT NOT NULL, + rake INT NOT NULL, + totalProfit INT, + comment TEXT, + commentTs REAL, + tourneysPlayersId INT, + tourneyTypeId INT NOT NULL DEFAULT 1, + + wonWhenSeenStreet1 REAL, + wonWhenSeenStreet2 REAL, + wonWhenSeenStreet3 REAL, + wonWhenSeenStreet4 REAL, + wonAtSD REAL, + + street0VPI INT, + street0Aggr INT, + street0_3BChance INT, + street0_3BDone INT, + street0_4BChance INT, + street0_4BDone INT, + other3BStreet0 INT, + other4BStreet0 INT, + + street1Seen INT, + street2Seen INT, + street3Seen INT, + street4Seen INT, + sawShowdown INT, + + street1Aggr INT, + street2Aggr INT, + street3Aggr INT, + street4Aggr INT, + + otherRaisedStreet0 INT, + otherRaisedStreet1 INT, + otherRaisedStreet2 INT, + otherRaisedStreet3 INT, + otherRaisedStreet4 INT, + foldToOtherRaisedStreet0 INT, + foldToOtherRaisedStreet1 INT, + foldToOtherRaisedStreet2 INT, + foldToOtherRaisedStreet3 INT, + foldToOtherRaisedStreet4 INT, + + stealAttemptChance INT, + stealAttempted INT, + foldBbToStealChance INT, + foldedBbToSteal INT, + foldSbToStealChance INT, + foldedSbToSteal INT, + + street1CBChance INT, + street1CBDone INT, + street2CBChance INT, + street2CBDone INT, + street3CBChance INT, + street3CBDone INT, + street4CBChance INT, + street4CBDone INT, + + foldToStreet1CBChance INT, + foldToStreet1CBDone INT, + foldToStreet2CBChance INT, + foldToStreet2CBDone INT, + foldToStreet3CBChance INT, + foldToStreet3CBDone INT, + foldToStreet4CBChance INT, + foldToStreet4CBDone INT, + + street1CheckCallRaiseChance INT, + street1CheckCallRaiseDone INT, + street2CheckCallRaiseChance INT, + street2CheckCallRaiseDone INT, + street3CheckCallRaiseChance INT, + street3CheckCallRaiseDone INT, + street4CheckCallRaiseChance INT, + street4CheckCallRaiseDone INT, + + street0Calls INT, + street1Calls INT, + street2Calls INT, + street3Calls INT, + street4Calls INT, + street0Bets INT, + street1Bets INT, + street2Bets INT, + street3Bets INT, + street4Bets INT, + street0Raises INT, + street1Raises INT, + street2Raises INT, + street3Raises INT, + street4Raises INT, + + actionString REAL) + """ + + + ################################ + # Create TourneysPlayers + ################################ + + if db_server == 'mysql': + self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers ( + id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id), + playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), + payinAmount INT NOT NULL, + rank INT NOT NULL, + winnings INT NOT NULL, + nbRebuys INT DEFAULT 0, + nbAddons INT DEFAULT 0, + nbKO INT DEFAULT 0, + comment TEXT, + commentTs DATETIME) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers ( + id BIGSERIAL, PRIMARY KEY (id), + tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id), + playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id), + payinAmount INT, + rank INT, + winnings INT, + nbRebuys INT DEFAULT 0, + nbAddons INT DEFAULT 0, + nbKO INT DEFAULT 0, + comment TEXT, + commentTs timestamp without time zone)""" + elif db_server == 'sqlite': + self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers ( + id INT PRIMARY KEY, + tourneyId INT, + playerId INT, + payinAmount INT, + rank INT, + winnings INT, + nbRebuys INT DEFAULT 0, + nbAddons INT DEFAULT 0, + nbKO INT DEFAULT 0, + comment TEXT, + commentTs timestamp without time zone, + FOREIGN KEY (tourneyId) REFERENCES Tourneys(id), + FOREIGN KEY (playerId) REFERENCES Players(id) + )""" + + + ################################ + # Create HandsActions + ################################ + + if db_server == 'mysql': + self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( + id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + handsPlayerId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id), + street SMALLINT NOT NULL, + actionNo SMALLINT NOT NULL, + action CHAR(5) NOT NULL, + allIn BOOLEAN NOT NULL, + amount INT NOT NULL, + comment TEXT, + commentTs DATETIME) + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( + id BIGSERIAL, PRIMARY KEY (id), + handsPlayerId BIGINT, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id), + street SMALLINT, + actionNo SMALLINT, + action CHAR(5), + allIn BOOLEAN, + amount INT, + comment TEXT, + commentTs timestamp without time zone)""" + elif db_server == 'sqlite': + self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( + id INT PRIMARY KEY, + handsPlayerId BIGINT, + street SMALLINT, + actionNo SMALLINT, + action CHAR(5), + allIn INT, + amount INT, + comment TEXT, + commentTs timestamp without time zone, + FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id) + )""" + + + ################################ + # Create HudCache + ################################ + + if db_server == 'mysql': + self.query['createHudCacheTable'] = """CREATE TABLE HudCache ( + id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), + gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), + playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), + activeSeats SMALLINT NOT NULL, + position CHAR(1), + tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), + styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */ + HDs INT NOT NULL, + + wonWhenSeenStreet1 FLOAT, + wonWhenSeenStreet2 FLOAT, + wonWhenSeenStreet3 FLOAT, + wonWhenSeenStreet4 FLOAT, + wonAtSD FLOAT, + + street0VPI INT, + street0Aggr INT, + street0_3BChance INT, + street0_3BDone INT, + street0_4BChance INT, + street0_4BDone INT, + other3BStreet0 INT, + other4BStreet0 INT, + + street1Seen INT, + street2Seen INT, + street3Seen INT, + street4Seen INT, + sawShowdown INT, - card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ - card2 smallint NOT NULL, - card3 smallint, - card4 smallint, - card5 smallint, - card6 smallint, - card7 smallint, - startCards smallint, + street1Aggr INT, + street2Aggr INT, + street3Aggr INT, + street4Aggr INT, + + otherRaisedStreet0 INT, + otherRaisedStreet1 INT, + otherRaisedStreet2 INT, + otherRaisedStreet3 INT, + otherRaisedStreet4 INT, + foldToOtherRaisedStreet0 INT, + foldToOtherRaisedStreet1 INT, + foldToOtherRaisedStreet2 INT, + foldToOtherRaisedStreet3 INT, + foldToOtherRaisedStreet4 INT, - ante INT, - winnings int NOT NULL, - rake int NOT NULL, - totalProfit INT, - comment text, - commentTs DATETIME, - tourneysPlayersId BIGINT UNSIGNED, - tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), + stealAttemptChance INT, + stealAttempted INT, + foldBbToStealChance INT, + foldedBbToSteal INT, + foldSbToStealChance INT, + foldedSbToSteal INT, - wonWhenSeenStreet1 FLOAT, - wonWhenSeenStreet2 FLOAT, - wonWhenSeenStreet3 FLOAT, - wonWhenSeenStreet4 FLOAT, - wonAtSD FLOAT, - - street0VPI BOOLEAN, - street0Aggr BOOLEAN, - street0_3BChance BOOLEAN, - street0_3BDone BOOLEAN, - street0_4BChance BOOLEAN, - street0_4BDone BOOLEAN, - other3BStreet0 BOOLEAN, - other4BStreet0 BOOLEAN, - - street1Seen BOOLEAN, - street2Seen BOOLEAN, - street3Seen BOOLEAN, - street4Seen BOOLEAN, - sawShowdown BOOLEAN, - - street1Aggr BOOLEAN, - street2Aggr BOOLEAN, - street3Aggr BOOLEAN, - street4Aggr BOOLEAN, - - otherRaisedStreet0 BOOLEAN, - otherRaisedStreet1 BOOLEAN, - otherRaisedStreet2 BOOLEAN, - otherRaisedStreet3 BOOLEAN, - otherRaisedStreet4 BOOLEAN, - foldToOtherRaisedStreet0 BOOLEAN, - foldToOtherRaisedStreet1 BOOLEAN, - foldToOtherRaisedStreet2 BOOLEAN, - foldToOtherRaisedStreet3 BOOLEAN, - foldToOtherRaisedStreet4 BOOLEAN, - - stealAttemptChance BOOLEAN, - stealAttempted BOOLEAN, - foldBbToStealChance BOOLEAN, - foldedBbToSteal BOOLEAN, - foldSbToStealChance BOOLEAN, - foldedSbToSteal BOOLEAN, - - street1CBChance BOOLEAN, - street1CBDone BOOLEAN, - street2CBChance BOOLEAN, - street2CBDone BOOLEAN, - street3CBChance BOOLEAN, - street3CBDone BOOLEAN, - street4CBChance BOOLEAN, - street4CBDone BOOLEAN, - - foldToStreet1CBChance BOOLEAN, - foldToStreet1CBDone BOOLEAN, - foldToStreet2CBChance BOOLEAN, - foldToStreet2CBDone BOOLEAN, - foldToStreet3CBChance BOOLEAN, - foldToStreet3CBDone BOOLEAN, - foldToStreet4CBChance BOOLEAN, - foldToStreet4CBDone BOOLEAN, - - street1CheckCallRaiseChance BOOLEAN, - street1CheckCallRaiseDone BOOLEAN, - street2CheckCallRaiseChance BOOLEAN, - street2CheckCallRaiseDone BOOLEAN, - street3CheckCallRaiseChance BOOLEAN, - street3CheckCallRaiseDone BOOLEAN, - street4CheckCallRaiseChance BOOLEAN, - street4CheckCallRaiseDone BOOLEAN, - - street0Calls TINYINT, - street1Calls TINYINT, - street2Calls TINYINT, - street3Calls TINYINT, - street4Calls TINYINT, - street0Bets TINYINT, - street1Bets TINYINT, - street2Bets TINYINT, - street3Bets TINYINT, - street4Bets TINYINT, - street0Raises TINYINT, - street1Raises TINYINT, - street2Raises TINYINT, - street3Raises TINYINT, - street4Raises TINYINT, - - actionString VARCHAR(15), - - FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id)) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers ( - id BIGSERIAL, PRIMARY KEY (id), - handId BIGINT NOT NULL, FOREIGN KEY (handId) REFERENCES Hands(id), - playerId INT NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), - startCash INT NOT NULL, - position CHAR(1), - seatNo SMALLINT NOT NULL, - - card1 smallint NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ - card2 smallint NOT NULL, - card3 smallint, - card4 smallint, - card5 smallint, - card6 smallint, - card7 smallint, - startCards smallint, - - ante INT, - winnings int NOT NULL, - rake int NOT NULL, - totalProfit INT, - comment text, - commentTs timestamp without time zone, - tourneysPlayersId BIGINT, - tourneyTypeId INT NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), - - wonWhenSeenStreet1 FLOAT, - wonWhenSeenStreet2 FLOAT, - wonWhenSeenStreet3 FLOAT, - wonWhenSeenStreet4 FLOAT, - wonAtSD FLOAT, - - street0VPI BOOLEAN, - street0Aggr BOOLEAN, - street0_3BChance BOOLEAN, - street0_3BDone BOOLEAN, - street0_4BChance BOOLEAN, - street0_4BDone BOOLEAN, - other3BStreet0 BOOLEAN, - other4BStreet0 BOOLEAN, - - street1Seen BOOLEAN, - street2Seen BOOLEAN, - street3Seen BOOLEAN, - street4Seen BOOLEAN, - sawShowdown BOOLEAN, - - street1Aggr BOOLEAN, - street2Aggr BOOLEAN, - street3Aggr BOOLEAN, - street4Aggr BOOLEAN, - - otherRaisedStreet0 BOOLEAN, - otherRaisedStreet1 BOOLEAN, - otherRaisedStreet2 BOOLEAN, - otherRaisedStreet3 BOOLEAN, - otherRaisedStreet4 BOOLEAN, - foldToOtherRaisedStreet0 BOOLEAN, - foldToOtherRaisedStreet1 BOOLEAN, - foldToOtherRaisedStreet2 BOOLEAN, - foldToOtherRaisedStreet3 BOOLEAN, - foldToOtherRaisedStreet4 BOOLEAN, - - stealAttemptChance BOOLEAN, - stealAttempted BOOLEAN, - foldBbToStealChance BOOLEAN, - foldedBbToSteal BOOLEAN, - foldSbToStealChance BOOLEAN, - foldedSbToSteal BOOLEAN, - - street1CBChance BOOLEAN, - street1CBDone BOOLEAN, - street2CBChance BOOLEAN, - street2CBDone BOOLEAN, - street3CBChance BOOLEAN, - street3CBDone BOOLEAN, - street4CBChance BOOLEAN, - street4CBDone BOOLEAN, - - foldToStreet1CBChance BOOLEAN, - foldToStreet1CBDone BOOLEAN, - foldToStreet2CBChance BOOLEAN, - foldToStreet2CBDone BOOLEAN, - foldToStreet3CBChance BOOLEAN, - foldToStreet3CBDone BOOLEAN, - foldToStreet4CBChance BOOLEAN, - foldToStreet4CBDone BOOLEAN, - - street1CheckCallRaiseChance BOOLEAN, - street1CheckCallRaiseDone BOOLEAN, - street2CheckCallRaiseChance BOOLEAN, - street2CheckCallRaiseDone BOOLEAN, - street3CheckCallRaiseChance BOOLEAN, - street3CheckCallRaiseDone BOOLEAN, - street4CheckCallRaiseChance BOOLEAN, - street4CheckCallRaiseDone BOOLEAN, - - street0Calls SMALLINT, - street1Calls SMALLINT, - street2Calls SMALLINT, - street3Calls SMALLINT, - street4Calls SMALLINT, - street0Bets SMALLINT, - street1Bets SMALLINT, - street2Bets SMALLINT, - street3Bets SMALLINT, - street4Bets SMALLINT, - street0Raises SMALLINT, - street1Raises SMALLINT, - street2Raises SMALLINT, - street3Raises SMALLINT, - street4Raises SMALLINT, - - actionString VARCHAR(15), - - FOREIGN KEY (tourneysPlayersId) REFERENCES TourneysPlayers(id))""" - elif db_server == 'sqlite': - self.query['createHandsPlayersTable'] = """CREATE TABLE HandsPlayers ( - id INTEGER PRIMARY KEY, - handId INT NOT NULL, - playerId INT NOT NULL, - startCash INT NOT NULL, - position TEXT, - seatNo INT NOT NULL, + street1CBChance INT, + street1CBDone INT, + street2CBChance INT, + street2CBDone INT, + street3CBChance INT, + street3CBDone INT, + street4CBChance INT, + street4CBDone INT, - card1 INT NOT NULL, /* 0=none, 1-13=2-Ah 14-26=2-Ad 27-39=2-Ac 40-52=2-As */ - card2 INT NOT NULL, - card3 INT, - card4 INT, - card5 INT, - card6 INT, - card7 INT, - startCards INT, + foldToStreet1CBChance INT, + foldToStreet1CBDone INT, + foldToStreet2CBChance INT, + foldToStreet2CBDone INT, + foldToStreet3CBChance INT, + foldToStreet3CBDone INT, + foldToStreet4CBChance INT, + foldToStreet4CBDone INT, - ante INT, - winnings INT NOT NULL, - rake INT NOT NULL, - totalProfit INT, - comment TEXT, - commentTs REAL, - tourneysPlayersId INT, - tourneyTypeId INT NOT NULL DEFAULT 1, + totalProfit INT, + + street1CheckCallRaiseChance INT, + street1CheckCallRaiseDone INT, + street2CheckCallRaiseChance INT, + street2CheckCallRaiseDone INT, + street3CheckCallRaiseChance INT, + street3CheckCallRaiseDone INT, + street4CheckCallRaiseChance INT, + street4CheckCallRaiseDone INT, - wonWhenSeenStreet1 REAL, - wonWhenSeenStreet2 REAL, - wonWhenSeenStreet3 REAL, - wonWhenSeenStreet4 REAL, - wonAtSD REAL, + street0Calls INT, + street1Calls INT, + street2Calls INT, + street3Calls INT, + street4Calls INT, + street0Bets INT, + street1Bets INT, + street2Bets INT, + street3Bets INT, + street4Bets INT, + street0Raises INT, + street1Raises INT, + street2Raises INT, + street3Raises INT, + street4Raises INT) - street0VPI INT, - street0Aggr INT, - street0_3BChance INT, - street0_3BDone INT, - street0_4BChance INT, - street0_4BDone INT, - other3BStreet0 INT, - other4BStreet0 INT, + ENGINE=INNODB""" + elif db_server == 'postgresql': + self.query['createHudCacheTable'] = """CREATE TABLE HudCache ( + id BIGSERIAL, PRIMARY KEY (id), + gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), + playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id), + activeSeats SMALLINT, + position CHAR(1), + tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), + styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */ + HDs INT, - street1Seen INT, - street2Seen INT, - street3Seen INT, - street4Seen INT, - sawShowdown INT, + wonWhenSeenStreet1 FLOAT, + wonWhenSeenStreet2 FLOAT, + wonWhenSeenStreet3 FLOAT, + wonWhenSeenStreet4 FLOAT, + wonAtSD FLOAT, - street1Aggr INT, - street2Aggr INT, - street3Aggr INT, - street4Aggr INT, + street0VPI INT, + street0Aggr INT, + street0_3BChance INT, + street0_3BDone INT, + street0_4BChance INT, + street0_4BDone INT, + other3BStreet0 INT, + other4BStreet0 INT, - otherRaisedStreet0 INT, - otherRaisedStreet1 INT, - otherRaisedStreet2 INT, - otherRaisedStreet3 INT, - otherRaisedStreet4 INT, - foldToOtherRaisedStreet0 INT, - foldToOtherRaisedStreet1 INT, - foldToOtherRaisedStreet2 INT, - foldToOtherRaisedStreet3 INT, - foldToOtherRaisedStreet4 INT, + street1Seen INT, + street2Seen INT, + street3Seen INT, + street4Seen INT, + sawShowdown INT, + street1Aggr INT, + street2Aggr INT, + street3Aggr INT, + street4Aggr INT, - stealAttemptChance INT, - stealAttempted INT, - foldBbToStealChance INT, - foldedBbToSteal INT, - foldSbToStealChance INT, - foldedSbToSteal INT, + otherRaisedStreet0 INT, + otherRaisedStreet1 INT, + otherRaisedStreet2 INT, + otherRaisedStreet3 INT, + otherRaisedStreet4 INT, + foldToOtherRaisedStreet0 INT, + foldToOtherRaisedStreet1 INT, + foldToOtherRaisedStreet2 INT, + foldToOtherRaisedStreet3 INT, + foldToOtherRaisedStreet4 INT, - street1CBChance INT, - street1CBDone INT, - street2CBChance INT, - street2CBDone INT, - street3CBChance INT, - street3CBDone INT, - street4CBChance INT, - street4CBDone INT, + stealAttemptChance INT, + stealAttempted INT, + foldBbToStealChance INT, + foldedBbToSteal INT, + foldSbToStealChance INT, + foldedSbToSteal INT, - foldToStreet1CBChance INT, - foldToStreet1CBDone INT, - foldToStreet2CBChance INT, - foldToStreet2CBDone INT, - foldToStreet3CBChance INT, - foldToStreet3CBDone INT, - foldToStreet4CBChance INT, - foldToStreet4CBDone INT, + street1CBChance INT, + street1CBDone INT, + street2CBChance INT, + street2CBDone INT, + street3CBChance INT, + street3CBDone INT, + street4CBChance INT, + street4CBDone INT, - street1CheckCallRaiseChance INT, - street1CheckCallRaiseDone INT, - street2CheckCallRaiseChance INT, - street2CheckCallRaiseDone INT, - street3CheckCallRaiseChance INT, - street3CheckCallRaiseDone INT, - street4CheckCallRaiseChance INT, - street4CheckCallRaiseDone INT, + foldToStreet1CBChance INT, + foldToStreet1CBDone INT, + foldToStreet2CBChance INT, + foldToStreet2CBDone INT, + foldToStreet3CBChance INT, + foldToStreet3CBDone INT, + foldToStreet4CBChance INT, + foldToStreet4CBDone INT, - street0Calls INT, - street1Calls INT, - street2Calls INT, - street3Calls INT, - street4Calls INT, - street0Bets INT, - street1Bets INT, - street2Bets INT, - street3Bets INT, - street4Bets INT, - street0Raises INT, - street1Raises INT, - street2Raises INT, - street3Raises INT, - street4Raises INT, + totalProfit INT, - actionString REAL) - """ + street1CheckCallRaiseChance INT, + street1CheckCallRaiseDone INT, + street2CheckCallRaiseChance INT, + street2CheckCallRaiseDone INT, + street3CheckCallRaiseChance INT, + street3CheckCallRaiseDone INT, + street4CheckCallRaiseChance INT, + street4CheckCallRaiseDone INT, + + street0Calls INT, + street1Calls INT, + street2Calls INT, + street3Calls INT, + street4Calls INT, + street0Bets INT, + street1Bets INT, + street2Bets INT, + street3Bets INT, + street4Bets INT, + street0Raises INT, + street1Raises INT, + street2Raises INT, + street3Raises INT, + street4Raises INT) + """ + elif db_server == 'sqlite': + self.query['createHudCacheTable'] = """CREATE TABLE HudCache ( + id INTEGER PRIMARY KEY, + gametypeId INT, + playerId INT, + activeSeats INT, + position TEXT, + tourneyTypeId INT DEFAULT 1, + styleKey TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */ + HDs INT, + + wonWhenSeenStreet1 REAL, + wonWhenSeenStreet2 REAL, + wonWhenSeenStreet3 REAL, + wonWhenSeenStreet4 REAL, + wonAtSD REAL, + + street0VPI INT, + street0Aggr INT, + street0_3BChance INT, + street0_3BDone INT, + street0_4BChance INT, + street0_4BDone INT, + other3BStreet0 INT, + other4BStreet0 INT, + + street1Seen INT, + street2Seen INT, + street3Seen INT, + street4Seen INT, + sawShowdown INT, + street1Aggr INT, + street2Aggr INT, + street3Aggr INT, + street4Aggr INT, + + otherRaisedStreet0 INT, + otherRaisedStreet1 INT, + otherRaisedStreet2 INT, + otherRaisedStreet3 INT, + otherRaisedStreet4 INT, + foldToOtherRaisedStreet0 INT, + foldToOtherRaisedStreet1 INT, + foldToOtherRaisedStreet2 INT, + foldToOtherRaisedStreet3 INT, + foldToOtherRaisedStreet4 INT, + + stealAttemptChance INT, + stealAttempted INT, + foldBbToStealChance INT, + foldedBbToSteal INT, + foldSbToStealChance INT, + foldedSbToSteal INT, + + street1CBChance INT, + street1CBDone INT, + street2CBChance INT, + street2CBDone INT, + street3CBChance INT, + street3CBDone INT, + street4CBChance INT, + street4CBDone INT, + + foldToStreet1CBChance INT, + foldToStreet1CBDone INT, + foldToStreet2CBChance INT, + foldToStreet2CBDone INT, + foldToStreet3CBChance INT, + foldToStreet3CBDone INT, + foldToStreet4CBChance INT, + foldToStreet4CBDone INT, + + totalProfit INT, + + street1CheckCallRaiseChance INT, + street1CheckCallRaiseDone INT, + street2CheckCallRaiseChance INT, + street2CheckCallRaiseDone INT, + street3CheckCallRaiseChance INT, + street3CheckCallRaiseDone INT, + street4CheckCallRaiseChance INT, + street4CheckCallRaiseDone INT, + + street0Calls INT, + street1Calls INT, + street2Calls INT, + street3Calls INT, + street4Calls INT, + street0Bets INT, + street1Bets INT, + street2Bets INT, + street3Bets INT, + street4Bets INT, + street0Raises INT, + street1Raises INT, + street2Raises INT, + street3Raises INT, + street4Raises INT) + """ - ################################ - # Create TourneysPlayers - ################################ + if db_server == 'mysql': + self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD UNIQUE INDEX siteTourneyNo(siteTourneyNo, tourneyTypeId)""" + elif db_server == 'postgresql': + self.query['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)""" + elif db_server == 'sqlite': + self.query['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)""" - if db_server == 'mysql': - self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers ( - id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - tourneyId INT UNSIGNED NOT NULL, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id), - playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), - payinAmount INT NOT NULL, - rank INT NOT NULL, - winnings INT NOT NULL, - nbRebuys INT DEFAULT 0, - nbAddons INT DEFAULT 0, - nbKO INT DEFAULT 0, - comment TEXT, - commentTs DATETIME) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers ( - id BIGSERIAL, PRIMARY KEY (id), - tourneyId INT, FOREIGN KEY (tourneyId) REFERENCES Tourneys(id), - playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id), - payinAmount INT, - rank INT, - winnings INT, - nbRebuys INT DEFAULT 0, - nbAddons INT DEFAULT 0, - nbKO INT DEFAULT 0, - comment TEXT, - commentTs timestamp without time zone)""" - elif db_server == 'sqlite': - self.query['createTourneysPlayersTable'] = """CREATE TABLE TourneysPlayers ( - id INT PRIMARY KEY, - tourneyId INT, - playerId INT, - payinAmount INT, - rank INT, - winnings INT, - nbRebuys INT DEFAULT 0, - nbAddons INT DEFAULT 0, - nbKO INT DEFAULT 0, - comment TEXT, - commentTs timestamp without time zone, - FOREIGN KEY (tourneyId) REFERENCES Tourneys(id), - FOREIGN KEY (playerId) REFERENCES Players(id) - )""" + if db_server == 'mysql': + self.query['addHandsIndex'] = """ALTER TABLE Hands ADD UNIQUE INDEX siteHandNo(siteHandNo, gameTypeId)""" + elif db_server == 'postgresql': + self.query['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gameTypeId)""" + elif db_server == 'sqlite': + self.query['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gameTypeId)""" + if db_server == 'mysql': + self.query['addPlayersIndex'] = """ALTER TABLE Players ADD UNIQUE INDEX name(name, siteId)""" + elif db_server == 'postgresql': + self.query['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)""" + elif db_server == 'sqlite': + self.query['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)""" - ################################ - # Create HandsActions - ################################ + if db_server == 'mysql': + self.query['addTPlayersIndex'] = """ALTER TABLE TourneysPlayers ADD UNIQUE INDEX tourneyId(tourneyId, playerId)""" + elif db_server == 'postgresql': + self.query['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)""" + elif db_server == 'sqlite': + self.query['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)""" - if db_server == 'mysql': - self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( - id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - handsPlayerId BIGINT UNSIGNED NOT NULL, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id), - street SMALLINT NOT NULL, - actionNo SMALLINT NOT NULL, - action CHAR(5) NOT NULL, - allIn BOOLEAN NOT NULL, - amount INT NOT NULL, - comment TEXT, - commentTs DATETIME) - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( - id BIGSERIAL, PRIMARY KEY (id), - handsPlayerId BIGINT, FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id), - street SMALLINT, - actionNo SMALLINT, - action CHAR(5), - allIn BOOLEAN, - amount INT, - comment TEXT, - commentTs timestamp without time zone)""" - elif db_server == 'sqlite': - self.query['createHandsActionsTable'] = """CREATE TABLE HandsActions ( - id INT PRIMARY KEY, - handsPlayerId BIGINT, - street SMALLINT, - actionNo SMALLINT, - action CHAR(5), - allIn INT, - amount INT, - comment TEXT, - commentTs timestamp without time zone, - FOREIGN KEY (handsPlayerId) REFERENCES HandsPlayers(id) - )""" + if db_server == 'mysql': + self.query['addTTypesIndex'] = """ALTER TABLE TourneyTypes ADD UNIQUE INDEX tourneytypes_all(buyin, fee + , maxSeats, knockout, rebuyOrAddon, speed, headsUp, shootout, matrix, sng)""" + elif db_server == 'postgresql': + self.query['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (buyin, fee + , maxSeats, knockout, rebuyOrAddon, speed, headsUp, shootout, matrix, sng)""" + elif db_server == 'sqlite': + self.query['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (buyin, fee + , maxSeats, knockout, rebuyOrAddon, speed, headsUp, shootout, matrix, sng)""" + self.query['get_last_hand'] = "select max(id) from Hands" - ################################ - # Create HudCache - ################################ + self.query['get_player_id'] = """ + select Players.id AS player_id + from Players, Sites + where Players.name = %s + and Sites.name = %s + and Players.siteId = Sites.id + """ - if db_server == 'mysql': - self.query['createHudCacheTable'] = """CREATE TABLE HudCache ( - id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - gametypeId SMALLINT UNSIGNED NOT NULL, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), - playerId INT UNSIGNED NOT NULL, FOREIGN KEY (playerId) REFERENCES Players(id), - activeSeats SMALLINT NOT NULL, - position CHAR(1), - tourneyTypeId SMALLINT UNSIGNED NOT NULL DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), - styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */ - HDs INT NOT NULL, + self.query['get_player_names'] = """ + select p.name + from Players p + where lower(p.name) like lower(%s) + and (p.siteId = %s or %s = -1) + """ - wonWhenSeenStreet1 FLOAT, - wonWhenSeenStreet2 FLOAT, - wonWhenSeenStreet3 FLOAT, - wonWhenSeenStreet4 FLOAT, - wonAtSD FLOAT, + self.query['getSiteId'] = """SELECT id from Sites where name = %s""" - street0VPI INT, - street0Aggr INT, - street0_3BChance INT, - street0_3BDone INT, - street0_4BChance INT, - street0_4BDone INT, - other3BStreet0 INT, - other4BStreet0 INT, - - street1Seen INT, - street2Seen INT, - street3Seen INT, - street4Seen INT, - sawShowdown INT, - - street1Aggr INT, - street2Aggr INT, - street3Aggr INT, - street4Aggr INT, - - otherRaisedStreet0 INT, - otherRaisedStreet1 INT, - otherRaisedStreet2 INT, - otherRaisedStreet3 INT, - otherRaisedStreet4 INT, - foldToOtherRaisedStreet0 INT, - foldToOtherRaisedStreet1 INT, - foldToOtherRaisedStreet2 INT, - foldToOtherRaisedStreet3 INT, - foldToOtherRaisedStreet4 INT, - - stealAttemptChance INT, - stealAttempted INT, - foldBbToStealChance INT, - foldedBbToSteal INT, - foldSbToStealChance INT, - foldedSbToSteal INT, - - street1CBChance INT, - street1CBDone INT, - street2CBChance INT, - street2CBDone INT, - street3CBChance INT, - street3CBDone INT, - street4CBChance INT, - street4CBDone INT, - - foldToStreet1CBChance INT, - foldToStreet1CBDone INT, - foldToStreet2CBChance INT, - foldToStreet2CBDone INT, - foldToStreet3CBChance INT, - foldToStreet3CBDone INT, - foldToStreet4CBChance INT, - foldToStreet4CBDone INT, - - totalProfit INT, - - street1CheckCallRaiseChance INT, - street1CheckCallRaiseDone INT, - street2CheckCallRaiseChance INT, - street2CheckCallRaiseDone INT, - street3CheckCallRaiseChance INT, - street3CheckCallRaiseDone INT, - street4CheckCallRaiseChance INT, - street4CheckCallRaiseDone INT, - - street0Calls INT, - street1Calls INT, - street2Calls INT, - street3Calls INT, - street4Calls INT, - street0Bets INT, - street1Bets INT, - street2Bets INT, - street3Bets INT, - street4Bets INT, - street0Raises INT, - street1Raises INT, - street2Raises INT, - street3Raises INT, - street4Raises INT) - - ENGINE=INNODB""" - elif db_server == 'postgresql': - self.query['createHudCacheTable'] = """CREATE TABLE HudCache ( - id BIGSERIAL, PRIMARY KEY (id), - gametypeId INT, FOREIGN KEY (gametypeId) REFERENCES Gametypes(id), - playerId INT, FOREIGN KEY (playerId) REFERENCES Players(id), - activeSeats SMALLINT, - position CHAR(1), - tourneyTypeId INT DEFAULT 1, FOREIGN KEY (tourneyTypeId) REFERENCES TourneyTypes(id), - styleKey CHAR(7) NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */ - HDs INT, - - wonWhenSeenStreet1 FLOAT, - wonWhenSeenStreet2 FLOAT, - wonWhenSeenStreet3 FLOAT, - wonWhenSeenStreet4 FLOAT, - wonAtSD FLOAT, - - street0VPI INT, - street0Aggr INT, - street0_3BChance INT, - street0_3BDone INT, - street0_4BChance INT, - street0_4BDone INT, - other3BStreet0 INT, - other4BStreet0 INT, - - street1Seen INT, - street2Seen INT, - street3Seen INT, - street4Seen INT, - sawShowdown INT, - street1Aggr INT, - street2Aggr INT, - street3Aggr INT, - street4Aggr INT, - - otherRaisedStreet0 INT, - otherRaisedStreet1 INT, - otherRaisedStreet2 INT, - otherRaisedStreet3 INT, - otherRaisedStreet4 INT, - foldToOtherRaisedStreet0 INT, - foldToOtherRaisedStreet1 INT, - foldToOtherRaisedStreet2 INT, - foldToOtherRaisedStreet3 INT, - foldToOtherRaisedStreet4 INT, - - stealAttemptChance INT, - stealAttempted INT, - foldBbToStealChance INT, - foldedBbToSteal INT, - foldSbToStealChance INT, - foldedSbToSteal INT, - - street1CBChance INT, - street1CBDone INT, - street2CBChance INT, - street2CBDone INT, - street3CBChance INT, - street3CBDone INT, - street4CBChance INT, - street4CBDone INT, - - foldToStreet1CBChance INT, - foldToStreet1CBDone INT, - foldToStreet2CBChance INT, - foldToStreet2CBDone INT, - foldToStreet3CBChance INT, - foldToStreet3CBDone INT, - foldToStreet4CBChance INT, - foldToStreet4CBDone INT, - - totalProfit INT, - - street1CheckCallRaiseChance INT, - street1CheckCallRaiseDone INT, - street2CheckCallRaiseChance INT, - street2CheckCallRaiseDone INT, - street3CheckCallRaiseChance INT, - street3CheckCallRaiseDone INT, - street4CheckCallRaiseChance INT, - street4CheckCallRaiseDone INT, - - street0Calls INT, - street1Calls INT, - street2Calls INT, - street3Calls INT, - street4Calls INT, - street0Bets INT, - street1Bets INT, - street2Bets INT, - street3Bets INT, - street4Bets INT, - street0Raises INT, - street1Raises INT, - street2Raises INT, - street3Raises INT, - street4Raises INT) - """ - elif db_server == 'sqlite': - self.query['createHudCacheTable'] = """CREATE TABLE HudCache ( - id INTEGER PRIMARY KEY, - gametypeId INT, - playerId INT, - activeSeats INT, - position TEXT, - tourneyTypeId INT DEFAULT 1, - styleKey TEXT NOT NULL, /* 1st char is style (A/T/H/S), other 6 are the key */ - HDs INT, - - wonWhenSeenStreet1 REAL, - wonWhenSeenStreet2 REAL, - wonWhenSeenStreet3 REAL, - wonWhenSeenStreet4 REAL, - wonAtSD REAL, - - street0VPI INT, - street0Aggr INT, - street0_3BChance INT, - street0_3BDone INT, - street0_4BChance INT, - street0_4BDone INT, - other3BStreet0 INT, - other4BStreet0 INT, - - street1Seen INT, - street2Seen INT, - street3Seen INT, - street4Seen INT, - sawShowdown INT, - street1Aggr INT, - street2Aggr INT, - street3Aggr INT, - street4Aggr INT, - - otherRaisedStreet0 INT, - otherRaisedStreet1 INT, - otherRaisedStreet2 INT, - otherRaisedStreet3 INT, - otherRaisedStreet4 INT, - foldToOtherRaisedStreet0 INT, - foldToOtherRaisedStreet1 INT, - foldToOtherRaisedStreet2 INT, - foldToOtherRaisedStreet3 INT, - foldToOtherRaisedStreet4 INT, - - stealAttemptChance INT, - stealAttempted INT, - foldBbToStealChance INT, - foldedBbToSteal INT, - foldSbToStealChance INT, - foldedSbToSteal INT, - - street1CBChance INT, - street1CBDone INT, - street2CBChance INT, - street2CBDone INT, - street3CBChance INT, - street3CBDone INT, - street4CBChance INT, - street4CBDone INT, - - foldToStreet1CBChance INT, - foldToStreet1CBDone INT, - foldToStreet2CBChance INT, - foldToStreet2CBDone INT, - foldToStreet3CBChance INT, - foldToStreet3CBDone INT, - foldToStreet4CBChance INT, - foldToStreet4CBDone INT, - - totalProfit INT, - - street1CheckCallRaiseChance INT, - street1CheckCallRaiseDone INT, - street2CheckCallRaiseChance INT, - street2CheckCallRaiseDone INT, - street3CheckCallRaiseChance INT, - street3CheckCallRaiseDone INT, - street4CheckCallRaiseChance INT, - street4CheckCallRaiseDone INT, - - street0Calls INT, - street1Calls INT, - street2Calls INT, - street3Calls INT, - street4Calls INT, - street0Bets INT, - street1Bets INT, - street2Bets INT, - street3Bets INT, - street4Bets INT, - street0Raises INT, - street1Raises INT, - street2Raises INT, - street3Raises INT, - street4Raises INT) - """ - - - if db_server == 'mysql': - self.query['addTourneyIndex'] = """ALTER TABLE Tourneys ADD UNIQUE INDEX siteTourneyNo(siteTourneyNo, tourneyTypeId)""" - elif db_server == 'postgresql': - self.query['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)""" - elif db_server == 'sqlite': - self.query['addTourneyIndex'] = """CREATE UNIQUE INDEX siteTourneyNo ON Tourneys (siteTourneyNo, tourneyTypeId)""" - - if db_server == 'mysql': - self.query['addHandsIndex'] = """ALTER TABLE Hands ADD UNIQUE INDEX siteHandNo(siteHandNo, gameTypeId)""" - elif db_server == 'postgresql': - self.query['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gameTypeId)""" - elif db_server == 'sqlite': - self.query['addHandsIndex'] = """CREATE UNIQUE INDEX siteHandNo ON Hands (siteHandNo, gameTypeId)""" - - if db_server == 'mysql': - self.query['addPlayersIndex'] = """ALTER TABLE Players ADD UNIQUE INDEX name(name, siteId)""" - elif db_server == 'postgresql': - self.query['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)""" - elif db_server == 'sqlite': - self.query['addPlayersIndex'] = """CREATE UNIQUE INDEX name ON Players (name, siteId)""" - - if db_server == 'mysql': - self.query['addTPlayersIndex'] = """ALTER TABLE TourneysPlayers ADD UNIQUE INDEX tourneyId(tourneyId, playerId)""" - elif db_server == 'postgresql': - self.query['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)""" - elif db_server == 'sqlite': - self.query['addTPlayersIndex'] = """CREATE UNIQUE INDEX tourneyId ON TourneysPlayers (tourneyId, playerId)""" - - if db_server == 'mysql': - self.query['addTTypesIndex'] = """ALTER TABLE TourneyTypes ADD UNIQUE INDEX tourneytypes_all(buyin, fee - , maxSeats, knockout, rebuyOrAddon, speed, headsUp, shootout, matrix, sng)""" - elif db_server == 'postgresql': - self.query['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (buyin, fee - , maxSeats, knockout, rebuyOrAddon, speed, headsUp, shootout, matrix, sng)""" - elif db_server == 'sqlite': - self.query['addTTypesIndex'] = """CREATE UNIQUE INDEX tourneyTypes_all ON TourneyTypes (buyin, fee - , maxSeats, knockout, rebuyOrAddon, speed, headsUp, shootout, matrix, sng)""" - - self.query['get_last_hand'] = "select max(id) from Hands" - - self.query['get_player_id'] = """ - select Players.id AS player_id - from Players, Sites - where Players.name = %s - and Sites.name = %s - and Players.siteId = Sites.id - """ - - self.query['get_player_names'] = """ - select p.name - from Players p - where lower(p.name) like lower(%s) - and (p.siteId = %s or %s = -1) - """ - - self.query['getSiteId'] = """SELECT id from Sites where name = %s""" - - self.query['get_stats_from_hand'] = """ - SELECT hc.playerId AS player_id, - hp.seatNo AS seat, - p.name AS screen_name, - sum(hc.HDs) AS n, - sum(hc.street0VPI) AS vpip, - sum(hc.street0Aggr) AS pfr, - sum(hc.street0_3BChance) AS TB_opp_0, - sum(hc.street0_3BDone) AS TB_0, - sum(hc.street1Seen) AS saw_f, - sum(hc.street1Seen) AS saw_1, - sum(hc.street2Seen) AS saw_2, - sum(hc.street3Seen) AS saw_3, - sum(hc.street4Seen) AS saw_4, - sum(hc.sawShowdown) AS sd, - sum(hc.street1Aggr) AS aggr_1, - sum(hc.street2Aggr) AS aggr_2, - sum(hc.street3Aggr) AS aggr_3, - sum(hc.street4Aggr) AS aggr_4, - sum(hc.otherRaisedStreet1) AS was_raised_1, - sum(hc.otherRaisedStreet2) AS was_raised_2, - sum(hc.otherRaisedStreet3) AS was_raised_3, - sum(hc.otherRaisedStreet4) AS was_raised_4, - sum(hc.foldToOtherRaisedStreet1) AS f_freq_1, - sum(hc.foldToOtherRaisedStreet2) AS f_freq_2, - sum(hc.foldToOtherRaisedStreet3) AS f_freq_3, - sum(hc.foldToOtherRaisedStreet4) AS f_freq_4, - sum(hc.wonWhenSeenStreet1) AS w_w_s_1, - sum(hc.wonAtSD) AS wmsd, - sum(hc.stealAttemptChance) AS steal_opp, - sum(hc.stealAttempted) AS steal, - sum(hc.foldSbToStealChance) AS SBstolen, - sum(hc.foldedSbToSteal) AS SBnotDef, - sum(hc.foldBbToStealChance) AS BBstolen, - sum(hc.foldedBbToSteal) AS BBnotDef, - sum(hc.street1CBChance) AS CB_opp_1, - sum(hc.street1CBDone) AS CB_1, - sum(hc.street2CBChance) AS CB_opp_2, - sum(hc.street2CBDone) AS CB_2, - sum(hc.street3CBChance) AS CB_opp_3, - sum(hc.street3CBDone) AS CB_3, - sum(hc.street4CBChance) AS CB_opp_4, - sum(hc.street4CBDone) AS CB_4, - sum(hc.foldToStreet1CBChance) AS f_cb_opp_1, - sum(hc.foldToStreet1CBDone) AS f_cb_1, - sum(hc.foldToStreet2CBChance) AS f_cb_opp_2, - sum(hc.foldToStreet2CBDone) AS f_cb_2, - sum(hc.foldToStreet3CBChance) AS f_cb_opp_3, - sum(hc.foldToStreet3CBDone) AS f_cb_3, - sum(hc.foldToStreet4CBChance) AS f_cb_opp_4, - sum(hc.foldToStreet4CBDone) AS f_cb_4, - sum(hc.totalProfit) AS net, - sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1, - sum(hc.street1CheckCallRaiseDone) AS ccr_1, - sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2, - sum(hc.street2CheckCallRaiseDone) AS ccr_2, - sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3, - sum(hc.street3CheckCallRaiseDone) AS ccr_3, - sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4, - sum(hc.street4CheckCallRaiseDone) AS ccr_4 - FROM Hands h - INNER JOIN HandsPlayers hp ON (hp.handId = h.id) - INNER JOIN HudCache hc ON ( hc.PlayerId = hp.PlayerId+0 - AND hc.gametypeId+0 = h.gametypeId+0) - INNER JOIN Players p ON (p.id = hp.PlayerId+0) - WHERE h.id = %s - AND hc.styleKey > %s - /* styleKey is currently 'd' (for date) followed by a yyyymmdd - date key. Set it to 0000000 or similar to get all records */ - /* also check activeseats here even if only 3 groups eg 2-3/4-6/7+ - e.g. could use a multiplier: - AND h.seats > X / 1.25 and hp.seats < X * 1.25 - where X is the number of active players at the current table (and - 1.25 would be a config value so user could change it) - */ - GROUP BY hc.PlayerId, hp.seatNo, p.name - """ + self.query['get_stats_from_hand'] = """ + SELECT hc.playerId AS player_id, + hp.seatNo AS seat, + p.name AS screen_name, + sum(hc.HDs) AS n, + sum(hc.street0VPI) AS vpip, + sum(hc.street0Aggr) AS pfr, + sum(hc.street0_3BChance) AS TB_opp_0, + sum(hc.street0_3BDone) AS TB_0, + sum(hc.street1Seen) AS saw_f, + sum(hc.street1Seen) AS saw_1, + sum(hc.street2Seen) AS saw_2, + sum(hc.street3Seen) AS saw_3, + sum(hc.street4Seen) AS saw_4, + sum(hc.sawShowdown) AS sd, + sum(hc.street1Aggr) AS aggr_1, + sum(hc.street2Aggr) AS aggr_2, + sum(hc.street3Aggr) AS aggr_3, + sum(hc.street4Aggr) AS aggr_4, + sum(hc.otherRaisedStreet1) AS was_raised_1, + sum(hc.otherRaisedStreet2) AS was_raised_2, + sum(hc.otherRaisedStreet3) AS was_raised_3, + sum(hc.otherRaisedStreet4) AS was_raised_4, + sum(hc.foldToOtherRaisedStreet1) AS f_freq_1, + sum(hc.foldToOtherRaisedStreet2) AS f_freq_2, + sum(hc.foldToOtherRaisedStreet3) AS f_freq_3, + sum(hc.foldToOtherRaisedStreet4) AS f_freq_4, + sum(hc.wonWhenSeenStreet1) AS w_w_s_1, + sum(hc.wonAtSD) AS wmsd, + sum(hc.stealAttemptChance) AS steal_opp, + sum(hc.stealAttempted) AS steal, + sum(hc.foldSbToStealChance) AS SBstolen, + sum(hc.foldedSbToSteal) AS SBnotDef, + sum(hc.foldBbToStealChance) AS BBstolen, + sum(hc.foldedBbToSteal) AS BBnotDef, + sum(hc.street1CBChance) AS CB_opp_1, + sum(hc.street1CBDone) AS CB_1, + sum(hc.street2CBChance) AS CB_opp_2, + sum(hc.street2CBDone) AS CB_2, + sum(hc.street3CBChance) AS CB_opp_3, + sum(hc.street3CBDone) AS CB_3, + sum(hc.street4CBChance) AS CB_opp_4, + sum(hc.street4CBDone) AS CB_4, + sum(hc.foldToStreet1CBChance) AS f_cb_opp_1, + sum(hc.foldToStreet1CBDone) AS f_cb_1, + sum(hc.foldToStreet2CBChance) AS f_cb_opp_2, + sum(hc.foldToStreet2CBDone) AS f_cb_2, + sum(hc.foldToStreet3CBChance) AS f_cb_opp_3, + sum(hc.foldToStreet3CBDone) AS f_cb_3, + sum(hc.foldToStreet4CBChance) AS f_cb_opp_4, + sum(hc.foldToStreet4CBDone) AS f_cb_4, + sum(hc.totalProfit) AS net, + sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1, + sum(hc.street1CheckCallRaiseDone) AS ccr_1, + sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2, + sum(hc.street2CheckCallRaiseDone) AS ccr_2, + sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3, + sum(hc.street3CheckCallRaiseDone) AS ccr_3, + sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4, + sum(hc.street4CheckCallRaiseDone) AS ccr_4 + FROM Hands h + INNER JOIN HandsPlayers hp ON (hp.handId = h.id) + INNER JOIN HudCache hc ON ( hc.PlayerId = hp.PlayerId+0 + AND hc.gametypeId+0 = h.gametypeId+0) + INNER JOIN Players p ON (p.id = hp.PlayerId+0) + WHERE h.id = %s + AND hc.styleKey > %s + /* styleKey is currently 'd' (for date) followed by a yyyymmdd + date key. Set it to 0000000 or similar to get all records */ + /* also check activeseats here even if only 3 groups eg 2-3/4-6/7+ + e.g. could use a multiplier: + AND h.seats > X / 1.25 and hp.seats < X * 1.25 + where X is the number of active players at the current table (and + 1.25 would be a config value so user could change it) + */ + GROUP BY hc.PlayerId, hp.seatNo, p.name + """ # same as above except stats are aggregated for all blind/limit levels - self.query['get_stats_from_hand_aggregated'] = """ - SELECT hc.playerId AS player_id, - max(case when hc.gametypeId = h.gametypeId - then hp.seatNo - else -1 - end) AS seat, - p.name AS screen_name, - sum(hc.HDs) AS n, - sum(hc.street0VPI) AS vpip, - sum(hc.street0Aggr) AS pfr, - sum(hc.street0_3BChance) AS TB_opp_0, - sum(hc.street0_3BDone) AS TB_0, - sum(hc.street1Seen) AS saw_f, - sum(hc.street1Seen) AS saw_1, - sum(hc.street2Seen) AS saw_2, - sum(hc.street3Seen) AS saw_3, - sum(hc.street4Seen) AS saw_4, - sum(hc.sawShowdown) AS sd, - sum(hc.street1Aggr) AS aggr_1, - sum(hc.street2Aggr) AS aggr_2, - sum(hc.street3Aggr) AS aggr_3, - sum(hc.street4Aggr) AS aggr_4, - sum(hc.otherRaisedStreet1) AS was_raised_1, - sum(hc.otherRaisedStreet2) AS was_raised_2, - sum(hc.otherRaisedStreet3) AS was_raised_3, - sum(hc.otherRaisedStreet4) AS was_raised_4, - sum(hc.foldToOtherRaisedStreet1) AS f_freq_1, - sum(hc.foldToOtherRaisedStreet2) AS f_freq_2, - sum(hc.foldToOtherRaisedStreet3) AS f_freq_3, - sum(hc.foldToOtherRaisedStreet4) AS f_freq_4, - sum(hc.wonWhenSeenStreet1) AS w_w_s_1, - sum(hc.wonAtSD) AS wmsd, - sum(hc.stealAttemptChance) AS steal_opp, - sum(hc.stealAttempted) AS steal, - sum(hc.foldSbToStealChance) AS SBstolen, - sum(hc.foldedSbToSteal) AS SBnotDef, - sum(hc.foldBbToStealChance) AS BBstolen, - sum(hc.foldedBbToSteal) AS BBnotDef, - sum(hc.street1CBChance) AS CB_opp_1, - sum(hc.street1CBDone) AS CB_1, - sum(hc.street2CBChance) AS CB_opp_2, - sum(hc.street2CBDone) AS CB_2, - sum(hc.street3CBChance) AS CB_opp_3, - sum(hc.street3CBDone) AS CB_3, - sum(hc.street4CBChance) AS CB_opp_4, - sum(hc.street4CBDone) AS CB_4, - sum(hc.foldToStreet1CBChance) AS f_cb_opp_1, - sum(hc.foldToStreet1CBDone) AS f_cb_1, - sum(hc.foldToStreet2CBChance) AS f_cb_opp_2, - sum(hc.foldToStreet2CBDone) AS f_cb_2, - sum(hc.foldToStreet3CBChance) AS f_cb_opp_3, - sum(hc.foldToStreet3CBDone) AS f_cb_3, - sum(hc.foldToStreet4CBChance) AS f_cb_opp_4, - sum(hc.foldToStreet4CBDone) AS f_cb_4, - sum(hc.totalProfit) AS net, - sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1, - sum(hc.street1CheckCallRaiseDone) AS ccr_1, - sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2, - sum(hc.street2CheckCallRaiseDone) AS ccr_2, - sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3, - sum(hc.street3CheckCallRaiseDone) AS ccr_3, - sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4, - sum(hc.street4CheckCallRaiseDone) AS ccr_4 - FROM Hands h - INNER JOIN HandsPlayers hp ON (hp.handId = h.id) - INNER JOIN HudCache hc ON (hc.playerId = hp.playerId) - INNER JOIN Players p ON (p.id = hc.playerId) - WHERE h.id = %s - AND ( /* 2 separate parts for hero and opponents */ - ( hp.playerId != %s - AND hc.styleKey > %s - AND hc.gametypeId+0 in - (SELECT gt1.id from Gametypes gt1, Gametypes gt2 - WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */ - AND gt1.type = gt2.type /* ring/tourney */ - AND gt1.category = gt2.category /* holdem/stud*/ - AND gt1.limittype = gt2.limittype /* fl/nl */ - AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */ - AND gt1.bigblind >= gt2.bigblind / %s - AND gt2.id = h.gametypeId) - ) - OR - ( hp.playerId = %s - AND hc.styleKey > %s - AND hc.gametypeId+0 in - (SELECT gt1.id from Gametypes gt1, Gametypes gt2 - WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */ - AND gt1.type = gt2.type /* ring/tourney */ - AND gt1.category = gt2.category /* holdem/stud*/ - AND gt1.limittype = gt2.limittype /* fl/nl */ - AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */ - AND gt1.bigblind >= gt2.bigblind / %s - AND gt2.id = h.gametypeId) - ) + self.query['get_stats_from_hand_aggregated'] = """ + SELECT hc.playerId AS player_id, + max(case when hc.gametypeId = h.gametypeId + then hp.seatNo + else -1 + end) AS seat, + p.name AS screen_name, + sum(hc.HDs) AS n, + sum(hc.street0VPI) AS vpip, + sum(hc.street0Aggr) AS pfr, + sum(hc.street0_3BChance) AS TB_opp_0, + sum(hc.street0_3BDone) AS TB_0, + sum(hc.street1Seen) AS saw_f, + sum(hc.street1Seen) AS saw_1, + sum(hc.street2Seen) AS saw_2, + sum(hc.street3Seen) AS saw_3, + sum(hc.street4Seen) AS saw_4, + sum(hc.sawShowdown) AS sd, + sum(hc.street1Aggr) AS aggr_1, + sum(hc.street2Aggr) AS aggr_2, + sum(hc.street3Aggr) AS aggr_3, + sum(hc.street4Aggr) AS aggr_4, + sum(hc.otherRaisedStreet1) AS was_raised_1, + sum(hc.otherRaisedStreet2) AS was_raised_2, + sum(hc.otherRaisedStreet3) AS was_raised_3, + sum(hc.otherRaisedStreet4) AS was_raised_4, + sum(hc.foldToOtherRaisedStreet1) AS f_freq_1, + sum(hc.foldToOtherRaisedStreet2) AS f_freq_2, + sum(hc.foldToOtherRaisedStreet3) AS f_freq_3, + sum(hc.foldToOtherRaisedStreet4) AS f_freq_4, + sum(hc.wonWhenSeenStreet1) AS w_w_s_1, + sum(hc.wonAtSD) AS wmsd, + sum(hc.stealAttemptChance) AS steal_opp, + sum(hc.stealAttempted) AS steal, + sum(hc.foldSbToStealChance) AS SBstolen, + sum(hc.foldedSbToSteal) AS SBnotDef, + sum(hc.foldBbToStealChance) AS BBstolen, + sum(hc.foldedBbToSteal) AS BBnotDef, + sum(hc.street1CBChance) AS CB_opp_1, + sum(hc.street1CBDone) AS CB_1, + sum(hc.street2CBChance) AS CB_opp_2, + sum(hc.street2CBDone) AS CB_2, + sum(hc.street3CBChance) AS CB_opp_3, + sum(hc.street3CBDone) AS CB_3, + sum(hc.street4CBChance) AS CB_opp_4, + sum(hc.street4CBDone) AS CB_4, + sum(hc.foldToStreet1CBChance) AS f_cb_opp_1, + sum(hc.foldToStreet1CBDone) AS f_cb_1, + sum(hc.foldToStreet2CBChance) AS f_cb_opp_2, + sum(hc.foldToStreet2CBDone) AS f_cb_2, + sum(hc.foldToStreet3CBChance) AS f_cb_opp_3, + sum(hc.foldToStreet3CBDone) AS f_cb_3, + sum(hc.foldToStreet4CBChance) AS f_cb_opp_4, + sum(hc.foldToStreet4CBDone) AS f_cb_4, + sum(hc.totalProfit) AS net, + sum(hc.street1CheckCallRaiseChance) AS ccr_opp_1, + sum(hc.street1CheckCallRaiseDone) AS ccr_1, + sum(hc.street2CheckCallRaiseChance) AS ccr_opp_2, + sum(hc.street2CheckCallRaiseDone) AS ccr_2, + sum(hc.street3CheckCallRaiseChance) AS ccr_opp_3, + sum(hc.street3CheckCallRaiseDone) AS ccr_3, + sum(hc.street4CheckCallRaiseChance) AS ccr_opp_4, + sum(hc.street4CheckCallRaiseDone) AS ccr_4 + FROM Hands h + INNER JOIN HandsPlayers hp ON (hp.handId = h.id) + INNER JOIN HudCache hc ON (hc.playerId = hp.playerId) + INNER JOIN Players p ON (p.id = hc.playerId) + WHERE h.id = %s + AND ( /* 2 separate parts for hero and opponents */ + ( hp.playerId != %s + AND hc.styleKey > %s + AND hc.gametypeId+0 in + (SELECT gt1.id from Gametypes gt1, Gametypes gt2 + WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */ + AND gt1.type = gt2.type /* ring/tourney */ + AND gt1.category = gt2.category /* holdem/stud*/ + AND gt1.limittype = gt2.limittype /* fl/nl */ + AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */ + AND gt1.bigblind >= gt2.bigblind / %s + AND gt2.id = h.gametypeId) ) - GROUP BY hc.PlayerId, p.name - """ - # NOTES on above cursor: - # - Do NOT include %s inside query in a comment - the db api thinks - # they are actual arguments. - # - styleKey is currently 'd' (for date) followed by a yyyymmdd - # date key. Set it to 0000000 or similar to get all records - # Could also check activeseats here even if only 3 groups eg 2-3/4-6/7+ - # e.g. could use a multiplier: - # AND h.seats > %s / 1.25 and hp.seats < %s * 1.25 - # where %s is the number of active players at the current table (and - # 1.25 would be a config value so user could change it) + OR + ( hp.playerId = %s + AND hc.styleKey > %s + AND hc.gametypeId+0 in + (SELECT gt1.id from Gametypes gt1, Gametypes gt2 + WHERE gt1.siteid = gt2.siteid /* find gametypes where these match: */ + AND gt1.type = gt2.type /* ring/tourney */ + AND gt1.category = gt2.category /* holdem/stud*/ + AND gt1.limittype = gt2.limittype /* fl/nl */ + AND gt1.bigblind <= gt2.bigblind * %s /* bigblind similar size */ + AND gt1.bigblind >= gt2.bigblind / %s + AND gt2.id = h.gametypeId) + ) + ) + GROUP BY hc.PlayerId, p.name + """ + # NOTES on above cursor: + # - Do NOT include %s inside query in a comment - the db api thinks + # they are actual arguments. + # - styleKey is currently 'd' (for date) followed by a yyyymmdd + # date key. Set it to 0000000 or similar to get all records + # Could also check activeseats here even if only 3 groups eg 2-3/4-6/7+ + # e.g. could use a multiplier: + # AND h.seats > %s / 1.25 and hp.seats < %s * 1.25 + # where %s is the number of active players at the current table (and + # 1.25 would be a config value so user could change it) - if db_server == 'mysql': - self.query['get_stats_from_hand_session'] = """ - SELECT hp.playerId AS player_id, - hp.handId AS hand_id, - hp.seatNo AS seat, - p.name AS screen_name, - h.seats AS seats, - 1 AS n, - cast(hp2.street0VPI as integer) AS vpip, - cast(hp2.street0Aggr as integer) AS pfr, - cast(hp2.street0_3BChance as integer) AS TB_opp_0, - cast(hp2.street0_3BDone as integer) AS TB_0, - cast(hp2.street1Seen as integer) AS saw_f, - cast(hp2.street1Seen as integer) AS saw_1, - cast(hp2.street2Seen as integer) AS saw_2, - cast(hp2.street3Seen as integer) AS saw_3, - cast(hp2.street4Seen as integer) AS saw_4, - cast(hp2.sawShowdown as integer) AS sd, - cast(hp2.street1Aggr as integer) AS aggr_1, - cast(hp2.street2Aggr as integer) AS aggr_2, - cast(hp2.street3Aggr as integer) AS aggr_3, - cast(hp2.street4Aggr as integer) AS aggr_4, - cast(hp2.otherRaisedStreet1 as integer) AS was_raised_1, - cast(hp2.otherRaisedStreet2 as integer) AS was_raised_2, - cast(hp2.otherRaisedStreet3 as integer) AS was_raised_3, - cast(hp2.otherRaisedStreet4 as integer) AS was_raised_4, - cast(hp2.foldToOtherRaisedStreet1 as integer) AS f_freq_1, - cast(hp2.foldToOtherRaisedStreet2 as integer) AS f_freq_2, - cast(hp2.foldToOtherRaisedStreet3 as integer) AS f_freq_3, - cast(hp2.foldToOtherRaisedStreet4 as integer) AS f_freq_4, - cast(hp2.wonWhenSeenStreet1 as integer) AS w_w_s_1, - cast(hp2.wonAtSD as integer) AS wmsd, - cast(hp2.stealAttemptChance as integer) AS steal_opp, - cast(hp2.stealAttempted as integer) AS steal, - cast(hp2.foldSbToStealChance as integer) AS SBstolen, - cast(hp2.foldedSbToSteal as integer) AS SBnotDef, - cast(hp2.foldBbToStealChance as integer) AS BBstolen, - cast(hp2.foldedBbToSteal as integer) AS BBnotDef, - cast(hp2.street1CBChance as integer) AS CB_opp_1, - cast(hp2.street1CBDone as integer) AS CB_1, - cast(hp2.street2CBChance as integer) AS CB_opp_2, - cast(hp2.street2CBDone as integer) AS CB_2, - cast(hp2.street3CBChance as integer) AS CB_opp_3, - cast(hp2.street3CBDone as integer) AS CB_3, - cast(hp2.street4CBChance as integer) AS CB_opp_4, - cast(hp2.street4CBDone as integer) AS CB_4, - cast(hp2.foldToStreet1CBChance as integer) AS f_cb_opp_1, - cast(hp2.foldToStreet1CBDone as integer) AS f_cb_1, - cast(hp2.foldToStreet2CBChance as integer) AS f_cb_opp_2, - cast(hp2.foldToStreet2CBDone as integer) AS f_cb_2, - cast(hp2.foldToStreet3CBChance as integer) AS f_cb_opp_3, - cast(hp2.foldToStreet3CBDone as integer) AS f_cb_3, - cast(hp2.foldToStreet4CBChance as integer) AS f_cb_opp_4, - cast(hp2.foldToStreet4CBDone as integer) AS f_cb_4, - cast(hp2.totalProfit as integer) AS net, - cast(hp2.street1CheckCallRaiseChance as integer) AS ccr_opp_1, - cast(hp2.street1CheckCallRaiseDone as integer) AS ccr_1, - cast(hp2.street2CheckCallRaiseChance as integer) AS ccr_opp_2, - cast(hp2.street2CheckCallRaiseDone as integer) AS ccr_2, - cast(hp2.street3CheckCallRaiseChance as integer) AS ccr_opp_3, - cast(hp2.street3CheckCallRaiseDone as integer) AS ccr_3, - cast(hp2.street4CheckCallRaiseChance as integer) AS ccr_opp_4, - cast(hp2.street4CheckCallRaiseDone as integer) AS ccr_4 - FROM - Hands h /* players in this hand */ - INNER JOIN Hands h2 ON (h2.id > %s AND h2.tableName = h.tableName) - INNER JOIN HandsPlayers hp ON (h.id = hp.handId) - INNER JOIN HandsPlayers hp2 ON (hp2.playerId+0 = hp.playerId+0 AND (hp2.handId = h2.id+0)) /* other hands by these players */ - INNER JOIN Players p ON (p.id = hp2.PlayerId+0) - WHERE hp.handId = %s - /* check activeseats once this data returned (don't want to do that here as it might - assume a session ended just because the number of seats dipped for a few hands) - */ - ORDER BY h.handStart desc, hp2.PlayerId - /* order rows by handstart descending so that we can stop reading rows when - there's a gap over X minutes between hands (ie. when we get back to start of - the session */ - """ - else: # assume postgresql - self.query['get_stats_from_hand_session'] = """ - SELECT hp.playerId AS player_id, - hp.handId AS hand_id, - hp.seatNo AS seat, - p.name AS screen_name, - h.seats AS seats, - 1 AS n, - cast(hp2.street0VPI as integer) AS vpip, - cast(hp2.street0Aggr as integer) AS pfr, - cast(hp2.street0_3BChance as integer) AS TB_opp_0, - cast(hp2.street0_3BDone as integer) AS TB_0, - cast(hp2.street1Seen as integer) AS saw_f, - cast(hp2.street1Seen as integer) AS saw_1, - cast(hp2.street2Seen as integer) AS saw_2, - cast(hp2.street3Seen as integer) AS saw_3, - cast(hp2.street4Seen as integer) AS saw_4, - cast(hp2.sawShowdown as integer) AS sd, - cast(hp2.street1Aggr as integer) AS aggr_1, - cast(hp2.street2Aggr as integer) AS aggr_2, - cast(hp2.street3Aggr as integer) AS aggr_3, - cast(hp2.street4Aggr as integer) AS aggr_4, - cast(hp2.otherRaisedStreet1 as integer) AS was_raised_1, - cast(hp2.otherRaisedStreet2 as integer) AS was_raised_2, - cast(hp2.otherRaisedStreet3 as integer) AS was_raised_3, - cast(hp2.otherRaisedStreet4 as integer) AS was_raised_4, - cast(hp2.foldToOtherRaisedStreet1 as integer) AS f_freq_1, - cast(hp2.foldToOtherRaisedStreet2 as integer) AS f_freq_2, - cast(hp2.foldToOtherRaisedStreet3 as integer) AS f_freq_3, - cast(hp2.foldToOtherRaisedStreet4 as integer) AS f_freq_4, - cast(hp2.wonWhenSeenStreet1 as integer) AS w_w_s_1, - cast(hp2.wonAtSD as integer) AS wmsd, - cast(hp2.stealAttemptChance as integer) AS steal_opp, - cast(hp2.stealAttempted as integer) AS steal, - cast(hp2.foldSbToStealChance as integer) AS SBstolen, - cast(hp2.foldedSbToSteal as integer) AS SBnotDef, - cast(hp2.foldBbToStealChance as integer) AS BBstolen, - cast(hp2.foldedBbToSteal as integer) AS BBnotDef, - cast(hp2.street1CBChance as integer) AS CB_opp_1, - cast(hp2.street1CBDone as integer) AS CB_1, - cast(hp2.street2CBChance as integer) AS CB_opp_2, - cast(hp2.street2CBDone as integer) AS CB_2, - cast(hp2.street3CBChance as integer) AS CB_opp_3, - cast(hp2.street3CBDone as integer) AS CB_3, - cast(hp2.street4CBChance as integer) AS CB_opp_4, - cast(hp2.street4CBDone as integer) AS CB_4, - cast(hp2.foldToStreet1CBChance as integer) AS f_cb_opp_1, - cast(hp2.foldToStreet1CBDone as integer) AS f_cb_1, - cast(hp2.foldToStreet2CBChance as integer) AS f_cb_opp_2, - cast(hp2.foldToStreet2CBDone as integer) AS f_cb_2, - cast(hp2.foldToStreet3CBChance as integer) AS f_cb_opp_3, - cast(hp2.foldToStreet3CBDone as integer) AS f_cb_3, - cast(hp2.foldToStreet4CBChance as integer) AS f_cb_opp_4, - cast(hp2.foldToStreet4CBDone as integer) AS f_cb_4, - cast(hp2.totalProfit as integer) AS net, - cast(hp2.street1CheckCallRaiseChance as integer) AS ccr_opp_1, - cast(hp2.street1CheckCallRaiseDone as integer) AS ccr_1, - cast(hp2.street2CheckCallRaiseChance as integer) AS ccr_opp_2, - cast(hp2.street2CheckCallRaiseDone as integer) AS ccr_2, - cast(hp2.street3CheckCallRaiseChance as integer) AS ccr_opp_3, - cast(hp2.street3CheckCallRaiseDone as integer) AS ccr_3, - cast(hp2.street4CheckCallRaiseChance as integer) AS ccr_opp_4, - cast(hp2.street4CheckCallRaiseDone as integer) AS ccr_4 - FROM Hands h /* this hand */ - INNER JOIN Hands h2 ON ( h2.id > %s /* other hands */ - AND h2.tableName = h.tableName) - INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */ - INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0 - AND hp2.handId = h2.id) /* other hands by these players */ - INNER JOIN Players p ON (p.id = hp2.PlayerId+0) - WHERE h.id = %s - /* check activeseats once this data returned (don't want to do that here as it might - assume a session ended just because the number of seats dipped for a few hands) - */ - ORDER BY h.handStart desc, hp2.PlayerId - /* order rows by handstart descending so that we can stop reading rows when - there's a gap over X minutes between hands (ie. when we get back to start of - the session */ - """ - - self.query['get_players_from_hand'] = """ - SELECT HandsPlayers.playerId, seatNo, name - FROM HandsPlayers INNER JOIN Players ON (HandsPlayers.playerId = Players.id) - WHERE handId = %s + if db_server == 'mysql': + self.query['get_stats_from_hand_session'] = """ + SELECT hp.playerId AS player_id, + hp.handId AS hand_id, + hp.seatNo AS seat, + p.name AS screen_name, + h.seats AS seats, + 1 AS n, + cast(hp2.street0VPI as integer) AS vpip, + cast(hp2.street0Aggr as integer) AS pfr, + cast(hp2.street0_3BChance as integer) AS TB_opp_0, + cast(hp2.street0_3BDone as integer) AS TB_0, + cast(hp2.street1Seen as integer) AS saw_f, + cast(hp2.street1Seen as integer) AS saw_1, + cast(hp2.street2Seen as integer) AS saw_2, + cast(hp2.street3Seen as integer) AS saw_3, + cast(hp2.street4Seen as integer) AS saw_4, + cast(hp2.sawShowdown as integer) AS sd, + cast(hp2.street1Aggr as integer) AS aggr_1, + cast(hp2.street2Aggr as integer) AS aggr_2, + cast(hp2.street3Aggr as integer) AS aggr_3, + cast(hp2.street4Aggr as integer) AS aggr_4, + cast(hp2.otherRaisedStreet1 as integer) AS was_raised_1, + cast(hp2.otherRaisedStreet2 as integer) AS was_raised_2, + cast(hp2.otherRaisedStreet3 as integer) AS was_raised_3, + cast(hp2.otherRaisedStreet4 as integer) AS was_raised_4, + cast(hp2.foldToOtherRaisedStreet1 as integer) AS f_freq_1, + cast(hp2.foldToOtherRaisedStreet2 as integer) AS f_freq_2, + cast(hp2.foldToOtherRaisedStreet3 as integer) AS f_freq_3, + cast(hp2.foldToOtherRaisedStreet4 as integer) AS f_freq_4, + cast(hp2.wonWhenSeenStreet1 as integer) AS w_w_s_1, + cast(hp2.wonAtSD as integer) AS wmsd, + cast(hp2.stealAttemptChance as integer) AS steal_opp, + cast(hp2.stealAttempted as integer) AS steal, + cast(hp2.foldSbToStealChance as integer) AS SBstolen, + cast(hp2.foldedSbToSteal as integer) AS SBnotDef, + cast(hp2.foldBbToStealChance as integer) AS BBstolen, + cast(hp2.foldedBbToSteal as integer) AS BBnotDef, + cast(hp2.street1CBChance as integer) AS CB_opp_1, + cast(hp2.street1CBDone as integer) AS CB_1, + cast(hp2.street2CBChance as integer) AS CB_opp_2, + cast(hp2.street2CBDone as integer) AS CB_2, + cast(hp2.street3CBChance as integer) AS CB_opp_3, + cast(hp2.street3CBDone as integer) AS CB_3, + cast(hp2.street4CBChance as integer) AS CB_opp_4, + cast(hp2.street4CBDone as integer) AS CB_4, + cast(hp2.foldToStreet1CBChance as integer) AS f_cb_opp_1, + cast(hp2.foldToStreet1CBDone as integer) AS f_cb_1, + cast(hp2.foldToStreet2CBChance as integer) AS f_cb_opp_2, + cast(hp2.foldToStreet2CBDone as integer) AS f_cb_2, + cast(hp2.foldToStreet3CBChance as integer) AS f_cb_opp_3, + cast(hp2.foldToStreet3CBDone as integer) AS f_cb_3, + cast(hp2.foldToStreet4CBChance as integer) AS f_cb_opp_4, + cast(hp2.foldToStreet4CBDone as integer) AS f_cb_4, + cast(hp2.totalProfit as integer) AS net, + cast(hp2.street1CheckCallRaiseChance as integer) AS ccr_opp_1, + cast(hp2.street1CheckCallRaiseDone as integer) AS ccr_1, + cast(hp2.street2CheckCallRaiseChance as integer) AS ccr_opp_2, + cast(hp2.street2CheckCallRaiseDone as integer) AS ccr_2, + cast(hp2.street3CheckCallRaiseChance as integer) AS ccr_opp_3, + cast(hp2.street3CheckCallRaiseDone as integer) AS ccr_3, + cast(hp2.street4CheckCallRaiseChance as integer) AS ccr_opp_4, + cast(hp2.street4CheckCallRaiseDone as integer) AS ccr_4 + FROM + Hands h /* players in this hand */ + INNER JOIN Hands h2 ON (h2.id > %s AND h2.tableName = h.tableName) + INNER JOIN HandsPlayers hp ON (h.id = hp.handId) + INNER JOIN HandsPlayers hp2 ON (hp2.playerId+0 = hp.playerId+0 AND (hp2.handId = h2.id+0)) /* other hands by these players */ + INNER JOIN Players p ON (p.id = hp2.PlayerId+0) + WHERE hp.handId = %s + /* check activeseats once this data returned (don't want to do that here as it might + assume a session ended just because the number of seats dipped for a few hands) + */ + ORDER BY h.handStart desc, hp2.PlayerId + /* order rows by handstart descending so that we can stop reading rows when + there's a gap over X minutes between hands (ie. when we get back to start of + the session */ """ + else: # assume postgresql + self.query['get_stats_from_hand_session'] = """ + SELECT hp.playerId AS player_id, + hp.handId AS hand_id, + hp.seatNo AS seat, + p.name AS screen_name, + h.seats AS seats, + 1 AS n, + cast(hp2.street0VPI as integer) AS vpip, + cast(hp2.street0Aggr as integer) AS pfr, + cast(hp2.street0_3BChance as integer) AS TB_opp_0, + cast(hp2.street0_3BDone as integer) AS TB_0, + cast(hp2.street1Seen as integer) AS saw_f, + cast(hp2.street1Seen as integer) AS saw_1, + cast(hp2.street2Seen as integer) AS saw_2, + cast(hp2.street3Seen as integer) AS saw_3, + cast(hp2.street4Seen as integer) AS saw_4, + cast(hp2.sawShowdown as integer) AS sd, + cast(hp2.street1Aggr as integer) AS aggr_1, + cast(hp2.street2Aggr as integer) AS aggr_2, + cast(hp2.street3Aggr as integer) AS aggr_3, + cast(hp2.street4Aggr as integer) AS aggr_4, + cast(hp2.otherRaisedStreet1 as integer) AS was_raised_1, + cast(hp2.otherRaisedStreet2 as integer) AS was_raised_2, + cast(hp2.otherRaisedStreet3 as integer) AS was_raised_3, + cast(hp2.otherRaisedStreet4 as integer) AS was_raised_4, + cast(hp2.foldToOtherRaisedStreet1 as integer) AS f_freq_1, + cast(hp2.foldToOtherRaisedStreet2 as integer) AS f_freq_2, + cast(hp2.foldToOtherRaisedStreet3 as integer) AS f_freq_3, + cast(hp2.foldToOtherRaisedStreet4 as integer) AS f_freq_4, + cast(hp2.wonWhenSeenStreet1 as integer) AS w_w_s_1, + cast(hp2.wonAtSD as integer) AS wmsd, + cast(hp2.stealAttemptChance as integer) AS steal_opp, + cast(hp2.stealAttempted as integer) AS steal, + cast(hp2.foldSbToStealChance as integer) AS SBstolen, + cast(hp2.foldedSbToSteal as integer) AS SBnotDef, + cast(hp2.foldBbToStealChance as integer) AS BBstolen, + cast(hp2.foldedBbToSteal as integer) AS BBnotDef, + cast(hp2.street1CBChance as integer) AS CB_opp_1, + cast(hp2.street1CBDone as integer) AS CB_1, + cast(hp2.street2CBChance as integer) AS CB_opp_2, + cast(hp2.street2CBDone as integer) AS CB_2, + cast(hp2.street3CBChance as integer) AS CB_opp_3, + cast(hp2.street3CBDone as integer) AS CB_3, + cast(hp2.street4CBChance as integer) AS CB_opp_4, + cast(hp2.street4CBDone as integer) AS CB_4, + cast(hp2.foldToStreet1CBChance as integer) AS f_cb_opp_1, + cast(hp2.foldToStreet1CBDone as integer) AS f_cb_1, + cast(hp2.foldToStreet2CBChance as integer) AS f_cb_opp_2, + cast(hp2.foldToStreet2CBDone as integer) AS f_cb_2, + cast(hp2.foldToStreet3CBChance as integer) AS f_cb_opp_3, + cast(hp2.foldToStreet3CBDone as integer) AS f_cb_3, + cast(hp2.foldToStreet4CBChance as integer) AS f_cb_opp_4, + cast(hp2.foldToStreet4CBDone as integer) AS f_cb_4, + cast(hp2.totalProfit as integer) AS net, + cast(hp2.street1CheckCallRaiseChance as integer) AS ccr_opp_1, + cast(hp2.street1CheckCallRaiseDone as integer) AS ccr_1, + cast(hp2.street2CheckCallRaiseChance as integer) AS ccr_opp_2, + cast(hp2.street2CheckCallRaiseDone as integer) AS ccr_2, + cast(hp2.street3CheckCallRaiseChance as integer) AS ccr_opp_3, + cast(hp2.street3CheckCallRaiseDone as integer) AS ccr_3, + cast(hp2.street4CheckCallRaiseChance as integer) AS ccr_opp_4, + cast(hp2.street4CheckCallRaiseDone as integer) AS ccr_4 + FROM Hands h /* this hand */ + INNER JOIN Hands h2 ON ( h2.id > %s /* other hands */ + AND h2.tableName = h.tableName) + INNER JOIN HandsPlayers hp ON (h.id = hp.handId) /* players in this hand */ + INNER JOIN HandsPlayers hp2 ON ( hp2.playerId+0 = hp.playerId+0 + AND hp2.handId = h2.id) /* other hands by these players */ + INNER JOIN Players p ON (p.id = hp2.PlayerId+0) + WHERE h.id = %s + /* check activeseats once this data returned (don't want to do that here as it might + assume a session ended just because the number of seats dipped for a few hands) + */ + ORDER BY h.handStart desc, hp2.PlayerId + /* order rows by handstart descending so that we can stop reading rows when + there's a gap over X minutes between hands (ie. when we get back to start of + the session */ + """ + + self.query['get_players_from_hand'] = """ + SELECT HandsPlayers.playerId, seatNo, name + FROM HandsPlayers INNER JOIN Players ON (HandsPlayers.playerId = Players.id) + WHERE handId = %s + """ # WHERE handId = %s AND Players.id LIKE %s - self.query['get_winners_from_hand'] = """ - SELECT name, winnings - FROM HandsPlayers, Players - WHERE winnings > 0 - AND Players.id = HandsPlayers.playerId - AND handId = %s; - """ - - self.query['get_table_name'] = """ - SELECT h.tableName, h.maxSeats, gt.category, gt.type, s.id, s.name - FROM Hands h, Gametypes gt, Sites s - WHERE h.id = %s - AND gt.id = h.gametypeId - AND s.id = gt.siteID - """ - - self.query['get_actual_seat'] = """ - select seatNo - from HandsPlayers - where HandsPlayers.handId = %s - and HandsPlayers.playerId = (select Players.id from Players - where Players.name = %s) - """ - - self.query['get_cards'] = """ - select - seatNo AS seat_number, - card1, /*card1Value, card1Suit, */ - card2, /*card2Value, card2Suit, */ - card3, /*card3Value, card3Suit, */ - card4, /*card4Value, card4Suit, */ - card5, /*card5Value, card5Suit, */ - card6, /*card6Value, card6Suit, */ - card7 /*card7Value, card7Suit */ - from HandsPlayers, Players - where handID = %s and HandsPlayers.playerId = Players.id - order by seatNo - """ - - self.query['get_common_cards'] = """ - select - boardcard1, - boardcard2, - boardcard3, - boardcard4, - boardcard5 - from Hands - where Id = %s - """ - - self.query['get_action_from_hand'] = """ - SELECT street, Players.name, HandsActions.action, HandsActions.amount, actionno - FROM Players, HandsActions, HandsPlayers - WHERE HandsPlayers.handid = %s - AND HandsPlayers.playerid = Players.id - AND HandsActions.handsPlayerId = HandsPlayers.id - ORDER BY street, actionno + self.query['get_winners_from_hand'] = """ + SELECT name, winnings + FROM HandsPlayers, Players + WHERE winnings > 0 + AND Players.id = HandsPlayers.playerId + AND handId = %s; """ - if db_server == 'mysql': - self.query['get_hand_1day_ago'] = """ - select coalesce(max(id),0) - from Hands - where handStart < date_sub(utc_timestamp(), interval '1' day)""" - elif db_server == 'postgresql': - self.query['get_hand_1day_ago'] = """ - select coalesce(max(id),0) - from Hands - where handStart < now() at time zone 'UTC' - interval '1 day'""" - elif db_server == 'sqlite': - self.query['get_hand_1day_ago'] = """ - select coalesce(max(id),0) - from Hands - where handStart < strftime('%J', 'now') - 1""" + self.query['get_table_name'] = """ + SELECT h.tableName, h.maxSeats, gt.category, gt.type, s.id, s.name + FROM Hands h, Gametypes gt, Sites s + WHERE h.id = %s + AND gt.id = h.gametypeId + AND s.id = gt.siteID + """ - # not used yet ... - # gets a date, would need to use handsplayers (not hudcache) to get exact hand Id - if db_server == 'mysql': - self.query['get_date_nhands_ago'] = """ - select concat( 'd', date_format(max(h.handStart), '%Y%m%d') ) - from (select hp.playerId - ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx - from HandsPlayers hp - where hp.playerId = %s - group by hp.playerId) hp2 - inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx - and hp3.playerId = hp2.playerId) - inner join Hands h on (h.id = hp3.handId) - """ - elif db_server == 'postgresql': - self.query['get_date_nhands_ago'] = """ - select 'd' || to_char(max(h3.handStart), 'YYMMDD') - from (select hp.playerId - ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx - from HandsPlayers hp - where hp.playerId = %s - group by hp.playerId) hp2 - inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx - and hp3.playerId = hp2.playerId) - inner join Hands h on (h.id = hp3.handId) - """ - elif db_server == 'sqlite': # untested guess at query: - self.query['get_date_nhands_ago'] = """ - select 'd' || strftime(max(h3.handStart), 'YYMMDD') - from (select hp.playerId - ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx - from HandsPlayers hp - where hp.playerId = %s - group by hp.playerId) hp2 - inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx - and hp3.playerId = hp2.playerId) - inner join Hands h on (h.id = hp3.handId) - """ + self.query['get_actual_seat'] = """ + select seatNo + from HandsPlayers + where HandsPlayers.handId = %s + and HandsPlayers.playerId = (select Players.id from Players + where Players.name = %s) + """ - # used in GuiPlayerStats: - self.query['getPlayerId'] = """SELECT id from Players where name = %s""" + self.query['get_cards'] = """ + select + seatNo AS seat_number, + card1, /*card1Value, card1Suit, */ + card2, /*card2Value, card2Suit, */ + card3, /*card3Value, card3Suit, */ + card4, /*card4Value, card4Suit, */ + card5, /*card5Value, card5Suit, */ + card6, /*card6Value, card6Suit, */ + card7 /*card7Value, card7Suit */ + from HandsPlayers, Players + where handID = %s and HandsPlayers.playerId = Players.id + order by seatNo + """ - self.query['getPlayerIdBySite'] = """SELECT id from Players where name = %s AND siteId = %s""" + self.query['get_common_cards'] = """ + select + boardcard1, + boardcard2, + boardcard3, + boardcard4, + boardcard5 + from Hands + where Id = %s + """ + + if db_server == 'mysql': + self.query['get_hand_1day_ago'] = """ + select coalesce(max(id),0) + from Hands + where handStart < date_sub(utc_timestamp(), interval '1' day)""" + elif db_server == 'postgresql': + self.query['get_hand_1day_ago'] = """ + select coalesce(max(id),0) + from Hands + where handStart < now() at time zone 'UTC' - interval '1 day'""" + elif db_server == 'sqlite': + self.query['get_hand_1day_ago'] = """ + select coalesce(max(id),0) + from Hands + where handStart < strftime('%J', 'now') - 1""" + + # not used yet ... + # gets a date, would need to use handsplayers (not hudcache) to get exact hand Id + if db_server == 'mysql': + self.query['get_date_nhands_ago'] = """ + select concat( 'd', date_format(max(h.handStart), '%Y%m%d') ) + from (select hp.playerId + ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx + from HandsPlayers hp + where hp.playerId = %s + group by hp.playerId) hp2 + inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx + and hp3.playerId = hp2.playerId) + inner join Hands h on (h.id = hp3.handId) + """ + elif db_server == 'postgresql': + self.query['get_date_nhands_ago'] = """ + select 'd' || to_char(max(h3.handStart), 'YYMMDD') + from (select hp.playerId + ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx + from HandsPlayers hp + where hp.playerId = %s + group by hp.playerId) hp2 + inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx + and hp3.playerId = hp2.playerId) + inner join Hands h on (h.id = hp3.handId) + """ + elif db_server == 'sqlite': # untested guess at query: + self.query['get_date_nhands_ago'] = """ + select 'd' || strftime(max(h3.handStart), 'YYMMDD') + from (select hp.playerId + ,coalesce(greatest(max(hp.handId)-%s,1),1) as maxminusx + from HandsPlayers hp + where hp.playerId = %s + group by hp.playerId) hp2 + inner join HandsPlayers hp3 on ( hp3.handId <= hp2.maxminusx + and hp3.playerId = hp2.playerId) + inner join Hands h on (h.id = hp3.handId) + """ + + # used in GuiPlayerStats: + self.query['getPlayerId'] = """SELECT id from Players where name = %s""" + + self.query['getPlayerIdBySite'] = """SELECT id from Players where name = %s AND siteId = %s""" - # used in Filters: - self.query['getSiteId'] = """SELECT id from Sites where name = %s""" - self.query['getGames'] = """SELECT DISTINCT category from Gametypes""" - self.query['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC""" - self.query['getLimits2'] = """SELECT DISTINCT type, limitType, bigBlind - from Gametypes - ORDER by type, limitType DESC, bigBlind DESC""" + # used in Filters: + self.query['getSiteId'] = """SELECT id from Sites where name = %s""" + self.query['getGames'] = """SELECT DISTINCT category from Gametypes""" + self.query['getLimits'] = """SELECT DISTINCT bigBlind from Gametypes ORDER by bigBlind DESC""" + self.query['getLimits2'] = """SELECT DISTINCT type, limitType, bigBlind + from Gametypes + ORDER by type, limitType DESC, bigBlind DESC""" - if db_server == 'mysql': - self.query['playerDetailedStats'] = """ - select AS hgametypeid - , AS pname - ,gt.base - ,gt.category - ,upper(gt.limitType) AS limittype - ,s.name - ,min(gt.bigBlind) AS minbigblind - ,max(gt.bigBlind) AS maxbigblind - /*, AS gtid*/ - , AS plposition - ,count(1) AS n - ,100.0*sum(cast(hp.street0VPI as integer))/count(1) AS vpip - ,100.0*sum(cast(hp.street0Aggr as integer))/count(1) AS pfr - ,case when sum(cast(hp.street0_3Bchance as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street0_3Bdone as integer))/sum(cast(hp.street0_3Bchance as integer)) - end AS pf3 - ,case when sum(cast(hp.stealattemptchance as integer)) = 0 then -999 - else 100.0*sum(cast(hp.stealattempted as integer))/sum(cast(hp.stealattemptchance as integer)) - end AS steals - ,100.0*sum(cast(hp.street1Seen as integer))/count(1) AS saw_f - ,100.0*sum(cast(hp.sawShowdown as integer))/count(1) AS sawsd - ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.sawShowdown as integer))/sum(cast(hp.street1Seen as integer)) - end AS wtsdwsf - ,case when sum(cast(hp.sawShowdown as integer)) = 0 then -999 - else 100.0*sum(cast(hp.wonAtSD as integer))/sum(cast(hp.sawShowdown as integer)) - end AS wmsd - ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street1Aggr as integer))/sum(cast(hp.street1Seen as integer)) - end AS flafq - ,case when sum(cast(hp.street2Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street2Aggr as integer))/sum(cast(hp.street2Seen as integer)) - end AS tuafq - ,case when sum(cast(hp.street3Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street3Aggr as integer))/sum(cast(hp.street3Seen as integer)) - end AS rvafq - ,case when sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer)) = 0 then -999 - else 100.0*(sum(cast(hp.street1Aggr as integer))+sum(cast(hp.street2Aggr as integer))+sum(cast(hp.street3Aggr as integer))) - /(sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer))) - end AS pofafq - ,sum(hp.totalProfit)/100.0 AS net - ,sum(hp.rake)/100.0 AS rake - ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100 - ,avg(hp.totalProfit)/100.0 AS profitperhand - ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr - ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr - ,avg(h.seats+0.0) AS avgseats - ,variance(hp.totalProfit/100.0) AS variance - from HandsPlayers hp - inner join Hands h on (h.id = hp.handId) - inner join Gametypes gt on (gt.Id = h.gameTypeId) - inner join Sites s on (s.Id = gt.siteId) - inner join Players p on (p.Id = hp.playerId) - where hp.playerId in - /*and hp.tourneysPlayersId IS NULL*/ - and h.seats - - - and date_format(h.handStart, '%Y-%m-%d') - group by hgameTypeId - ,pname - ,gt.base - ,gt.category - - ,plposition - ,upper(gt.limitType) - ,s.name - having 1 = 1 - order by pname - ,gt.base - ,gt.category - - ,case when 'B' then 'B' - when 'S' then 'S' - else concat('Z', ) - end - - ,upper(gt.limitType) desc - ,maxbigblind desc - ,s.name - """ - elif db_server == 'postgresql': - self.query['playerDetailedStats'] = """ - select AS hgametypeid - , AS pname - ,gt.base - ,gt.category - ,upper(gt.limitType) AS limittype - ,s.name - ,min(gt.bigBlind) AS minbigblind - ,max(gt.bigBlind) AS maxbigblind - /*, AS gtid*/ - , AS plposition - ,count(1) AS n - ,100.0*sum(cast(hp.street0VPI as integer))/count(1) AS vpip - ,100.0*sum(cast(hp.street0Aggr as integer))/count(1) AS pfr - ,case when sum(cast(hp.street0_3Bchance as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street0_3Bdone as integer))/sum(cast(hp.street0_3Bchance as integer)) - end AS pf3 - ,case when sum(cast(hp.stealattemptchance as integer)) = 0 then -999 - else 100.0*sum(cast(hp.stealattempted as integer))/sum(cast(hp.stealattemptchance as integer)) - end AS steals - ,100.0*sum(cast(hp.street1Seen as integer))/count(1) AS saw_f - ,100.0*sum(cast(hp.sawShowdown as integer))/count(1) AS sawsd - ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.sawShowdown as integer))/sum(cast(hp.street1Seen as integer)) - end AS wtsdwsf - ,case when sum(cast(hp.sawShowdown as integer)) = 0 then -999 - else 100.0*sum(cast(hp.wonAtSD as integer))/sum(cast(hp.sawShowdown as integer)) - end AS wmsd - ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street1Aggr as integer))/sum(cast(hp.street1Seen as integer)) - end AS flafq - ,case when sum(cast(hp.street2Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street2Aggr as integer))/sum(cast(hp.street2Seen as integer)) - end AS tuafq - ,case when sum(cast(hp.street3Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street3Aggr as integer))/sum(cast(hp.street3Seen as integer)) - end AS rvafq - ,case when sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer)) = 0 then -999 - else 100.0*(sum(cast(hp.street1Aggr as integer))+sum(cast(hp.street2Aggr as integer))+sum(cast(hp.street3Aggr as integer))) - /(sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer))) - end AS pofafq - ,sum(hp.totalProfit)/100.0 AS net - ,sum(hp.rake)/100.0 AS rake - ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100 - ,avg(hp.totalProfit)/100.0 AS profitperhand - ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr - ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr - ,avg(h.seats+0.0) AS avgseats - ,variance(hp.totalProfit/100.0) AS variance - from HandsPlayers hp - inner join Hands h on (h.id = hp.handId) - inner join Gametypes gt on (gt.Id = h.gameTypeId) - inner join Sites s on (s.Id = gt.siteId) - inner join Players p on (p.Id = hp.playerId) - where hp.playerId in - /*and hp.tourneysPlayersId IS NULL*/ - and h.seats - - - and to_char(h.handStart, 'YYYY-MM-DD') - group by hgameTypeId - ,pname - ,gt.base - ,gt.category - - ,plposition - ,upper(gt.limitType) - ,s.name - having 1 = 1 - order by pname - ,gt.base - ,gt.category - - ,case when 'B' then 'B' - when 'S' then 'S' - when '0' then 'Y' - else 'Z'|| - end - - ,upper(gt.limitType) desc - ,maxbigblind desc - ,s.name - """ - elif db_server == 'sqlite': - self.query['playerDetailedStats'] = """ - select AS hgametypeid - ,gt.base - ,gt.category AS category - ,upper(gt.limitType) AS limittype - ,s.name AS name - ,min(gt.bigBlind) AS minbigblind - ,max(gt.bigBlind) AS maxbigblind - /*, AS gtid*/ - , AS plposition - ,count(1) AS n - ,100.0*sum(cast(hp.street0VPI as integer))/count(1) AS vpip - ,100.0*sum(cast(hp.street0Aggr as integer))/count(1) AS pfr - ,case when sum(cast(hp.street0_3Bchance as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street0_3Bdone as integer))/sum(cast(hp.street0_3Bchance as integer)) - end AS pf3 - ,case when sum(cast(hp.stealattemptchance as integer)) = 0 then -999 - else 100.0*sum(cast(hp.stealattempted as integer))/sum(cast(hp.stealattemptchance as integer)) - end AS steals - ,100.0*sum(cast(hp.street1Seen as integer))/count(1) AS saw_f - ,100.0*sum(cast(hp.sawShowdown as integer))/count(1) AS sawsd - ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.sawShowdown as integer))/sum(cast(hp.street1Seen as integer)) - end AS wtsdwsf - ,case when sum(cast(hp.sawShowdown as integer)) = 0 then -999 - else 100.0*sum(cast(hp.wonAtSD as integer))/sum(cast(hp.sawShowdown as integer)) - end AS wmsd - ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street1Aggr as integer))/sum(cast(hp.street1Seen as integer)) - end AS flafq - ,case when sum(cast(hp.street2Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street2Aggr as integer))/sum(cast(hp.street2Seen as integer)) - end AS tuafq - ,case when sum(cast(hp.street3Seen as integer)) = 0 then -999 - else 100.0*sum(cast(hp.street3Aggr as integer))/sum(cast(hp.street3Seen as integer)) - end AS rvafq - ,case when sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer)) = 0 then -999 - else 100.0*(sum(cast(hp.street1Aggr as integer))+sum(cast(hp.street2Aggr as integer))+sum(cast(hp.street3Aggr as integer))) - /(sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer))) - end AS pofafq - ,sum(hp.totalProfit)/100.0 AS net - ,sum(hp.rake)/100.0 AS rake - ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100 - ,avg(hp.totalProfit)/100.0 AS profitperhand - ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr - ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr - ,avg(h.seats+0.0) AS avgseats - /*,variance(hp.totalProfit/100.0) AS variance*/ - ,0.0 AS variance - from HandsPlayers hp - inner join Hands h on (h.id = hp.handId) - inner join Gametypes gt on (gt.Id = h.gameTypeId) - inner join Sites s on (s.Id = gt.siteId) - where hp.playerId in - /*and hp.tourneysPlayersId IS NULL*/ - and h.seats - - - and to_char(h.handStart, 'YYYY-MM-DD') - group by hgameTypeId - ,hp.playerId - ,gt.base - ,gt.category - - ,plposition - ,upper(gt.limitType) - ,s.name - order by hp.playerId - ,gt.base - ,gt.category - - ,case when 'B' then 'B' - when 'S' then 'S' - when '0' then 'Y' - else 'Z'|| - end - - ,upper(gt.limitType) desc - ,maxbigblind desc - ,s.name - """ - - if db_server == 'mysql': - self.query['playerStats'] = """ - SELECT - concat(upper(stats.limitType), ' ' - ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' ' - ,stats.name, ' ' - ,cast(stats.bigBlindDesc as char) - ) AS Game - ,stats.n - ,stats.vpip - ,stats.pfr - ,stats.pf3 - ,stats.steals - ,stats.saw_f - ,stats.sawsd - ,stats.wtsdwsf - ,stats.wmsd - ,stats.FlAFq - ,stats.TuAFq - ,stats.RvAFq - ,stats.PoFAFq - ,stats.Net - ,stats.BBper100 - ,stats.Profitperhand - ,case when hprof2.variance = -999 then '-' - else format(hprof2.variance, 2) - end AS Variance - ,stats.AvgSeats - FROM - (select /* stats from hudcache */ - gt.base - ,gt.category - ,upper(gt.limitType) as limitType - ,s.name - , AS bigBlindDesc - , AS gtId - ,sum(HDs) AS n - ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip - ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr - ,case when sum(street0_3Bchance) = 0 then '0' - else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1) - end AS pf3 - ,case when sum(stealattemptchance) = 0 then '-' - else format(100.0*sum(stealattempted)/sum(stealattemptchance),1) - end AS steals - ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f - ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd - ,case when sum(street1Seen) = 0 then '-' - else format(100.0*sum(sawShowdown)/sum(street1Seen),1) - end AS wtsdwsf - ,case when sum(sawShowdown) = 0 then '-' - else format(100.0*sum(wonAtSD)/sum(sawShowdown),1) - end AS wmsd - ,case when sum(street1Seen) = 0 then '-' - else format(100.0*sum(street1Aggr)/sum(street1Seen),1) - end AS FlAFq - ,case when sum(street2Seen) = 0 then '-' - else format(100.0*sum(street2Aggr)/sum(street2Seen),1) - end AS TuAFq - ,case when sum(street3Seen) = 0 then '-' - else format(100.0*sum(street3Aggr)/sum(street3Seen),1) - end AS RvAFq - ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-' - else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr)) - /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1) - end AS PoFAFq - ,format(sum(totalProfit)/100.0,2) AS Net - ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2) - AS BBper100 - ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand - ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats - from Gametypes gt - inner join Sites s on s.Id = gt.siteId - inner join HudCache hc on hc.gameTypeId = gt.Id - where hc.playerId in - and - and hc.activeSeats - and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-' - , substring(hc.styleKey,6,2) ) - group by gt.base + if db_server == 'mysql': + self.query['playerDetailedStats'] = """ + select AS hgametypeid + , AS pname + ,gt.base + ,gt.category + ,upper(gt.limitType) AS limittype + ,s.name + ,min(gt.bigBlind) AS minbigblind + ,max(gt.bigBlind) AS maxbigblind + /*, AS gtid*/ + , AS plposition + ,count(1) AS n + ,100.0*sum(cast(hp.street0VPI as integer))/count(1) AS vpip + ,100.0*sum(cast(hp.street0Aggr as integer))/count(1) AS pfr + ,case when sum(cast(hp.street0_3Bchance as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street0_3Bdone as integer))/sum(cast(hp.street0_3Bchance as integer)) + end AS pf3 + ,case when sum(cast(hp.stealattemptchance as integer)) = 0 then -999 + else 100.0*sum(cast(hp.stealattempted as integer))/sum(cast(hp.stealattemptchance as integer)) + end AS steals + ,100.0*sum(cast(hp.street1Seen as integer))/count(1) AS saw_f + ,100.0*sum(cast(hp.sawShowdown as integer))/count(1) AS sawsd + ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.sawShowdown as integer))/sum(cast(hp.street1Seen as integer)) + end AS wtsdwsf + ,case when sum(cast(hp.sawShowdown as integer)) = 0 then -999 + else 100.0*sum(cast(hp.wonAtSD as integer))/sum(cast(hp.sawShowdown as integer)) + end AS wmsd + ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street1Aggr as integer))/sum(cast(hp.street1Seen as integer)) + end AS flafq + ,case when sum(cast(hp.street2Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street2Aggr as integer))/sum(cast(hp.street2Seen as integer)) + end AS tuafq + ,case when sum(cast(hp.street3Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street3Aggr as integer))/sum(cast(hp.street3Seen as integer)) + end AS rvafq + ,case when sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer)) = 0 then -999 + else 100.0*(sum(cast(hp.street1Aggr as integer))+sum(cast(hp.street2Aggr as integer))+sum(cast(hp.street3Aggr as integer))) + /(sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer))) + end AS pofafq + ,sum(hp.totalProfit)/100.0 AS net + ,sum(hp.rake)/100.0 AS rake + ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100 + ,avg(hp.totalProfit)/100.0 AS profitperhand + ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr + ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr + ,avg(h.seats+0.0) AS avgseats + ,variance(hp.totalProfit/100.0) AS variance + from HandsPlayers hp + inner join Hands h on (h.id = hp.handId) + inner join Gametypes gt on (gt.Id = h.gameTypeId) + inner join Sites s on (s.Id = gt.siteId) + inner join Players p on (p.Id = hp.playerId) + where hp.playerId in + /*and hp.tourneysPlayersId IS NULL*/ + and h.seats + + + and date_format(h.handStart, '%Y-%m-%d') + group by hgameTypeId + ,pname + ,gt.base ,gt.category - ,upper(gt.limitType) - ,s.name - - ,gtId - ) stats - inner join - ( select # profit from handsplayers/handsactions - hprof.gtId, sum(hprof.profit) sum_profit, - avg(hprof.profit/100.0) profitperhand, - case when hprof.gtId = -1 then -999 - else variance(hprof.profit/100.0) - end as variance - from - (select hp.handId, as gtId, hp.totalProfit as profit - from HandsPlayers hp - inner join Hands h ON h.id = hp.handId - where hp.playerId in - and hp.tourneysPlayersId IS NULL - and date_format(h.handStart, '%Y-%m-%d') - group by hp.handId, gtId, hp.totalProfit - ) hprof - group by hprof.gtId - ) hprof2 - on hprof2.gtId = stats.gtId - order by stats.category, stats.limittype, stats.bigBlindDesc desc """ - else: # assume postgres - self.query['playerStats'] = """ - SELECT upper(stats.limitType) || ' ' - || initcap(stats.category) || ' ' - || stats.name || ' ' - || stats.bigBlindDesc AS Game - ,stats.n - ,stats.vpip - ,stats.pfr - ,stats.pf3 - ,stats.steals - ,stats.saw_f - ,stats.sawsd - ,stats.wtsdwsf - ,stats.wmsd - ,stats.FlAFq - ,stats.TuAFq - ,stats.RvAFq - ,stats.PoFAFq - ,stats.Net - ,stats.BBper100 - ,stats.Profitperhand - ,case when hprof2.variance = -999 then '-' - else to_char(hprof2.variance, '0D00') - end AS Variance - ,AvgSeats - FROM - (select gt.base - ,gt.category - ,upper(gt.limitType) AS limitType - ,s.name - , AS bigBlindDesc - , AS gtId - ,sum(HDs) as n - ,to_char(100.0*sum(street0VPI)/sum(HDs),'990D0') AS vpip - ,to_char(100.0*sum(street0Aggr)/sum(HDs),'90D0') AS pfr - ,case when sum(street0_3Bchance) = 0 then '0' - else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0') - end AS pf3 - ,case when sum(stealattemptchance) = 0 then '-' - else to_char(100.0*sum(stealattempted)/sum(stealattemptchance),'90D0') - end AS steals - ,to_char(100.0*sum(street1Seen)/sum(HDs),'90D0') AS saw_f - ,to_char(100.0*sum(sawShowdown)/sum(HDs),'90D0') AS sawsd - ,case when sum(street1Seen) = 0 then '-' - else to_char(100.0*sum(sawShowdown)/sum(street1Seen),'90D0') - end AS wtsdwsf - ,case when sum(sawShowdown) = 0 then '-' - else to_char(100.0*sum(wonAtSD)/sum(sawShowdown),'90D0') - end AS wmsd - ,case when sum(street1Seen) = 0 then '-' - else to_char(100.0*sum(street1Aggr)/sum(street1Seen),'90D0') - end AS FlAFq - ,case when sum(street2Seen) = 0 then '-' - else to_char(100.0*sum(street2Aggr)/sum(street2Seen),'90D0') - end AS TuAFq - ,case when sum(street3Seen) = 0 then '-' - else to_char(100.0*sum(street3Aggr)/sum(street3Seen),'90D0') - end AS RvAFq - ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-' - else to_char(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr)) - /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),'90D0') - end AS PoFAFq - ,round(sum(totalProfit)/100.0,2) AS Net - ,to_char((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0), '990D00') - AS BBper100 - ,to_char(sum(totalProfit/100.0) / (sum(HDs)+0.0), '990D0000') AS Profitperhand - ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats - from Gametypes gt - inner join Sites s on s.Id = gt.siteId - inner join HudCache hc on hc.gameTypeId = gt.Id - where hc.playerId in - and - and hc.activeSeats - and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-' - || SUBSTR(hc.styleKey,6,2) - group by gt.base - ,gt.category - ,upper(gt.limitType) - ,s.name - - ,gtId - ) stats - inner join - ( select - hprof.gtId, sum(hprof.profit) AS sum_profit, - avg(hprof.profit/100.0) AS profitperhand, - case when hprof.gtId = -1 then -999 - else variance(hprof.profit/100.0) - end as variance - from - (select hp.handId, as gtId, hp.totalProfit as profit - from HandsPlayers hp - inner join Hands h ON (h.id = hp.handId) - where hp.playerId in - and hp.tourneysPlayersId IS NULL - and to_char(h.handStart, 'YYYY-MM-DD') - group by hp.handId, gtId, hp.totalProfit - ) hprof - group by hprof.gtId - ) hprof2 - on hprof2.gtId = stats.gtId - order by stats.base, stats.limittype, stats.bigBlindDesc desc """ - #elif db_server == 'sqlite': - # self.query['playerStats'] = """ """ - - if db_server == 'mysql': - self.query['playerStatsByPosition'] = """ - SELECT - concat(upper(stats.limitType), ' ' - ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' ' - ,stats.name, ' ' - ,cast(stats.bigBlindDesc as char) - ) AS Game - ,case when stats.PlPosition = -2 then 'BB' - when stats.PlPosition = -1 then 'SB' - when stats.PlPosition = 0 then 'Btn' - when stats.PlPosition = 1 then 'CO' - when stats.PlPosition = 2 then 'MP' - when stats.PlPosition = 5 then 'EP' - else 'xx' - end AS PlPosition - ,stats.n - ,stats.vpip - ,stats.pfr - ,stats.pf3 - ,stats.steals - ,stats.saw_f - ,stats.sawsd - ,stats.wtsdwsf - ,stats.wmsd - ,stats.FlAFq - ,stats.TuAFq - ,stats.RvAFq - ,stats.PoFAFq - ,stats.Net - ,stats.BBper100 - ,stats.Profitperhand - ,case when hprof2.variance = -999 then '-' - else format(hprof2.variance, 2) - end AS Variance - ,stats.AvgSeats - FROM - (select /* stats from hudcache */ - gt.base - ,gt.category - ,upper(gt.limitType) AS limitType - ,s.name - , AS bigBlindDesc - , AS gtId - ,case when hc.position = 'B' then -2 - when hc.position = 'S' then -1 - when hc.position = 'D' then 0 - when hc.position = 'C' then 1 - when hc.position = 'M' then 2 - when hc.position = 'E' then 5 - else 9 - end as PlPosition - ,sum(HDs) AS n - ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip - ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr - ,case when sum(street0_3Bchance) = 0 then '0' - else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1) - end AS pf3 - ,case when sum(stealattemptchance) = 0 then '-' - else format(100.0*sum(stealattempted)/sum(stealattemptchance),1) - end AS steals - ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f - ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd - ,case when sum(street1Seen) = 0 then '-' - else format(100.0*sum(sawShowdown)/sum(street1Seen),1) - end AS wtsdwsf - ,case when sum(sawShowdown) = 0 then '-' - else format(100.0*sum(wonAtSD)/sum(sawShowdown),1) - end AS wmsd - ,case when sum(street1Seen) = 0 then '-' - else format(100.0*sum(street1Aggr)/sum(street1Seen),1) - end AS FlAFq - ,case when sum(street2Seen) = 0 then '-' - else format(100.0*sum(street2Aggr)/sum(street2Seen),1) - end AS TuAFq - ,case when sum(street3Seen) = 0 then '-' - else format(100.0*sum(street3Aggr)/sum(street3Seen),1) - end AS RvAFq - ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-' - else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr)) - /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1) - end AS PoFAFq - ,format(sum(totalProfit)/100.0,2) AS Net - ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2) - AS BBper100 - ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand - ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats - from Gametypes gt - inner join Sites s on s.Id = gt.siteId - inner join HudCache hc on hc.gameTypeId = gt.Id - where hc.playerId in - and - and hc.activeSeats - and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-' - , substring(hc.styleKey,6,2) ) - group by gt.base - ,gt.category - ,upper(gt.limitType) - ,s.name - - ,gtId - ,PlPosition - ) stats - inner join - ( select # profit from handsplayers/handsactions - hprof.gtId, - case when hprof.position = 'B' then -2 - when hprof.position = 'S' then -1 - when hprof.position in ('3','4') then 2 - when hprof.position in ('6','7') then 5 - else hprof.position - end as PlPosition, - sum(hprof.profit) as sum_profit, - avg(hprof.profit/100.0) as profitperhand, - case when hprof.gtId = -1 then -999 - else variance(hprof.profit/100.0) - end as variance - from - (select hp.handId, as gtId, hp.position - , hp.totalProfit as profit - from HandsPlayers hp - inner join Hands h ON (h.id = hp.handId) - where hp.playerId in - and hp.tourneysPlayersId IS NULL - and date_format(h.handStart, '%Y-%m-%d') - group by hp.handId, gtId, hp.position, hp.totalProfit - ) hprof - group by hprof.gtId, PlPosition - ) hprof2 - on ( hprof2.gtId = stats.gtId - and hprof2.PlPosition = stats.PlPosition) - order by stats.category, stats.limitType, stats.bigBlindDesc desc - , cast(stats.PlPosition as signed) - """ - else: # assume postgresql - self.query['playerStatsByPosition'] = """ - select /* stats from hudcache */ - upper(stats.limitType) || ' ' - || upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' ' - || stats.name || ' ' - || stats.bigBlindDesc AS Game - ,case when stats.PlPosition = -2 then 'BB' - when stats.PlPosition = -1 then 'SB' - when stats.PlPosition = 0 then 'Btn' - when stats.PlPosition = 1 then 'CO' - when stats.PlPosition = 2 then 'MP' - when stats.PlPosition = 5 then 'EP' - else 'xx' - end AS PlPosition - ,stats.n - ,stats.vpip - ,stats.pfr - ,stats.pf3 - ,stats.steals - ,stats.saw_f - ,stats.sawsd - ,stats.wtsdwsf - ,stats.wmsd - ,stats.FlAFq - ,stats.TuAFq - ,stats.RvAFq - ,stats.PoFAFq - ,stats.Net - ,stats.BBper100 - ,stats.Profitperhand - ,case when hprof2.variance = -999 then '-' - else to_char(hprof2.variance, '0D00') - end AS Variance - ,stats.AvgSeats - FROM - (select /* stats from hudcache */ - gt.base - ,gt.category - ,upper(gt.limitType) AS limitType - ,s.name - , AS bigBlindDesc - , AS gtId - ,case when hc.position = 'B' then -2 - when hc.position = 'S' then -1 - when hc.position = 'D' then 0 - when hc.position = 'C' then 1 - when hc.position = 'M' then 2 - when hc.position = 'E' then 5 - else 9 - end AS PlPosition - ,sum(HDs) AS n - ,to_char(round(100.0*sum(street0VPI)/sum(HDs)),'990D0') AS vpip - ,to_char(round(100.0*sum(street0Aggr)/sum(HDs)),'90D0') AS pfr - ,case when sum(street0_3Bchance) = 0 then '0' - else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0') - end AS pf3 - ,case when sum(stealattemptchance) = 0 then '-' - else to_char(100.0*sum(stealattempted)/sum(stealattemptchance),'90D0') - end AS steals - ,to_char(round(100.0*sum(street1Seen)/sum(HDs)),'90D0') AS saw_f - ,to_char(round(100.0*sum(sawShowdown)/sum(HDs)),'90D0') AS sawsd - ,case when sum(street1Seen) = 0 then '-' - else to_char(round(100.0*sum(sawShowdown)/sum(street1Seen)),'90D0') - end AS wtsdwsf - ,case when sum(sawShowdown) = 0 then '-' - else to_char(round(100.0*sum(wonAtSD)/sum(sawShowdown)),'90D0') - end AS wmsd - ,case when sum(street1Seen) = 0 then '-' - else to_char(round(100.0*sum(street1Aggr)/sum(street1Seen)),'90D0') - end AS FlAFq - ,case when sum(street2Seen) = 0 then '-' - else to_char(round(100.0*sum(street2Aggr)/sum(street2Seen)),'90D0') - end AS TuAFq - ,case when sum(street3Seen) = 0 then '-' - else to_char(round(100.0*sum(street3Aggr)/sum(street3Seen)),'90D0') - end AS RvAFq - ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-' - else to_char(round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr)) - /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen))),'90D0') - end AS PoFAFq - ,to_char(sum(totalProfit)/100.0,'9G999G990D00') AS Net - ,case when sum(HDs) = 0 then '0' - else to_char(sum(totalProfit/(gt.bigBlind+0.0)) / (sum(HDs)/100.0), '990D00') - end AS BBper100 - ,case when sum(HDs) = 0 then '0' - else to_char( (sum(totalProfit)/100.0) / sum(HDs), '90D0000') - end AS Profitperhand - ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats - from Gametypes gt - inner join Sites s on (s.Id = gt.siteId) - inner join HudCache hc on (hc.gameTypeId = gt.Id) - where hc.playerId in - and - and hc.activeSeats - and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-' - || SUBSTR(hc.styleKey,6,2) - group by gt.base - ,gt.category + ,plposition ,upper(gt.limitType) ,s.name - - ,gtId + having 1 = 1 + order by pname + ,gt.base + ,gt.category + + ,case when 'B' then 'B' + when 'S' then 'S' + else concat('Z', ) + end + + ,upper(gt.limitType) desc + ,maxbigblind desc + ,s.name + """ + elif db_server == 'postgresql': + self.query['playerDetailedStats'] = """ + select AS hgametypeid + , AS pname + ,gt.base + ,gt.category + ,upper(gt.limitType) AS limittype + ,s.name + ,min(gt.bigBlind) AS minbigblind + ,max(gt.bigBlind) AS maxbigblind + /*, AS gtid*/ + , AS plposition + ,count(1) AS n + ,100.0*sum(cast(hp.street0VPI as integer))/count(1) AS vpip + ,100.0*sum(cast(hp.street0Aggr as integer))/count(1) AS pfr + ,case when sum(cast(hp.street0_3Bchance as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street0_3Bdone as integer))/sum(cast(hp.street0_3Bchance as integer)) + end AS pf3 + ,case when sum(cast(hp.stealattemptchance as integer)) = 0 then -999 + else 100.0*sum(cast(hp.stealattempted as integer))/sum(cast(hp.stealattemptchance as integer)) + end AS steals + ,100.0*sum(cast(hp.street1Seen as integer))/count(1) AS saw_f + ,100.0*sum(cast(hp.sawShowdown as integer))/count(1) AS sawsd + ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.sawShowdown as integer))/sum(cast(hp.street1Seen as integer)) + end AS wtsdwsf + ,case when sum(cast(hp.sawShowdown as integer)) = 0 then -999 + else 100.0*sum(cast(hp.wonAtSD as integer))/sum(cast(hp.sawShowdown as integer)) + end AS wmsd + ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street1Aggr as integer))/sum(cast(hp.street1Seen as integer)) + end AS flafq + ,case when sum(cast(hp.street2Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street2Aggr as integer))/sum(cast(hp.street2Seen as integer)) + end AS tuafq + ,case when sum(cast(hp.street3Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street3Aggr as integer))/sum(cast(hp.street3Seen as integer)) + end AS rvafq + ,case when sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer)) = 0 then -999 + else 100.0*(sum(cast(hp.street1Aggr as integer))+sum(cast(hp.street2Aggr as integer))+sum(cast(hp.street3Aggr as integer))) + /(sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer))) + end AS pofafq + ,sum(hp.totalProfit)/100.0 AS net + ,sum(hp.rake)/100.0 AS rake + ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100 + ,avg(hp.totalProfit)/100.0 AS profitperhand + ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr + ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr + ,avg(h.seats+0.0) AS avgseats + ,variance(hp.totalProfit/100.0) AS variance + from HandsPlayers hp + inner join Hands h on (h.id = hp.handId) + inner join Gametypes gt on (gt.Id = h.gameTypeId) + inner join Sites s on (s.Id = gt.siteId) + inner join Players p on (p.Id = hp.playerId) + where hp.playerId in + /*and hp.tourneysPlayersId IS NULL*/ + and h.seats + + + and to_char(h.handStart, 'YYYY-MM-DD') + group by hgameTypeId + ,pname + ,gt.base + ,gt.category - ,PlPosition - ) stats - inner join - ( select /* profit from handsplayers/handsactions */ - hprof.gtId, - case when hprof.position = 'B' then -2 - when hprof.position = 'S' then -1 - when hprof.position in ('3','4') then 2 - when hprof.position in ('6','7') then 5 - else cast(hprof.position as smallint) - end as PlPosition, - sum(hprof.profit) as sum_profit, - avg(hprof.profit/100.0) as profitperhand, - case when hprof.gtId = -1 then -999 - else variance(hprof.profit/100.0) - end as variance - from - (select hp.handId, as gtId, hp.position - , hp.totalProfit as profit - from HandsPlayers hp - inner join Hands h ON (h.id = hp.handId) - where hp.playerId in - and hp.tourneysPlayersId IS NULL - and to_char(h.handStart, 'YYYY-MM-DD') - group by hp.handId, gameTypeId, hp.position, hp.totalProfit - ) hprof - group by hprof.gtId, PlPosition - ) hprof2 - on ( hprof2.gtId = stats.gtId - and hprof2.PlPosition = stats.PlPosition) - order by stats.category, stats.limitType, stats.bigBlindDesc desc - , cast(stats.PlPosition as smallint) - """ - #elif db_server == 'sqlite': - # self.query['playerStatsByPosition'] = """ """ + ,plposition + ,upper(gt.limitType) + ,s.name + having 1 = 1 + order by pname + ,gt.base + ,gt.category + + ,case when 'B' then 'B' + when 'S' then 'S' + when '0' then 'Y' + else 'Z'|| + end + + ,upper(gt.limitType) desc + ,maxbigblind desc + ,s.name + """ + elif db_server == 'sqlite': + self.query['playerDetailedStats'] = """ + select AS hgametypeid + ,gt.base + ,gt.category AS category + ,upper(gt.limitType) AS limittype + ,s.name AS name + ,min(gt.bigBlind) AS minbigblind + ,max(gt.bigBlind) AS maxbigblind + /*, AS gtid*/ + , AS plposition + ,count(1) AS n + ,100.0*sum(cast(hp.street0VPI as integer))/count(1) AS vpip + ,100.0*sum(cast(hp.street0Aggr as integer))/count(1) AS pfr + ,case when sum(cast(hp.street0_3Bchance as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street0_3Bdone as integer))/sum(cast(hp.street0_3Bchance as integer)) + end AS pf3 + ,case when sum(cast(hp.stealattemptchance as integer)) = 0 then -999 + else 100.0*sum(cast(hp.stealattempted as integer))/sum(cast(hp.stealattemptchance as integer)) + end AS steals + ,100.0*sum(cast(hp.street1Seen as integer))/count(1) AS saw_f + ,100.0*sum(cast(hp.sawShowdown as integer))/count(1) AS sawsd + ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.sawShowdown as integer))/sum(cast(hp.street1Seen as integer)) + end AS wtsdwsf + ,case when sum(cast(hp.sawShowdown as integer)) = 0 then -999 + else 100.0*sum(cast(hp.wonAtSD as integer))/sum(cast(hp.sawShowdown as integer)) + end AS wmsd + ,case when sum(cast(hp.street1Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street1Aggr as integer))/sum(cast(hp.street1Seen as integer)) + end AS flafq + ,case when sum(cast(hp.street2Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street2Aggr as integer))/sum(cast(hp.street2Seen as integer)) + end AS tuafq + ,case when sum(cast(hp.street3Seen as integer)) = 0 then -999 + else 100.0*sum(cast(hp.street3Aggr as integer))/sum(cast(hp.street3Seen as integer)) + end AS rvafq + ,case when sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer)) = 0 then -999 + else 100.0*(sum(cast(hp.street1Aggr as integer))+sum(cast(hp.street2Aggr as integer))+sum(cast(hp.street3Aggr as integer))) + /(sum(cast(hp.street1Seen as integer))+sum(cast(hp.street2Seen as integer))+sum(cast(hp.street3Seen as integer))) + end AS pofafq + ,sum(hp.totalProfit)/100.0 AS net + ,sum(hp.rake)/100.0 AS rake + ,100.0*avg(hp.totalProfit/(gt.bigBlind+0.0)) AS bbper100 + ,avg(hp.totalProfit)/100.0 AS profitperhand + ,100.0*avg((hp.totalProfit+hp.rake)/(gt.bigBlind+0.0)) AS bb100xr + ,avg((hp.totalProfit+hp.rake)/100.0) AS profhndxr + ,avg(h.seats+0.0) AS avgseats + /*,variance(hp.totalProfit/100.0) AS variance*/ + ,0.0 AS variance + from HandsPlayers hp + inner join Hands h on (h.id = hp.handId) + inner join Gametypes gt on (gt.Id = h.gameTypeId) + inner join Sites s on (s.Id = gt.siteId) + where hp.playerId in + /*and hp.tourneysPlayersId IS NULL*/ + and h.seats + + + and date(h.handStart) + group by hgameTypeId + ,hp.playerId + ,gt.base + ,gt.category + + ,plposition + ,upper(gt.limitType) + ,s.name + order by hp.playerId + ,gt.base + ,gt.category + + ,case when 'B' then 'B' + when 'S' then 'S' + when '0' then 'Y' + else 'Z'|| + end + + ,upper(gt.limitType) desc + ,max(gt.bigBlind) desc + ,s.name + """ - self.query['getRingProfitAllHandsPlayerIdSite'] = """ - SELECT hp.handId, hp.totalProfit + if db_server == 'mysql': + self.query['playerStats'] = """ + SELECT + concat(upper(stats.limitType), ' ' + ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' ' + ,stats.name, ' ' + ,cast(stats.bigBlindDesc as char) + ) AS Game + ,stats.n + ,stats.vpip + ,stats.pfr + ,stats.pf3 + ,stats.steals + ,stats.saw_f + ,stats.sawsd + ,stats.wtsdwsf + ,stats.wmsd + ,stats.FlAFq + ,stats.TuAFq + ,stats.RvAFq + ,stats.PoFAFq + ,stats.Net + ,stats.BBper100 + ,stats.Profitperhand + ,case when hprof2.variance = -999 then '-' + else format(hprof2.variance, 2) + end AS Variance + ,stats.AvgSeats + FROM + (select /* stats from hudcache */ + gt.base + ,gt.category + ,upper(gt.limitType) as limitType + ,s.name + , AS bigBlindDesc + , AS gtId + ,sum(HDs) AS n + ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip + ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr + ,case when sum(street0_3Bchance) = 0 then '0' + else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1) + end AS pf3 + ,case when sum(stealattemptchance) = 0 then '-' + else format(100.0*sum(stealattempted)/sum(stealattemptchance),1) + end AS steals + ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f + ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd + ,case when sum(street1Seen) = 0 then '-' + else format(100.0*sum(sawShowdown)/sum(street1Seen),1) + end AS wtsdwsf + ,case when sum(sawShowdown) = 0 then '-' + else format(100.0*sum(wonAtSD)/sum(sawShowdown),1) + end AS wmsd + ,case when sum(street1Seen) = 0 then '-' + else format(100.0*sum(street1Aggr)/sum(street1Seen),1) + end AS FlAFq + ,case when sum(street2Seen) = 0 then '-' + else format(100.0*sum(street2Aggr)/sum(street2Seen),1) + end AS TuAFq + ,case when sum(street3Seen) = 0 then '-' + else format(100.0*sum(street3Aggr)/sum(street3Seen),1) + end AS RvAFq + ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-' + else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr)) + /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1) + end AS PoFAFq + ,format(sum(totalProfit)/100.0,2) AS Net + ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2) + AS BBper100 + ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand + ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats + from Gametypes gt + inner join Sites s on s.Id = gt.siteId + inner join HudCache hc on hc.gameTypeId = gt.Id + where hc.playerId in + and + and hc.activeSeats + and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-' + , substring(hc.styleKey,6,2) ) + group by gt.base + ,gt.category + ,upper(gt.limitType) + ,s.name + + ,gtId + ) stats + inner join + ( select # profit from handsplayers/handsactions + hprof.gtId, sum(hprof.profit) sum_profit, + avg(hprof.profit/100.0) profitperhand, + case when hprof.gtId = -1 then -999 + else variance(hprof.profit/100.0) + end as variance + from + (select hp.handId, as gtId, hp.totalProfit as profit + from HandsPlayers hp + inner join Hands h ON h.id = hp.handId + where hp.playerId in + and hp.tourneysPlayersId IS NULL + and date_format(h.handStart, '%Y-%m-%d') + group by hp.handId, gtId, hp.totalProfit + ) hprof + group by hprof.gtId + ) hprof2 + on hprof2.gtId = stats.gtId + order by stats.category, stats.limittype, stats.bigBlindDesc desc """ + else: # assume postgres + self.query['playerStats'] = """ + SELECT upper(stats.limitType) || ' ' + || initcap(stats.category) || ' ' + || stats.name || ' ' + || stats.bigBlindDesc AS Game + ,stats.n + ,stats.vpip + ,stats.pfr + ,stats.pf3 + ,stats.steals + ,stats.saw_f + ,stats.sawsd + ,stats.wtsdwsf + ,stats.wmsd + ,stats.FlAFq + ,stats.TuAFq + ,stats.RvAFq + ,stats.PoFAFq + ,stats.Net + ,stats.BBper100 + ,stats.Profitperhand + ,case when hprof2.variance = -999 then '-' + else to_char(hprof2.variance, '0D00') + end AS Variance + ,AvgSeats + FROM + (select gt.base + ,gt.category + ,upper(gt.limitType) AS limitType + ,s.name + , AS bigBlindDesc + , AS gtId + ,sum(HDs) as n + ,to_char(100.0*sum(street0VPI)/sum(HDs),'990D0') AS vpip + ,to_char(100.0*sum(street0Aggr)/sum(HDs),'90D0') AS pfr + ,case when sum(street0_3Bchance) = 0 then '0' + else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0') + end AS pf3 + ,case when sum(stealattemptchance) = 0 then '-' + else to_char(100.0*sum(stealattempted)/sum(stealattemptchance),'90D0') + end AS steals + ,to_char(100.0*sum(street1Seen)/sum(HDs),'90D0') AS saw_f + ,to_char(100.0*sum(sawShowdown)/sum(HDs),'90D0') AS sawsd + ,case when sum(street1Seen) = 0 then '-' + else to_char(100.0*sum(sawShowdown)/sum(street1Seen),'90D0') + end AS wtsdwsf + ,case when sum(sawShowdown) = 0 then '-' + else to_char(100.0*sum(wonAtSD)/sum(sawShowdown),'90D0') + end AS wmsd + ,case when sum(street1Seen) = 0 then '-' + else to_char(100.0*sum(street1Aggr)/sum(street1Seen),'90D0') + end AS FlAFq + ,case when sum(street2Seen) = 0 then '-' + else to_char(100.0*sum(street2Aggr)/sum(street2Seen),'90D0') + end AS TuAFq + ,case when sum(street3Seen) = 0 then '-' + else to_char(100.0*sum(street3Aggr)/sum(street3Seen),'90D0') + end AS RvAFq + ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-' + else to_char(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr)) + /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),'90D0') + end AS PoFAFq + ,round(sum(totalProfit)/100.0,2) AS Net + ,to_char((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0), '990D00') + AS BBper100 + ,to_char(sum(totalProfit/100.0) / (sum(HDs)+0.0), '990D0000') AS Profitperhand + ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats + from Gametypes gt + inner join Sites s on s.Id = gt.siteId + inner join HudCache hc on hc.gameTypeId = gt.Id + where hc.playerId in + and + and hc.activeSeats + and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-' + || SUBSTR(hc.styleKey,6,2) + group by gt.base + ,gt.category + ,upper(gt.limitType) + ,s.name + + ,gtId + ) stats + inner join + ( select + hprof.gtId, sum(hprof.profit) AS sum_profit, + avg(hprof.profit/100.0) AS profitperhand, + case when hprof.gtId = -1 then -999 + else variance(hprof.profit/100.0) + end as variance + from + (select hp.handId, as gtId, hp.totalProfit as profit + from HandsPlayers hp + inner join Hands h ON (h.id = hp.handId) + where hp.playerId in + and hp.tourneysPlayersId IS NULL + and to_char(h.handStart, 'YYYY-MM-DD') + group by hp.handId, gtId, hp.totalProfit + ) hprof + group by hprof.gtId + ) hprof2 + on hprof2.gtId = stats.gtId + order by stats.base, stats.limittype, stats.bigBlindDesc desc """ + #elif db_server == 'sqlite': + # self.query['playerStats'] = """ """ + + if db_server == 'mysql': + self.query['playerStatsByPosition'] = """ + SELECT + concat(upper(stats.limitType), ' ' + ,concat(upper(substring(stats.category,1,1)),substring(stats.category,2) ), ' ' + ,stats.name, ' ' + ,cast(stats.bigBlindDesc as char) + ) AS Game + ,case when stats.PlPosition = -2 then 'BB' + when stats.PlPosition = -1 then 'SB' + when stats.PlPosition = 0 then 'Btn' + when stats.PlPosition = 1 then 'CO' + when stats.PlPosition = 2 then 'MP' + when stats.PlPosition = 5 then 'EP' + else 'xx' + end AS PlPosition + ,stats.n + ,stats.vpip + ,stats.pfr + ,stats.pf3 + ,stats.steals + ,stats.saw_f + ,stats.sawsd + ,stats.wtsdwsf + ,stats.wmsd + ,stats.FlAFq + ,stats.TuAFq + ,stats.RvAFq + ,stats.PoFAFq + ,stats.Net + ,stats.BBper100 + ,stats.Profitperhand + ,case when hprof2.variance = -999 then '-' + else format(hprof2.variance, 2) + end AS Variance + ,stats.AvgSeats + FROM + (select /* stats from hudcache */ + gt.base + ,gt.category + ,upper(gt.limitType) AS limitType + ,s.name + , AS bigBlindDesc + , AS gtId + ,case when hc.position = 'B' then -2 + when hc.position = 'S' then -1 + when hc.position = 'D' then 0 + when hc.position = 'C' then 1 + when hc.position = 'M' then 2 + when hc.position = 'E' then 5 + else 9 + end as PlPosition + ,sum(HDs) AS n + ,format(100.0*sum(street0VPI)/sum(HDs),1) AS vpip + ,format(100.0*sum(street0Aggr)/sum(HDs),1) AS pfr + ,case when sum(street0_3Bchance) = 0 then '0' + else format(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),1) + end AS pf3 + ,case when sum(stealattemptchance) = 0 then '-' + else format(100.0*sum(stealattempted)/sum(stealattemptchance),1) + end AS steals + ,format(100.0*sum(street1Seen)/sum(HDs),1) AS saw_f + ,format(100.0*sum(sawShowdown)/sum(HDs),1) AS sawsd + ,case when sum(street1Seen) = 0 then '-' + else format(100.0*sum(sawShowdown)/sum(street1Seen),1) + end AS wtsdwsf + ,case when sum(sawShowdown) = 0 then '-' + else format(100.0*sum(wonAtSD)/sum(sawShowdown),1) + end AS wmsd + ,case when sum(street1Seen) = 0 then '-' + else format(100.0*sum(street1Aggr)/sum(street1Seen),1) + end AS FlAFq + ,case when sum(street2Seen) = 0 then '-' + else format(100.0*sum(street2Aggr)/sum(street2Seen),1) + end AS TuAFq + ,case when sum(street3Seen) = 0 then '-' + else format(100.0*sum(street3Aggr)/sum(street3Seen),1) + end AS RvAFq + ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-' + else format(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr)) + /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen)),1) + end AS PoFAFq + ,format(sum(totalProfit)/100.0,2) AS Net + ,format((sum(totalProfit/(gt.bigBlind+0.0))) / (sum(HDs)/100.0),2) + AS BBper100 + ,format( (sum(totalProfit)/100.0) / sum(HDs), 4) AS Profitperhand + ,format( sum(activeSeats*HDs)/(sum(HDs)+0.0), 2) AS AvgSeats + from Gametypes gt + inner join Sites s on s.Id = gt.siteId + inner join HudCache hc on hc.gameTypeId = gt.Id + where hc.playerId in + and + and hc.activeSeats + and concat( '20', substring(hc.styleKey,2,2), '-', substring(hc.styleKey,4,2), '-' + , substring(hc.styleKey,6,2) ) + group by gt.base + ,gt.category + ,upper(gt.limitType) + ,s.name + + ,gtId + + ,PlPosition + ) stats + inner join + ( select # profit from handsplayers/handsactions + hprof.gtId, + case when hprof.position = 'B' then -2 + when hprof.position = 'S' then -1 + when hprof.position in ('3','4') then 2 + when hprof.position in ('6','7') then 5 + else hprof.position + end as PlPosition, + sum(hprof.profit) as sum_profit, + avg(hprof.profit/100.0) as profitperhand, + case when hprof.gtId = -1 then -999 + else variance(hprof.profit/100.0) + end as variance + from + (select hp.handId, as gtId, hp.position + , hp.totalProfit as profit + from HandsPlayers hp + inner join Hands h ON (h.id = hp.handId) + where hp.playerId in + and hp.tourneysPlayersId IS NULL + and date_format(h.handStart, '%Y-%m-%d') + group by hp.handId, gtId, hp.position, hp.totalProfit + ) hprof + group by hprof.gtId, PlPosition + ) hprof2 + on ( hprof2.gtId = stats.gtId + and hprof2.PlPosition = stats.PlPosition) + order by stats.category, stats.limitType, stats.bigBlindDesc desc + , cast(stats.PlPosition as signed) + """ + else: # assume postgresql + self.query['playerStatsByPosition'] = """ + select /* stats from hudcache */ + upper(stats.limitType) || ' ' + || upper(substr(stats.category,1,1)) || substr(stats.category,2) || ' ' + || stats.name || ' ' + || stats.bigBlindDesc AS Game + ,case when stats.PlPosition = -2 then 'BB' + when stats.PlPosition = -1 then 'SB' + when stats.PlPosition = 0 then 'Btn' + when stats.PlPosition = 1 then 'CO' + when stats.PlPosition = 2 then 'MP' + when stats.PlPosition = 5 then 'EP' + else 'xx' + end AS PlPosition + ,stats.n + ,stats.vpip + ,stats.pfr + ,stats.pf3 + ,stats.steals + ,stats.saw_f + ,stats.sawsd + ,stats.wtsdwsf + ,stats.wmsd + ,stats.FlAFq + ,stats.TuAFq + ,stats.RvAFq + ,stats.PoFAFq + ,stats.Net + ,stats.BBper100 + ,stats.Profitperhand + ,case when hprof2.variance = -999 then '-' + else to_char(hprof2.variance, '0D00') + end AS Variance + ,stats.AvgSeats + FROM + (select /* stats from hudcache */ + gt.base + ,gt.category + ,upper(gt.limitType) AS limitType + ,s.name + , AS bigBlindDesc + , AS gtId + ,case when hc.position = 'B' then -2 + when hc.position = 'S' then -1 + when hc.position = 'D' then 0 + when hc.position = 'C' then 1 + when hc.position = 'M' then 2 + when hc.position = 'E' then 5 + else 9 + end AS PlPosition + ,sum(HDs) AS n + ,to_char(round(100.0*sum(street0VPI)/sum(HDs)),'990D0') AS vpip + ,to_char(round(100.0*sum(street0Aggr)/sum(HDs)),'90D0') AS pfr + ,case when sum(street0_3Bchance) = 0 then '0' + else to_char(100.0*sum(street0_3Bdone)/sum(street0_3Bchance),'90D0') + end AS pf3 + ,case when sum(stealattemptchance) = 0 then '-' + else to_char(100.0*sum(stealattempted)/sum(stealattemptchance),'90D0') + end AS steals + ,to_char(round(100.0*sum(street1Seen)/sum(HDs)),'90D0') AS saw_f + ,to_char(round(100.0*sum(sawShowdown)/sum(HDs)),'90D0') AS sawsd + ,case when sum(street1Seen) = 0 then '-' + else to_char(round(100.0*sum(sawShowdown)/sum(street1Seen)),'90D0') + end AS wtsdwsf + ,case when sum(sawShowdown) = 0 then '-' + else to_char(round(100.0*sum(wonAtSD)/sum(sawShowdown)),'90D0') + end AS wmsd + ,case when sum(street1Seen) = 0 then '-' + else to_char(round(100.0*sum(street1Aggr)/sum(street1Seen)),'90D0') + end AS FlAFq + ,case when sum(street2Seen) = 0 then '-' + else to_char(round(100.0*sum(street2Aggr)/sum(street2Seen)),'90D0') + end AS TuAFq + ,case when sum(street3Seen) = 0 then '-' + else to_char(round(100.0*sum(street3Aggr)/sum(street3Seen)),'90D0') + end AS RvAFq + ,case when sum(street1Seen)+sum(street2Seen)+sum(street3Seen) = 0 then '-' + else to_char(round(100.0*(sum(street1Aggr)+sum(street2Aggr)+sum(street3Aggr)) + /(sum(street1Seen)+sum(street2Seen)+sum(street3Seen))),'90D0') + end AS PoFAFq + ,to_char(sum(totalProfit)/100.0,'9G999G990D00') AS Net + ,case when sum(HDs) = 0 then '0' + else to_char(sum(totalProfit/(gt.bigBlind+0.0)) / (sum(HDs)/100.0), '990D00') + end AS BBper100 + ,case when sum(HDs) = 0 then '0' + else to_char( (sum(totalProfit)/100.0) / sum(HDs), '90D0000') + end AS Profitperhand + ,to_char(sum(activeSeats*HDs)/(sum(HDs)+0.0),'90D00') AS AvgSeats + from Gametypes gt + inner join Sites s on (s.Id = gt.siteId) + inner join HudCache hc on (hc.gameTypeId = gt.Id) + where hc.playerId in + and + and hc.activeSeats + and '20' || SUBSTR(hc.styleKey,2,2) || '-' || SUBSTR(hc.styleKey,4,2) || '-' + || SUBSTR(hc.styleKey,6,2) + group by gt.base + ,gt.category + ,upper(gt.limitType) + ,s.name + + ,gtId + + ,PlPosition + ) stats + inner join + ( select /* profit from handsplayers/handsactions */ + hprof.gtId, + case when hprof.position = 'B' then -2 + when hprof.position = 'S' then -1 + when hprof.position in ('3','4') then 2 + when hprof.position in ('6','7') then 5 + else cast(hprof.position as smallint) + end as PlPosition, + sum(hprof.profit) as sum_profit, + avg(hprof.profit/100.0) as profitperhand, + case when hprof.gtId = -1 then -999 + else variance(hprof.profit/100.0) + end as variance + from + (select hp.handId, as gtId, hp.position + , hp.totalProfit as profit + from HandsPlayers hp + inner join Hands h ON (h.id = hp.handId) + where hp.playerId in + and hp.tourneysPlayersId IS NULL + and to_char(h.handStart, 'YYYY-MM-DD') + group by hp.handId, gameTypeId, hp.position, hp.totalProfit + ) hprof + group by hprof.gtId, PlPosition + ) hprof2 + on ( hprof2.gtId = stats.gtId + and hprof2.PlPosition = stats.PlPosition) + order by stats.category, stats.limitType, stats.bigBlindDesc desc + , cast(stats.PlPosition as smallint) + """ + #elif db_server == 'sqlite': + # self.query['playerStatsByPosition'] = """ """ + + self.query['getRingProfitAllHandsPlayerIdSite'] = """ + SELECT hp.handId, hp.totalProfit + FROM HandsPlayers hp + INNER JOIN Players pl ON (pl.id = hp.playerId) + INNER JOIN Hands h ON (h.id = hp.handId) + INNER JOIN Gametypes gt ON (gt.id = h.gametypeId) + WHERE pl.id in + AND pl.siteId in + AND h.handStart > '' + AND h.handStart < '' + + AND hp.tourneysPlayersId IS NULL + GROUP BY h.handStart, hp.handId, hp.totalProfit + ORDER BY h.handStart""" + + #################################### + # Session stats query + #################################### + if db_server == 'mysql': + self.query['sessionStats'] = """ + SELECT UNIX_TIMESTAMP(h.handStart) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit FROM HandsPlayers hp - INNER JOIN Players pl ON (pl.id = hp.playerId) - INNER JOIN Hands h ON (h.id = hp.handId) - INNER JOIN Gametypes gt ON (gt.id = h.gametypeId) - WHERE pl.id in - AND pl.siteId in - AND h.handStart > '' - AND h.handStart < '' - - AND hp.tourneysPlayersId IS NULL - GROUP BY h.handStart, hp.handId, hp.totalProfit - ORDER BY h.handStart""" + INNER JOIN Players pl ON (pl.id = hp.playerId) + INNER JOIN Hands h ON (h.id = hp.handId) + INNER JOIN Gametypes gt ON (gt.id = h.gametypeId) + WHERE pl.id in + AND pl.siteId in + AND h.handStart > '' + AND h.handStart < '' + + AND hp.tourneysPlayersId IS NULL + GROUP BY h.handStart, hp.handId, hp.totalProfit + ORDER BY h.handStart""" - #################################### - # Session stats query - #################################### - if db_server == 'mysql': - self.query['sessionStats'] = """ - SELECT UNIX_TIMESTAMP(h.handStart) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit - FROM HandsPlayers hp - INNER JOIN Hands h on (h.id = hp.handId) - INNER JOIN Gametypes gt on (gt.Id = h.gameTypeId) - INNER JOIN Sites s on (s.Id = gt.siteId) - INNER JOIN Players p on (p.Id = hp.playerId) - WHERE hp.playerId in - AND date_format(h.handStart, '%Y-%m-%d') - ORDER by time""" - elif db_server == 'postgresql': - self.query['sessionStats'] = """ - SELECT EXTRACT(epoch from h.handStart) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit - FROM HandsPlayers hp - INNER JOIN Hands h on (h.id = hp.handId) - INNER JOIN Gametypes gt on (gt.Id = h.gameTypeId) - INNER JOIN Sites s on (s.Id = gt.siteId) - INNER JOIN Players p on (p.Id = hp.playerId) - WHERE hp.playerId in - AND h.handStart - ORDER by time""" - elif db_server == 'sqlite': - self.query['sessionStats'] = """ - SELECT STRFTIME('', h.handStart) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit - FROM HandsPlayers hp - INNER JOIN Hands h on (h.id = hp.handId) - INNER JOIN Gametypes gt on (gt.Id = h.gameTypeId) - INNER JOIN Sites s on (s.Id = gt.siteId) - INNER JOIN Players p on (p.Id = hp.playerId) - WHERE hp.playerId in - AND h.handStart - ORDER by time""" + #################################### + # Session stats query + #################################### + if db_server == 'mysql': + self.query['sessionStats'] = """ + SELECT UNIX_TIMESTAMP(h.handStart) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit + FROM HandsPlayers hp + INNER JOIN Hands h on (h.id = hp.handId) + INNER JOIN Gametypes gt on (gt.Id = h.gameTypeId) + INNER JOIN Sites s on (s.Id = gt.siteId) + INNER JOIN Players p on (p.Id = hp.playerId) + WHERE hp.playerId in + AND date_format(h.handStart, '%Y-%m-%d') + ORDER by time""" + elif db_server == 'postgresql': + self.query['sessionStats'] = """ + SELECT EXTRACT(epoch from h.handStart) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit + FROM HandsPlayers hp + INNER JOIN Hands h on (h.id = hp.handId) + INNER JOIN Gametypes gt on (gt.Id = h.gameTypeId) + INNER JOIN Sites s on (s.Id = gt.siteId) + INNER JOIN Players p on (p.Id = hp.playerId) + WHERE hp.playerId in + AND h.handStart + ORDER by time""" + elif db_server == 'sqlite': + self.query['sessionStats'] = """ + SELECT STRFTIME('', h.handStart) as time, hp.handId, hp.startCash, hp.winnings, hp.totalProfit + FROM HandsPlayers hp + INNER JOIN Hands h on (h.id = hp.handId) + INNER JOIN Gametypes gt on (gt.Id = h.gameTypeId) + INNER JOIN Sites s on (s.Id = gt.siteId) + INNER JOIN Players p on (p.Id = hp.playerId) + WHERE hp.playerId in + AND h.handStart + ORDER by time""" - #################################### - # Queries to rebuild/modify hudcache - #################################### - - self.query['clearHudCache'] = """DELETE FROM HudCache""" - - if db_server == 'mysql': - self.query['rebuildHudCache'] = """ - INSERT INTO HudCache - (gametypeId - ,playerId - ,activeSeats - ,position - ,tourneyTypeId - ,styleKey - ,HDs - ,wonWhenSeenStreet1 - ,wonAtSD - ,street0VPI - ,street0Aggr - ,street0_3BChance - ,street0_3BDone - ,street1Seen - ,street2Seen - ,street3Seen - ,street4Seen - ,sawShowdown - ,street1Aggr - ,street2Aggr - ,street3Aggr - ,street4Aggr - ,otherRaisedStreet1 - ,otherRaisedStreet2 - ,otherRaisedStreet3 - ,otherRaisedStreet4 - ,foldToOtherRaisedStreet1 - ,foldToOtherRaisedStreet2 - ,foldToOtherRaisedStreet3 - ,foldToOtherRaisedStreet4 - ,stealAttemptChance - ,stealAttempted - ,foldBbToStealChance - ,foldedBbToSteal - ,foldSbToStealChance - ,foldedSbToSteal - ,street1CBChance - ,street1CBDone - ,street2CBChance - ,street2CBDone - ,street3CBChance - ,street3CBDone - ,street4CBChance - ,street4CBDone - ,foldToStreet1CBChance - ,foldToStreet1CBDone - ,foldToStreet2CBChance - ,foldToStreet2CBDone - ,foldToStreet3CBChance - ,foldToStreet3CBDone - ,foldToStreet4CBChance - ,foldToStreet4CBDone - ,totalProfit - ,street1CheckCallRaiseChance - ,street1CheckCallRaiseDone - ,street2CheckCallRaiseChance - ,street2CheckCallRaiseDone - ,street3CheckCallRaiseChance - ,street3CheckCallRaiseDone - ,street4CheckCallRaiseChance - ,street4CheckCallRaiseDone - ) - SELECT h.gametypeId - ,hp.playerId - ,h.seats - ,case when hp.position = 'B' then 'B' - when hp.position = 'S' then 'S' - when hp.position = '0' then 'D' - when hp.position = '1' then 'C' - when hp.position = '2' then 'M' - when hp.position = '3' then 'M' - when hp.position = '4' then 'M' - when hp.position = '5' then 'E' - when hp.position = '6' then 'E' - when hp.position = '7' then 'E' - when hp.position = '8' then 'E' - when hp.position = '9' then 'E' - else 'E' - end AS hc_position - ,hp.tourneyTypeId - ,date_format(h.handStart, 'd%y%m%d') - ,count(1) - ,sum(wonWhenSeenStreet1) - ,sum(wonAtSD) - ,sum(street0VPI) - ,sum(street0Aggr) - ,sum(street0_3BChance) - ,sum(street0_3BDone) - ,sum(street1Seen) - ,sum(street2Seen) - ,sum(street3Seen) - ,sum(street4Seen) - ,sum(sawShowdown) - ,sum(street1Aggr) - ,sum(street2Aggr) - ,sum(street3Aggr) - ,sum(street4Aggr) - ,sum(otherRaisedStreet1) - ,sum(otherRaisedStreet2) - ,sum(otherRaisedStreet3) - ,sum(otherRaisedStreet4) - ,sum(foldToOtherRaisedStreet1) - ,sum(foldToOtherRaisedStreet2) - ,sum(foldToOtherRaisedStreet3) - ,sum(foldToOtherRaisedStreet4) - ,sum(stealAttemptChance) - ,sum(stealAttempted) - ,sum(foldBbToStealChance) - ,sum(foldedBbToSteal) - ,sum(foldSbToStealChance) - ,sum(foldedSbToSteal) - ,sum(street1CBChance) - ,sum(street1CBDone) - ,sum(street2CBChance) - ,sum(street2CBDone) - ,sum(street3CBChance) - ,sum(street3CBDone) - ,sum(street4CBChance) - ,sum(street4CBDone) - ,sum(foldToStreet1CBChance) - ,sum(foldToStreet1CBDone) - ,sum(foldToStreet2CBChance) - ,sum(foldToStreet2CBDone) - ,sum(foldToStreet3CBChance) - ,sum(foldToStreet3CBDone) - ,sum(foldToStreet4CBChance) - ,sum(foldToStreet4CBDone) - ,sum(totalProfit) - ,sum(street1CheckCallRaiseChance) - ,sum(street1CheckCallRaiseDone) - ,sum(street2CheckCallRaiseChance) - ,sum(street2CheckCallRaiseDone) - ,sum(street3CheckCallRaiseChance) - ,sum(street3CheckCallRaiseDone) - ,sum(street4CheckCallRaiseChance) - ,sum(street4CheckCallRaiseDone) - FROM HandsPlayers hp - INNER JOIN Hands h ON (h.id = hp.handId) - - GROUP BY h.gametypeId - ,hp.playerId - ,h.seats - ,hc_position - ,hp.tourneyTypeId - ,date_format(h.handStart, 'd%y%m%d') + #################################### + # Queries to rebuild/modify hudcache + #################################### + + self.query['clearHudCache'] = """DELETE FROM HudCache""" + + if db_server == 'mysql': + self.query['rebuildHudCache'] = """ + INSERT INTO HudCache + (gametypeId + ,playerId + ,activeSeats + ,position + ,tourneyTypeId + ,styleKey + ,HDs + ,wonWhenSeenStreet1 + ,wonAtSD + ,street0VPI + ,street0Aggr + ,street0_3BChance + ,street0_3BDone + ,street1Seen + ,street2Seen + ,street3Seen + ,street4Seen + ,sawShowdown + ,street1Aggr + ,street2Aggr + ,street3Aggr + ,street4Aggr + ,otherRaisedStreet1 + ,otherRaisedStreet2 + ,otherRaisedStreet3 + ,otherRaisedStreet4 + ,foldToOtherRaisedStreet1 + ,foldToOtherRaisedStreet2 + ,foldToOtherRaisedStreet3 + ,foldToOtherRaisedStreet4 + ,stealAttemptChance + ,stealAttempted + ,foldBbToStealChance + ,foldedBbToSteal + ,foldSbToStealChance + ,foldedSbToSteal + ,street1CBChance + ,street1CBDone + ,street2CBChance + ,street2CBDone + ,street3CBChance + ,street3CBDone + ,street4CBChance + ,street4CBDone + ,foldToStreet1CBChance + ,foldToStreet1CBDone + ,foldToStreet2CBChance + ,foldToStreet2CBDone + ,foldToStreet3CBChance + ,foldToStreet3CBDone + ,foldToStreet4CBChance + ,foldToStreet4CBDone + ,totalProfit + ,street1CheckCallRaiseChance + ,street1CheckCallRaiseDone + ,street2CheckCallRaiseChance + ,street2CheckCallRaiseDone + ,street3CheckCallRaiseChance + ,street3CheckCallRaiseDone + ,street4CheckCallRaiseChance + ,street4CheckCallRaiseDone + ) + SELECT h.gametypeId + ,hp.playerId + ,h.seats + ,case when hp.position = 'B' then 'B' + when hp.position = 'S' then 'S' + when hp.position = '0' then 'D' + when hp.position = '1' then 'C' + when hp.position = '2' then 'M' + when hp.position = '3' then 'M' + when hp.position = '4' then 'M' + when hp.position = '5' then 'E' + when hp.position = '6' then 'E' + when hp.position = '7' then 'E' + when hp.position = '8' then 'E' + when hp.position = '9' then 'E' + else 'E' + end AS hc_position + ,hp.tourneyTypeId + ,date_format(h.handStart, 'd%y%m%d') + ,count(1) + ,sum(wonWhenSeenStreet1) + ,sum(wonAtSD) + ,sum(street0VPI) + ,sum(street0Aggr) + ,sum(street0_3BChance) + ,sum(street0_3BDone) + ,sum(street1Seen) + ,sum(street2Seen) + ,sum(street3Seen) + ,sum(street4Seen) + ,sum(sawShowdown) + ,sum(street1Aggr) + ,sum(street2Aggr) + ,sum(street3Aggr) + ,sum(street4Aggr) + ,sum(otherRaisedStreet1) + ,sum(otherRaisedStreet2) + ,sum(otherRaisedStreet3) + ,sum(otherRaisedStreet4) + ,sum(foldToOtherRaisedStreet1) + ,sum(foldToOtherRaisedStreet2) + ,sum(foldToOtherRaisedStreet3) + ,sum(foldToOtherRaisedStreet4) + ,sum(stealAttemptChance) + ,sum(stealAttempted) + ,sum(foldBbToStealChance) + ,sum(foldedBbToSteal) + ,sum(foldSbToStealChance) + ,sum(foldedSbToSteal) + ,sum(street1CBChance) + ,sum(street1CBDone) + ,sum(street2CBChance) + ,sum(street2CBDone) + ,sum(street3CBChance) + ,sum(street3CBDone) + ,sum(street4CBChance) + ,sum(street4CBDone) + ,sum(foldToStreet1CBChance) + ,sum(foldToStreet1CBDone) + ,sum(foldToStreet2CBChance) + ,sum(foldToStreet2CBDone) + ,sum(foldToStreet3CBChance) + ,sum(foldToStreet3CBDone) + ,sum(foldToStreet4CBChance) + ,sum(foldToStreet4CBDone) + ,sum(totalProfit) + ,sum(street1CheckCallRaiseChance) + ,sum(street1CheckCallRaiseDone) + ,sum(street2CheckCallRaiseChance) + ,sum(street2CheckCallRaiseDone) + ,sum(street3CheckCallRaiseChance) + ,sum(street3CheckCallRaiseDone) + ,sum(street4CheckCallRaiseChance) + ,sum(street4CheckCallRaiseDone) + FROM HandsPlayers hp + INNER JOIN Hands h ON (h.id = hp.handId) + + GROUP BY h.gametypeId + ,hp.playerId + ,h.seats + ,hc_position + ,hp.tourneyTypeId + ,date_format(h.handStart, 'd%y%m%d') """ - elif db_server == 'postgresql': - self.query['rebuildHudCache'] = """ - INSERT INTO HudCache - (gametypeId - ,playerId - ,activeSeats - ,position - ,tourneyTypeId - ,styleKey - ,HDs - ,wonWhenSeenStreet1 - ,wonAtSD - ,street0VPI - ,street0Aggr - ,street0_3BChance - ,street0_3BDone - ,street1Seen - ,street2Seen - ,street3Seen - ,street4Seen - ,sawShowdown - ,street1Aggr - ,street2Aggr - ,street3Aggr - ,street4Aggr - ,otherRaisedStreet1 - ,otherRaisedStreet2 - ,otherRaisedStreet3 - ,otherRaisedStreet4 - ,foldToOtherRaisedStreet1 - ,foldToOtherRaisedStreet2 - ,foldToOtherRaisedStreet3 - ,foldToOtherRaisedStreet4 - ,stealAttemptChance - ,stealAttempted - ,foldBbToStealChance - ,foldedBbToSteal - ,foldSbToStealChance - ,foldedSbToSteal - ,street1CBChance - ,street1CBDone - ,street2CBChance - ,street2CBDone - ,street3CBChance - ,street3CBDone - ,street4CBChance - ,street4CBDone - ,foldToStreet1CBChance - ,foldToStreet1CBDone - ,foldToStreet2CBChance - ,foldToStreet2CBDone - ,foldToStreet3CBChance - ,foldToStreet3CBDone - ,foldToStreet4CBChance - ,foldToStreet4CBDone - ,totalProfit - ,street1CheckCallRaiseChance - ,street1CheckCallRaiseDone - ,street2CheckCallRaiseChance - ,street2CheckCallRaiseDone - ,street3CheckCallRaiseChance - ,street3CheckCallRaiseDone - ,street4CheckCallRaiseChance - ,street4CheckCallRaiseDone - ) - SELECT h.gametypeId - ,hp.playerId - ,h.seats - ,case when hp.position = 'B' then 'B' - when hp.position = 'S' then 'S' - when hp.position = '0' then 'D' - when hp.position = '1' then 'C' - when hp.position = '2' then 'M' - when hp.position = '3' then 'M' - when hp.position = '4' then 'M' - when hp.position = '5' then 'E' - when hp.position = '6' then 'E' - when hp.position = '7' then 'E' - when hp.position = '8' then 'E' - when hp.position = '9' then 'E' - else 'E' - end AS hc_position - ,hp.tourneyTypeId - ,'d' || to_char(h.handStart, 'YYMMDD') - ,count(1) - ,sum(wonWhenSeenStreet1) - ,sum(wonAtSD) - ,sum(CAST(street0VPI as integer)) - ,sum(CAST(street0Aggr as integer)) - ,sum(CAST(street0_3BChance as integer)) - ,sum(CAST(street0_3BDone as integer)) - ,sum(CAST(street1Seen as integer)) - ,sum(CAST(street2Seen as integer)) - ,sum(CAST(street3Seen as integer)) - ,sum(CAST(street4Seen as integer)) - ,sum(CAST(sawShowdown as integer)) - ,sum(CAST(street1Aggr as integer)) - ,sum(CAST(street2Aggr as integer)) - ,sum(CAST(street3Aggr as integer)) - ,sum(CAST(street4Aggr as integer)) - ,sum(CAST(otherRaisedStreet1 as integer)) - ,sum(CAST(otherRaisedStreet2 as integer)) - ,sum(CAST(otherRaisedStreet3 as integer)) - ,sum(CAST(otherRaisedStreet4 as integer)) - ,sum(CAST(foldToOtherRaisedStreet1 as integer)) - ,sum(CAST(foldToOtherRaisedStreet2 as integer)) - ,sum(CAST(foldToOtherRaisedStreet3 as integer)) - ,sum(CAST(foldToOtherRaisedStreet4 as integer)) - ,sum(CAST(stealAttemptChance as integer)) - ,sum(CAST(stealAttempted as integer)) - ,sum(CAST(foldBbToStealChance as integer)) - ,sum(CAST(foldedBbToSteal as integer)) - ,sum(CAST(foldSbToStealChance as integer)) - ,sum(CAST(foldedSbToSteal as integer)) - ,sum(CAST(street1CBChance as integer)) - ,sum(CAST(street1CBDone as integer)) - ,sum(CAST(street2CBChance as integer)) - ,sum(CAST(street2CBDone as integer)) - ,sum(CAST(street3CBChance as integer)) - ,sum(CAST(street3CBDone as integer)) - ,sum(CAST(street4CBChance as integer)) - ,sum(CAST(street4CBDone as integer)) - ,sum(CAST(foldToStreet1CBChance as integer)) - ,sum(CAST(foldToStreet1CBDone as integer)) - ,sum(CAST(foldToStreet2CBChance as integer)) - ,sum(CAST(foldToStreet2CBDone as integer)) - ,sum(CAST(foldToStreet3CBChance as integer)) - ,sum(CAST(foldToStreet3CBDone as integer)) - ,sum(CAST(foldToStreet4CBChance as integer)) - ,sum(CAST(foldToStreet4CBDone as integer)) - ,sum(CAST(totalProfit as integer)) - ,sum(CAST(street1CheckCallRaiseChance as integer)) - ,sum(CAST(street1CheckCallRaiseDone as integer)) - ,sum(CAST(street2CheckCallRaiseChance as integer)) - ,sum(CAST(street2CheckCallRaiseDone as integer)) - ,sum(CAST(street3CheckCallRaiseChance as integer)) - ,sum(CAST(street3CheckCallRaiseDone as integer)) - ,sum(CAST(street4CheckCallRaiseChance as integer)) - ,sum(CAST(street4CheckCallRaiseDone as integer)) - FROM HandsPlayers hp - INNER JOIN Hands h ON (h.id = hp.handId) - - GROUP BY h.gametypeId - ,hp.playerId - ,h.seats - ,hc_position - ,hp.tourneyTypeId - ,to_char(h.handStart, 'YYMMDD') +#>>>>>>> 28ca49d592c8e706ad6ee58dd26655bcc33fc5fb:pyfpdb/SQL.py +#""" + elif db_server == 'postgresql': + self.query['rebuildHudCache'] = """ + INSERT INTO HudCache + (gametypeId + ,playerId + ,activeSeats + ,position + ,tourneyTypeId + ,styleKey + ,HDs + ,wonWhenSeenStreet1 + ,wonAtSD + ,street0VPI + ,street0Aggr + ,street0_3BChance + ,street0_3BDone + ,street1Seen + ,street2Seen + ,street3Seen + ,street4Seen + ,sawShowdown + ,street1Aggr + ,street2Aggr + ,street3Aggr + ,street4Aggr + ,otherRaisedStreet1 + ,otherRaisedStreet2 + ,otherRaisedStreet3 + ,otherRaisedStreet4 + ,foldToOtherRaisedStreet1 + ,foldToOtherRaisedStreet2 + ,foldToOtherRaisedStreet3 + ,foldToOtherRaisedStreet4 + ,stealAttemptChance + ,stealAttempted + ,foldBbToStealChance + ,foldedBbToSteal + ,foldSbToStealChance + ,foldedSbToSteal + ,street1CBChance + ,street1CBDone + ,street2CBChance + ,street2CBDone + ,street3CBChance + ,street3CBDone + ,street4CBChance + ,street4CBDone + ,foldToStreet1CBChance + ,foldToStreet1CBDone + ,foldToStreet2CBChance + ,foldToStreet2CBDone + ,foldToStreet3CBChance + ,foldToStreet3CBDone + ,foldToStreet4CBChance + ,foldToStreet4CBDone + ,totalProfit + ,street1CheckCallRaiseChance + ,street1CheckCallRaiseDone + ,street2CheckCallRaiseChance + ,street2CheckCallRaiseDone + ,street3CheckCallRaiseChance + ,street3CheckCallRaiseDone + ,street4CheckCallRaiseChance + ,street4CheckCallRaiseDone + ) + SELECT h.gametypeId + ,hp.playerId + ,h.seats + ,case when hp.position = 'B' then 'B' + when hp.position = 'S' then 'S' + when hp.position = '0' then 'D' + when hp.position = '1' then 'C' + when hp.position = '2' then 'M' + when hp.position = '3' then 'M' + when hp.position = '4' then 'M' + when hp.position = '5' then 'E' + when hp.position = '6' then 'E' + when hp.position = '7' then 'E' + when hp.position = '8' then 'E' + when hp.position = '9' then 'E' + else 'E' + end AS hc_position + ,hp.tourneyTypeId + ,'d' || to_char(h.handStart, 'YYMMDD') + ,count(1) + ,sum(wonWhenSeenStreet1) + ,sum(wonAtSD) + ,sum(CAST(street0VPI as integer)) + ,sum(CAST(street0Aggr as integer)) + ,sum(CAST(street0_3BChance as integer)) + ,sum(CAST(street0_3BDone as integer)) + ,sum(CAST(street1Seen as integer)) + ,sum(CAST(street2Seen as integer)) + ,sum(CAST(street3Seen as integer)) + ,sum(CAST(street4Seen as integer)) + ,sum(CAST(sawShowdown as integer)) + ,sum(CAST(street1Aggr as integer)) + ,sum(CAST(street2Aggr as integer)) + ,sum(CAST(street3Aggr as integer)) + ,sum(CAST(street4Aggr as integer)) + ,sum(CAST(otherRaisedStreet1 as integer)) + ,sum(CAST(otherRaisedStreet2 as integer)) + ,sum(CAST(otherRaisedStreet3 as integer)) + ,sum(CAST(otherRaisedStreet4 as integer)) + ,sum(CAST(foldToOtherRaisedStreet1 as integer)) + ,sum(CAST(foldToOtherRaisedStreet2 as integer)) + ,sum(CAST(foldToOtherRaisedStreet3 as integer)) + ,sum(CAST(foldToOtherRaisedStreet4 as integer)) + ,sum(CAST(stealAttemptChance as integer)) + ,sum(CAST(stealAttempted as integer)) + ,sum(CAST(foldBbToStealChance as integer)) + ,sum(CAST(foldedBbToSteal as integer)) + ,sum(CAST(foldSbToStealChance as integer)) + ,sum(CAST(foldedSbToSteal as integer)) + ,sum(CAST(street1CBChance as integer)) + ,sum(CAST(street1CBDone as integer)) + ,sum(CAST(street2CBChance as integer)) + ,sum(CAST(street2CBDone as integer)) + ,sum(CAST(street3CBChance as integer)) + ,sum(CAST(street3CBDone as integer)) + ,sum(CAST(street4CBChance as integer)) + ,sum(CAST(street4CBDone as integer)) + ,sum(CAST(foldToStreet1CBChance as integer)) + ,sum(CAST(foldToStreet1CBDone as integer)) + ,sum(CAST(foldToStreet2CBChance as integer)) + ,sum(CAST(foldToStreet2CBDone as integer)) + ,sum(CAST(foldToStreet3CBChance as integer)) + ,sum(CAST(foldToStreet3CBDone as integer)) + ,sum(CAST(foldToStreet4CBChance as integer)) + ,sum(CAST(foldToStreet4CBDone as integer)) + ,sum(CAST(totalProfit as integer)) + ,sum(CAST(street1CheckCallRaiseChance as integer)) + ,sum(CAST(street1CheckCallRaiseDone as integer)) + ,sum(CAST(street2CheckCallRaiseChance as integer)) + ,sum(CAST(street2CheckCallRaiseDone as integer)) + ,sum(CAST(street3CheckCallRaiseChance as integer)) + ,sum(CAST(street3CheckCallRaiseDone as integer)) + ,sum(CAST(street4CheckCallRaiseChance as integer)) + ,sum(CAST(street4CheckCallRaiseDone as integer)) + FROM HandsPlayers hp + INNER JOIN Hands h ON (h.id = hp.handId) + + GROUP BY h.gametypeId + ,hp.playerId + ,h.seats + ,hc_position + ,hp.tourneyTypeId + ,to_char(h.handStart, 'YYMMDD') """ - else: # assume sqlite - self.query['rebuildHudCache'] = """ - INSERT INTO HudCache - (gametypeId - ,playerId - ,activeSeats - ,position - ,tourneyTypeId - ,styleKey - ,HDs - ,wonWhenSeenStreet1 - ,wonAtSD - ,street0VPI - ,street0Aggr - ,street0_3BChance - ,street0_3BDone - ,street1Seen - ,street2Seen - ,street3Seen - ,street4Seen - ,sawShowdown - ,street1Aggr - ,street2Aggr - ,street3Aggr - ,street4Aggr - ,otherRaisedStreet1 - ,otherRaisedStreet2 - ,otherRaisedStreet3 - ,otherRaisedStreet4 - ,foldToOtherRaisedStreet1 - ,foldToOtherRaisedStreet2 - ,foldToOtherRaisedStreet3 - ,foldToOtherRaisedStreet4 - ,stealAttemptChance - ,stealAttempted - ,foldBbToStealChance - ,foldedBbToSteal - ,foldSbToStealChance - ,foldedSbToSteal - ,street1CBChance - ,street1CBDone - ,street2CBChance - ,street2CBDone - ,street3CBChance - ,street3CBDone - ,street4CBChance - ,street4CBDone - ,foldToStreet1CBChance - ,foldToStreet1CBDone - ,foldToStreet2CBChance - ,foldToStreet2CBDone - ,foldToStreet3CBChance - ,foldToStreet3CBDone - ,foldToStreet4CBChance - ,foldToStreet4CBDone - ,totalProfit - ,street1CheckCallRaiseChance - ,street1CheckCallRaiseDone - ,street2CheckCallRaiseChance - ,street2CheckCallRaiseDone - ,street3CheckCallRaiseChance - ,street3CheckCallRaiseDone - ,street4CheckCallRaiseChance - ,street4CheckCallRaiseDone - ) - SELECT h.gametypeId - ,hp.playerId - ,h.seats - ,case when hp.position = 'B' then 'B' - when hp.position = 'S' then 'S' - when hp.position = '0' then 'D' - when hp.position = '1' then 'C' - when hp.position = '2' then 'M' - when hp.position = '3' then 'M' - when hp.position = '4' then 'M' - when hp.position = '5' then 'E' - when hp.position = '6' then 'E' - when hp.position = '7' then 'E' - when hp.position = '8' then 'E' - when hp.position = '9' then 'E' - else 'E' - end AS hc_position - ,hp.tourneyTypeId - ,'d' || substr(strftime('%Y%m%d', h.handStart),3,7) - ,count(1) - ,sum(wonWhenSeenStreet1) - ,sum(wonAtSD) - ,sum(CAST(street0VPI as integer)) - ,sum(CAST(street0Aggr as integer)) - ,sum(CAST(street0_3BChance as integer)) - ,sum(CAST(street0_3BDone as integer)) - ,sum(CAST(street1Seen as integer)) - ,sum(CAST(street2Seen as integer)) - ,sum(CAST(street3Seen as integer)) - ,sum(CAST(street4Seen as integer)) - ,sum(CAST(sawShowdown as integer)) - ,sum(CAST(street1Aggr as integer)) - ,sum(CAST(street2Aggr as integer)) - ,sum(CAST(street3Aggr as integer)) - ,sum(CAST(street4Aggr as integer)) - ,sum(CAST(otherRaisedStreet1 as integer)) - ,sum(CAST(otherRaisedStreet2 as integer)) - ,sum(CAST(otherRaisedStreet3 as integer)) - ,sum(CAST(otherRaisedStreet4 as integer)) - ,sum(CAST(foldToOtherRaisedStreet1 as integer)) - ,sum(CAST(foldToOtherRaisedStreet2 as integer)) - ,sum(CAST(foldToOtherRaisedStreet3 as integer)) - ,sum(CAST(foldToOtherRaisedStreet4 as integer)) - ,sum(CAST(stealAttemptChance as integer)) - ,sum(CAST(stealAttempted as integer)) - ,sum(CAST(foldBbToStealChance as integer)) - ,sum(CAST(foldedBbToSteal as integer)) - ,sum(CAST(foldSbToStealChance as integer)) - ,sum(CAST(foldedSbToSteal as integer)) - ,sum(CAST(street1CBChance as integer)) - ,sum(CAST(street1CBDone as integer)) - ,sum(CAST(street2CBChance as integer)) - ,sum(CAST(street2CBDone as integer)) - ,sum(CAST(street3CBChance as integer)) - ,sum(CAST(street3CBDone as integer)) - ,sum(CAST(street4CBChance as integer)) - ,sum(CAST(street4CBDone as integer)) - ,sum(CAST(foldToStreet1CBChance as integer)) - ,sum(CAST(foldToStreet1CBDone as integer)) - ,sum(CAST(foldToStreet2CBChance as integer)) - ,sum(CAST(foldToStreet2CBDone as integer)) - ,sum(CAST(foldToStreet3CBChance as integer)) - ,sum(CAST(foldToStreet3CBDone as integer)) - ,sum(CAST(foldToStreet4CBChance as integer)) - ,sum(CAST(foldToStreet4CBDone as integer)) - ,sum(CAST(totalProfit as integer)) - ,sum(CAST(street1CheckCallRaiseChance as integer)) - ,sum(CAST(street1CheckCallRaiseDone as integer)) - ,sum(CAST(street2CheckCallRaiseChance as integer)) - ,sum(CAST(street2CheckCallRaiseDone as integer)) - ,sum(CAST(street3CheckCallRaiseChance as integer)) - ,sum(CAST(street3CheckCallRaiseDone as integer)) - ,sum(CAST(street4CheckCallRaiseChance as integer)) - ,sum(CAST(street4CheckCallRaiseDone as integer)) - FROM HandsPlayers hp - INNER JOIN Hands h ON (h.id = hp.handId) - - GROUP BY h.gametypeId - ,hp.playerId - ,h.seats - ,hc_position - ,hp.tourneyTypeId - ,'d' || substr(strftime('%Y%m%d', h.handStart),3,7) + else: # assume sqlite + self.query['rebuildHudCache'] = """ + INSERT INTO HudCache + (gametypeId + ,playerId + ,activeSeats + ,position + ,tourneyTypeId + ,styleKey + ,HDs + ,wonWhenSeenStreet1 + ,wonAtSD + ,street0VPI + ,street0Aggr + ,street0_3BChance + ,street0_3BDone + ,street1Seen + ,street2Seen + ,street3Seen + ,street4Seen + ,sawShowdown + ,street1Aggr + ,street2Aggr + ,street3Aggr + ,street4Aggr + ,otherRaisedStreet1 + ,otherRaisedStreet2 + ,otherRaisedStreet3 + ,otherRaisedStreet4 + ,foldToOtherRaisedStreet1 + ,foldToOtherRaisedStreet2 + ,foldToOtherRaisedStreet3 + ,foldToOtherRaisedStreet4 + ,stealAttemptChance + ,stealAttempted + ,foldBbToStealChance + ,foldedBbToSteal + ,foldSbToStealChance + ,foldedSbToSteal + ,street1CBChance + ,street1CBDone + ,street2CBChance + ,street2CBDone + ,street3CBChance + ,street3CBDone + ,street4CBChance + ,street4CBDone + ,foldToStreet1CBChance + ,foldToStreet1CBDone + ,foldToStreet2CBChance + ,foldToStreet2CBDone + ,foldToStreet3CBChance + ,foldToStreet3CBDone + ,foldToStreet4CBChance + ,foldToStreet4CBDone + ,totalProfit + ,street1CheckCallRaiseChance + ,street1CheckCallRaiseDone + ,street2CheckCallRaiseChance + ,street2CheckCallRaiseDone + ,street3CheckCallRaiseChance + ,street3CheckCallRaiseDone + ,street4CheckCallRaiseChance + ,street4CheckCallRaiseDone + ) + SELECT h.gametypeId + ,hp.playerId + ,h.seats + ,case when hp.position = 'B' then 'B' + when hp.position = 'S' then 'S' + when hp.position = '0' then 'D' + when hp.position = '1' then 'C' + when hp.position = '2' then 'M' + when hp.position = '3' then 'M' + when hp.position = '4' then 'M' + when hp.position = '5' then 'E' + when hp.position = '6' then 'E' + when hp.position = '7' then 'E' + when hp.position = '8' then 'E' + when hp.position = '9' then 'E' + else 'E' + end AS hc_position + ,hp.tourneyTypeId + ,'d' || substr(strftime('%Y%m%d', h.handStart),3,7) + ,count(1) + ,sum(wonWhenSeenStreet1) + ,sum(wonAtSD) + ,sum(CAST(street0VPI as integer)) + ,sum(CAST(street0Aggr as integer)) + ,sum(CAST(street0_3BChance as integer)) + ,sum(CAST(street0_3BDone as integer)) + ,sum(CAST(street1Seen as integer)) + ,sum(CAST(street2Seen as integer)) + ,sum(CAST(street3Seen as integer)) + ,sum(CAST(street4Seen as integer)) + ,sum(CAST(sawShowdown as integer)) + ,sum(CAST(street1Aggr as integer)) + ,sum(CAST(street2Aggr as integer)) + ,sum(CAST(street3Aggr as integer)) + ,sum(CAST(street4Aggr as integer)) + ,sum(CAST(otherRaisedStreet1 as integer)) + ,sum(CAST(otherRaisedStreet2 as integer)) + ,sum(CAST(otherRaisedStreet3 as integer)) + ,sum(CAST(otherRaisedStreet4 as integer)) + ,sum(CAST(foldToOtherRaisedStreet1 as integer)) + ,sum(CAST(foldToOtherRaisedStreet2 as integer)) + ,sum(CAST(foldToOtherRaisedStreet3 as integer)) + ,sum(CAST(foldToOtherRaisedStreet4 as integer)) + ,sum(CAST(stealAttemptChance as integer)) + ,sum(CAST(stealAttempted as integer)) + ,sum(CAST(foldBbToStealChance as integer)) + ,sum(CAST(foldedBbToSteal as integer)) + ,sum(CAST(foldSbToStealChance as integer)) + ,sum(CAST(foldedSbToSteal as integer)) + ,sum(CAST(street1CBChance as integer)) + ,sum(CAST(street1CBDone as integer)) + ,sum(CAST(street2CBChance as integer)) + ,sum(CAST(street2CBDone as integer)) + ,sum(CAST(street3CBChance as integer)) + ,sum(CAST(street3CBDone as integer)) + ,sum(CAST(street4CBChance as integer)) + ,sum(CAST(street4CBDone as integer)) + ,sum(CAST(foldToStreet1CBChance as integer)) + ,sum(CAST(foldToStreet1CBDone as integer)) + ,sum(CAST(foldToStreet2CBChance as integer)) + ,sum(CAST(foldToStreet2CBDone as integer)) + ,sum(CAST(foldToStreet3CBChance as integer)) + ,sum(CAST(foldToStreet3CBDone as integer)) + ,sum(CAST(foldToStreet4CBChance as integer)) + ,sum(CAST(foldToStreet4CBDone as integer)) + ,sum(CAST(totalProfit as integer)) + ,sum(CAST(street1CheckCallRaiseChance as integer)) + ,sum(CAST(street1CheckCallRaiseDone as integer)) + ,sum(CAST(street2CheckCallRaiseChance as integer)) + ,sum(CAST(street2CheckCallRaiseDone as integer)) + ,sum(CAST(street3CheckCallRaiseChance as integer)) + ,sum(CAST(street3CheckCallRaiseDone as integer)) + ,sum(CAST(street4CheckCallRaiseChance as integer)) + ,sum(CAST(street4CheckCallRaiseDone as integer)) + FROM HandsPlayers hp + INNER JOIN Hands h ON (h.id = hp.handId) + + GROUP BY h.gametypeId + ,hp.playerId + ,h.seats + ,hc_position + ,hp.tourneyTypeId + ,'d' || substr(strftime('%Y%m%d', h.handStart),3,7) """ - self.query['get_hero_hudcache_start'] = """select min(hc.styleKey) - from HudCache hc - where hc.playerId in - and hc.styleKey like 'd%'""" + self.query['get_hero_hudcache_start'] = """select min(hc.styleKey) + from HudCache hc + where hc.playerId in + and hc.styleKey like 'd%'""" - if db_server == 'mysql': - self.query['analyze'] = """ - analyze table Autorates, GameTypes, Hands, HandsPlayers, HudCache, Players - , Settings, Sites, Tourneys, TourneysPlayers, TourneyTypes + if db_server == 'mysql': + self.query['analyze'] = """ + analyze table Autorates, GameTypes, Hands, HandsPlayers, HudCache, Players + , Settings, Sites, Tourneys, TourneysPlayers, TourneyTypes + """ + else: # assume postgres + self.query['analyze'] = "vacuum analyze" + + if db_server == 'mysql': + self.query['lockForInsert'] = """ + lock tables Hands write, HandsPlayers write, HandsActions write, Players write + , HudCache write, GameTypes write, Sites write, Tourneys write + , TourneysPlayers write, TourneyTypes write, Autorates write """ - else: # assume postgres - self.query['analyze'] = "vacuum analyze" + else: # assume postgres + self.query['lockForInsert'] = "" - if db_server == 'mysql': - self.query['lockForInsert'] = """ - lock tables Hands write, HandsPlayers write, HandsActions write, Players write - , HudCache write, GameTypes write, Sites write, Tourneys write - , TourneysPlayers write, TourneyTypes write, Autorates write - """ - else: # assume postgres - self.query['lockForInsert'] = "" + self.query['getGametypeFL'] = """SELECT id + FROM Gametypes + WHERE siteId=%s + AND type=%s + AND category=%s + AND limitType=%s + AND smallBet=%s + AND bigBet=%s + """ - self.query['getGametypeFL'] = """SELECT id - FROM Gametypes - WHERE siteId=%s - AND type=%s - AND category=%s - AND limitType=%s - AND smallBet=%s - AND bigBet=%s - """ + self.query['getGametypeNL'] = """SELECT id + FROM Gametypes + WHERE siteId=%s + AND type=%s + AND category=%s + AND limitType=%s + AND smallBlind=%s + AND bigBlind=%s + """ - self.query['getGametypeNL'] = """SELECT id - FROM Gametypes - WHERE siteId=%s - AND type=%s - AND category=%s - AND limitType=%s - AND smallBlind=%s - AND bigBlind=%s - """ + self.query['insertGameTypes'] = """INSERT INTO Gametypes + (siteId, type, base, category, limitType + ,hiLo, smallBlind, bigBlind, smallBet, bigBet) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" - self.query['insertGameTypes'] = """INSERT INTO Gametypes - (siteId, type, base, category, limitType - ,hiLo, smallBlind, bigBlind, smallBet, bigBet) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" + self.query['isAlreadyInDB'] = """SELECT id FROM Hands + WHERE gametypeId=%s AND siteHandNo=%s + """ + + self.query['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id, + tt.buyin, + tt.fee, + tt.maxSeats, + tt.knockout, + tt.rebuyOrAddon, + tt.speed, + tt.headsUp, + tt.shootout, + tt.matrix + FROM TourneyTypes tt + INNER JOIN Tourneys t ON (t.tourneyTypeId = tt.id) + WHERE t.siteTourneyNo=%s AND tt.siteId=%s + """ + + self.query['getTourneyTypeId'] = """SELECT id + FROM TourneyTypes + WHERE siteId=%s + AND buyin=%s + AND fee=%s + AND knockout=%s + AND rebuyOrAddon=%s + AND speed=%s + AND headsUp=%s + AND shootout=%s + AND matrix=%s + """ - self.query['isAlreadyInDB'] = """SELECT id FROM Hands - WHERE gametypeId=%s AND siteHandNo=%s - """ - - self.query['getTourneyTypeIdByTourneyNo'] = """SELECT tt.id, - tt.buyin, - tt.fee, - tt.maxSeats, - tt.knockout, - tt.rebuyOrAddon, - tt.speed, - tt.headsUp, - tt.shootout, - tt.matrix - FROM TourneyTypes tt - INNER JOIN Tourneys t ON (t.tourneyTypeId = tt.id) - WHERE t.siteTourneyNo=%s AND tt.siteId=%s - """ - - self.query['getTourneyTypeId'] = """SELECT id - FROM TourneyTypes - WHERE siteId=%s - AND buyin=%s - AND fee=%s - AND knockout=%s - AND rebuyOrAddon=%s - AND speed=%s - AND headsUp=%s - AND shootout=%s - AND matrix=%s - """ + self.query['insertTourneyTypes'] = """INSERT INTO TourneyTypes + (siteId, buyin, fee, knockout, rebuyOrAddon + ,speed, headsUp, shootout, matrix) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) + """ - self.query['insertTourneyTypes'] = """INSERT INTO TourneyTypes - (siteId, buyin, fee, knockout, rebuyOrAddon - ,speed, headsUp, shootout, matrix) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) - """ + self.query['getTourney'] = """SELECT t.id, + t.tourneyTypeId, + t.entries, + t.prizepool, + t.startTime, + t.endTime, + t.buyinChips, + t.tourneyName, + t.matrixIdProcessed, + t.rebuyChips, + t.addonChips, + t.rebuyAmount, + t.addonAmount, + t.totalRebuys, + t.totalAddons, + t.koBounty, + t.comment + FROM Tourneys t + INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id) + WHERE t.siteTourneyNo=%s AND tt.siteId=%s + """ - self.query['getTourney'] = """SELECT t.id, - t.tourneyTypeId, - t.entries, - t.prizepool, - t.startTime, - t.endTime, - t.buyinChips, - t.tourneyName, - t.matrixIdProcessed, - t.rebuyChips, - t.addonChips, - t.rebuyAmount, - t.addonAmount, - t.totalRebuys, - t.totalAddons, - t.koBounty, - t.comment - FROM Tourneys t - INNER JOIN TourneyTypes tt ON (t.tourneyTypeId = tt.id) - WHERE t.siteTourneyNo=%s AND tt.siteId=%s - """ + self.query['insertTourney'] = """INSERT INTO Tourneys + (tourneyTypeId, siteTourneyNo, entries, prizepool, + startTime, endTime, buyinChips, tourneyName, matrixIdProcessed, + rebuyChips, addonChips, rebuyAmount, addonAmount, totalRebuys, + totalAddons, koBounty, comment, commentTs) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, %s, %s, %s) + """ + + self.query['updateTourney'] = """UPDATE Tourneys + SET tourneyTypeId = %s, + entries = %s, + prizepool = %s, + startTime = %s, + endTime = %s, + buyinChips = %s, + tourneyName = %s, + matrixIdProcessed = %s, + rebuyChips = %s, + addonChips = %s, + rebuyAmount = %s, + addonAmount = %s, + totalRebuys = %s, + totalAddons = %s, + koBounty = %s, + comment = %s, + commentTs = %s + WHERE id=%s + """ + + self.query['getTourneysPlayers'] = """SELECT id, + payinAmount, + rank, + winnings, + nbRebuys, + nbAddons, + nbKO, + comment, + commentTs + FROM TourneysPlayers + WHERE tourneyId=%s AND playerId+0=%s + """ - self.query['insertTourney'] = """INSERT INTO Tourneys - (tourneyTypeId, siteTourneyNo, entries, prizepool, - startTime, endTime, buyinChips, tourneyName, matrixIdProcessed, - rebuyChips, addonChips, rebuyAmount, addonAmount, totalRebuys, - totalAddons, koBounty, comment, commentTs) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, - %s, %s, %s, %s, %s, %s, %s, %s) - """ - - self.query['updateTourney'] = """UPDATE Tourneys - SET tourneyTypeId = %s, - entries = %s, - prizepool = %s, - startTime = %s, - endTime = %s, - buyinChips = %s, - tourneyName = %s, - matrixIdProcessed = %s, - rebuyChips = %s, - addonChips = %s, - rebuyAmount = %s, - addonAmount = %s, - totalRebuys = %s, - totalAddons = %s, - koBounty = %s, + self.query['updateTourneysPlayers'] = """UPDATE TourneysPlayers + SET payinAmount = %s, + rank = %s, + winnings = %s, + nbRebuys = %s, + nbAddons = %s, + nbKO = %s, comment = %s, commentTs = %s - WHERE id=%s - """ - - self.query['getTourneysPlayers'] = """SELECT id, - payinAmount, - rank, - winnings, - nbRebuys, - nbAddons, - nbKO, - comment, - commentTs - FROM TourneysPlayers - WHERE tourneyId=%s AND playerId+0=%s - """ + WHERE id=%s + """ - self.query['updateTourneysPlayers'] = """UPDATE TourneysPlayers - SET payinAmount = %s, - rank = %s, - winnings = %s, - nbRebuys = %s, - nbAddons = %s, - nbKO = %s, - comment = %s, - commentTs = %s - WHERE id=%s - """ + self.query['insertTourneysPlayers'] = """INSERT INTO TourneysPlayers + (tourneyId, playerId, payinAmount, rank, winnings, nbRebuys, nbAddons, nbKO, comment, commentTs) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) + """ - self.query['insertTourneysPlayers'] = """INSERT INTO TourneysPlayers - (tourneyId, playerId, payinAmount, rank, winnings, nbRebuys, nbAddons, nbKO, comment, commentTs) - VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) - """ - - self.query['selectHandsPlayersWithWrongTTypeId'] = """SELECT id - FROM HandsPlayers - WHERE tourneyTypeId <> %s AND (TourneysPlayersId+0=%s) - """ + self.query['selectHandsPlayersWithWrongTTypeId'] = """SELECT id + FROM HandsPlayers + WHERE tourneyTypeId <> %s AND (TourneysPlayersId+0=%s) + """ # self.query['updateHandsPlayersForTTypeId2'] = """UPDATE HandsPlayers # SET tourneyTypeId= %s # WHERE (TourneysPlayersId+0=%s) # """ - self.query['updateHandsPlayersForTTypeId'] = """UPDATE HandsPlayers - SET tourneyTypeId= %s - WHERE (id=%s) - """ + self.query['updateHandsPlayersForTTypeId'] = """UPDATE HandsPlayers + SET tourneyTypeId= %s + WHERE (id=%s) + """ - self.query['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0=" - self.query['handsPlayersTTypeId_joiner_id'] = " OR id=" + self.query['handsPlayersTTypeId_joiner'] = " OR TourneysPlayersId+0=" + self.query['handsPlayersTTypeId_joiner_id'] = " OR id=" - self.query['store_hand'] = """INSERT INTO Hands ( - tablename, - gametypeid, - sitehandno, - handstart, - importtime, - seats, - maxseats, - texture, - playersVpi, - boardcard1, - boardcard2, - boardcard3, - boardcard4, - boardcard5, - playersAtStreet1, - playersAtStreet2, - playersAtStreet3, - playersAtStreet4, - playersAtShowdown, - street0Raises, - street1Raises, - street2Raises, - street3Raises, - street4Raises, - street1Pot, - street2Pot, - street3Pot, - street4Pot, - showdownPot - ) - VALUES - (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, - %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, - %s, %s, %s, %s, %s, %s, %s, %s, %s)""" + self.query['store_hand'] = """INSERT INTO Hands ( + tablename, + gametypeid, + sitehandno, + handstart, + importtime, + seats, + maxseats, + texture, + playersVpi, + boardcard1, + boardcard2, + boardcard3, + boardcard4, + boardcard5, + playersAtStreet1, + playersAtStreet2, + playersAtStreet3, + playersAtStreet4, + playersAtShowdown, + street0Raises, + street1Raises, + street2Raises, + street3Raises, + street4Raises, + street1Pot, + street2Pot, + street3Pot, + street4Pot, + showdownPot + ) + VALUES + (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, %s, %s, %s, %s)""" - - - if db_server == 'mysql': - self.query['placeholder'] = u'%s' - elif db_server == 'postgresql': - self.query['placeholder'] = u'%s' - elif db_server == 'sqlite': - self.query['placeholder'] = u'?' + + + if db_server == 'mysql': + self.query['placeholder'] = u'%s' + elif db_server == 'postgresql': + self.query['placeholder'] = u'%s' + elif db_server == 'sqlite': + self.query['placeholder'] = u'?' - # If using sqlite, use the ? placeholder instead of %s - if db_server == 'sqlite': - for k,q in self.query.iteritems(): - self.query[k] = re.sub('%s','?',q) + # If using sqlite, use the ? placeholder instead of %s + if db_server == 'sqlite': + for k,q in self.query.iteritems(): + self.query[k] = re.sub('%s','?',q) if __name__== "__main__": # just print the default queries and exit diff --git a/pyfpdb/TableWindow.py b/pyfpdb/TableWindow.py index bdc9db87..10607b16 100644 --- a/pyfpdb/TableWindow.py +++ b/pyfpdb/TableWindow.py @@ -93,19 +93,17 @@ gobject.signal_new("client_destroyed", gtk.Window, # screen location of (0, 0) in the working window. class Table_Window(object): - def __init__(self, table_name = None, tournament = None, table_number = None): + def __init__(self, search_string, table_name = None, tournament = None, table_number = None): - if table_name is not None: - search_string = table_name - self.name = table_name - self.tournament = None - self.table = None - elif tournament is not None and table_number is not None: + if tournament is not None and table_number is not None: print "tournament %s, table %s" % (tournament, table_number) self.tournament = int(tournament) self.table = int(table_number) self.name = "%s - %s" % (self.tournament, self.table) - search_string = "%s.+Table\s%s" % (tournament, table_number) + elif table_name is not None: + search_string = table_name + self.name = table_name + self.tournament = None else: return None @@ -151,4 +149,4 @@ class Table_Window(object): def check_bad_words(self, title): for word in bad_words: if word in title: return True - return False \ No newline at end of file + return False diff --git a/pyfpdb/Tables_Demo.py b/pyfpdb/Tables_Demo.py index e141cab1..397579e7 100755 --- a/pyfpdb/Tables_Demo.py +++ b/pyfpdb/Tables_Demo.py @@ -82,18 +82,19 @@ if __name__=="__main__": (tour_no, tab_no) = table_name.split(",", 1) tour_no = tour_no.rstrip() tab_no = tab_no.rstrip() - table = Tables.Table(tournament = tour_no, table_number = tab_no) + table = Tables.Table(None, tournament = tour_no, table_number = tab_no) else: # not a tournament print "cash game" table_name = table_name.rstrip() - table = Tables.Table(table_name = table_name) + table = Tables.Table(None, table_name = table_name) + table.gdk_handle = gtk.gdk.window_foreign_new(table.number) print "table =", table - print "game =", table.get_game() +# print "game =", table.get_game() fake = fake_hud(table) print "fake =", fake - gobject.timeout_add(100, check_on_table, table, fake) +# gobject.timeout_add(100, check_on_table, table, fake) print "calling main" gtk.main() diff --git a/pyfpdb/XTables.py b/pyfpdb/XTables.py index fd1ce9c1..a14debc1 100644 --- a/pyfpdb/XTables.py +++ b/pyfpdb/XTables.py @@ -25,6 +25,7 @@ of Table_Window objects representing the windows found. # Standard Library modules import re +import os # pyGTK modules import pygtk @@ -40,39 +41,70 @@ from TableWindow import Table_Window # We might as well do this once and make them globals disp = Xlib.display.Display() root = disp.screen().root +name_atom = disp.get_atom("WM_NAME", 1) class Table(Table_Window): def find_table_parameters(self, search_string): - self.window = None - done_looping = False - for outside in root.query_tree().children: - for inside in outside.query_tree().children: - if done_looping: break - if inside.get_wm_name() and re.search(search_string, inside.get_wm_name()): - if self.check_bad_words(inside.get_wm_name()): continue - self.window = inside - self.parent = outside - done_looping = True - break +# self.window = None +# done_looping = False +# for outside in root.query_tree().children: +# for inside in outside.query_tree().children: +# if done_looping: break +# prop = inside.get_property(name_atom, Xlib.Xatom.STRING, 0, 1000) +# print prop +# if prop is None: continue +# if prop.value and re.search(search_string, prop.value): +# if self.check_bad_words(prop.value): continue +## if inside.get_wm_name() and re.search(search_string, inside.get_wm_name()): +## if self.check_bad_words(inside.get_wm_name()): +## print "bad word =", inside.get_wm_name() +## continue +# self.window = inside +# self.parent = outside +# done_looping = True +# break - if self.window == None or self.parent == None: + window_number = None + for listing in os.popen('xwininfo -root -tree').readlines(): + if re.search(search_string, listing): + print listing + mo = re.match('\s+([\dxabcdef]+) (.+):\s\(\"([a-zA-Z.]+)\".+ (\d+)x(\d+)\+\d+\+\d+ \+(\d+)\+(\d+)', listing) + self.number = int( mo.group(1), 0) + self.width = int( mo.group(4) ) + self.height = int( mo.group(5) ) + self.x = int( mo.group(6) ) + self.y = int( mo.group(7) ) + self.title = re.sub('\"', '', mo.group(2)) + self.exe = "" # not used? + self.hud = None +# done_looping = False +# for outside in root.query_tree().children: +# for inside in outside.query_tree().children: +# if done_looping: break +# if inside.id == window_number: +# self.window = inside +# self.parent = outside +# done_looping = True +# break + + if window_number is None: print "Window %s not found. Skipping." % search_string return None - my_geo = self.window.get_geometry() - pa_geo = self.parent.get_geometry() +# my_geo = self.window.get_geometry() +# pa_geo = self.parent.get_geometry() +# +# self.x = pa_geo.x + my_geo.x +# self.y = pa_geo.y + my_geo.y +# self.width = my_geo.width +# self.height = my_geo.height +# self.exe = self.window.get_wm_class()[0] +# self.title = self.window.get_wm_name() +# self.site = "" +# self.hud = None - self.x = pa_geo.x + my_geo.x - self.y = pa_geo.y + my_geo.y - self.width = my_geo.width - self.height = my_geo.height - self.exe = self.window.get_wm_class()[0] - self.title = self.window.get_wm_name() - self.site = "" - self.hud = None - - window_string = str(self.window) +# window_string = str(self.window) mo = re.match('Xlib\.display\.Window\(([\dxabcdef]+)', window_string) if not mo: print "Not matched" diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 18958880..f3dcd681 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -20,6 +20,7 @@ import os import re import sys import logging +import math from time import time, strftime from Exceptions import * @@ -30,11 +31,33 @@ except ImportError: logging.info("Not using sqlalchemy connection pool.") use_pool = False +try: + from numpy import var + use_numpy = True +except ImportError: + logging.info("Not using numpy to define variance in sqlite.") + use_numpy = False import fpdb_simple import FpdbSQLQueries import Configuration +# Variance created as sqlite has a bunch of undefined aggregate functions. + +class VARIANCE: + def __init__(self): + self.store = [] + + def step(self, value): + self.store.append(value) + + def finalize(self): + return float(var(self.store)) + +class sqlitemath: + def mod(self, a, b): + return a%b + class fpdb_db: MYSQL_INNODB = 2 PGSQL = 3 @@ -130,6 +153,13 @@ class fpdb_db: , detect_types=sqlite3.PARSE_DECLTYPES ) sqlite3.register_converter("bool", lambda x: bool(int(x))) sqlite3.register_adapter(bool, lambda x: "1" if x else "0") + self.db.create_function("floor", 1, math.floor) + tmp = sqlitemath() + self.db.create_function("mod", 2, tmp.mod) + if use_numpy: + self.db.create_aggregate("variance", 1, VARIANCE) + else: + logging.warning("Some database functions will not work without NumPy support") else: raise FpdbError("unrecognised database backend:"+backend) self.cursor = self.db.cursor() diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index fcad30be..850f34b6 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -42,15 +42,7 @@ import fpdb_parse_logic import Configuration import Exceptions -import logging, logging.config -import ConfigParser - -try: - logging.config.fileConfig(os.path.join(sys.path[0],"logging.conf")) -except ConfigParser.NoSectionError: # debian package path - logging.config.fileConfig('/usr/share/python-fpdb/logging.conf') - -log = logging.getLogger('importer') +log = Configuration.get_logger("logging.conf", "importer") # database interface modules try: diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 3e2d6f5f..aaf74772 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -927,7 +927,7 @@ def recogniseTourneyTypeId(db, siteId, tourneySiteId, buyin, fee, knockout, rebu except: cursor.execute( """SELECT id FROM TourneyTypes WHERE siteId=%s AND buyin=%s AND fee=%s - AND knockout=%s AND rebuyOrAddon=%s""" + AND knockout=%s AND rebuyOrAddon=%s""".replace('%s', db.sql.query['placeholder']) , (siteId, buyin, fee, knockout, rebuyOrAddon) ) result = cursor.fetchone() #print "tried selecting tourneytypes.id, result:", result @@ -939,14 +939,14 @@ def recogniseTourneyTypeId(db, siteId, tourneySiteId, buyin, fee, knockout, rebu #print "insert new tourneytype record ..." try: cursor.execute( """INSERT INTO TourneyTypes (siteId, buyin, fee, knockout, rebuyOrAddon) - VALUES (%s, %s, %s, %s, %s)""" + VALUES (%s, %s, %s, %s, %s)""".replace('%s', db.sql.query['placeholder']) , (siteId, buyin, fee, knockout, rebuyOrAddon) ) ret = db.get_last_insert_id(cursor) except: #print "maybe tourneytype was created since select, try selecting again ..." cursor.execute( """SELECT id FROM TourneyTypes WHERE siteId=%s AND buyin=%s AND fee=%s - AND knockout=%s AND rebuyOrAddon=%s""" + AND knockout=%s AND rebuyOrAddon=%s""".replace('%s', db.sql.query['placeholder']) , (siteId, buyin, fee, knockout, rebuyOrAddon) ) result = cursor.fetchone() try: diff --git a/pyfpdb/py2exe_setup.py b/pyfpdb/py2exe_setup.py index 028d004c..9565ac0b 100644 --- a/pyfpdb/py2exe_setup.py +++ b/pyfpdb/py2exe_setup.py @@ -27,6 +27,22 @@ Py2exe script for fpdb. # get rid of all the uneeded libraries (e.g., pyQT) # think about an installer +#HOW TO USE this script: +# +# cd to the folder where this script is stored, usually .../pyfpdb. +# If there are build and dist subfolders present , delete them to get +# rid of earlier builds. +# Run the script with "py2exe_setup.py py2exe" +# You will frequently get messages about missing .dll files. E. g., +# MSVCP90.dll. These are somewhere in your windows install, so you +# can just copy them to your working folder. +# If it works, you'll have 2 new folders, build and dist. Build is +# working space and should be deleted. Dist contains the files to be +# distributed. Last, you must copy the etc/, lib/ and share/ folders +# from your gtk/bin/ folder to the dist folder. (the whole folders, not +# just the contents) You can (should) then prune the etc/, lib/ and +# share/ folders to remove components we don't need. + from distutils.core import setup import py2exe @@ -36,7 +52,8 @@ setup( version = '0.12', console = [ {'script': 'fpdb.py', }, - {'script': 'HUD_main.py', } + {'script': 'HUD_main.py', }, + {'script': 'Configuration.py', } ], options = {'py2exe': { @@ -47,8 +64,10 @@ setup( } }, - data_files = ['HUD_config.xml', - 'Cards01.png' + data_files = ['HUD_config.xml.example', + 'Cards01.png', + 'logging.conf', + (r'matplotlibdata', glob.glob(r'c:\python26\Lib\site-packages\matplotlib\mpl-data\*')) ] ) diff --git a/pyfpdb/test_Database.py b/pyfpdb/test_Database.py new file mode 100644 index 00000000..b348f741 --- /dev/null +++ b/pyfpdb/test_Database.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +import sqlite3 +import fpdb_db +import math + +# Should probably use our wrapper classes - creating sqlite db in memory +sqlite3.register_converter("bool", lambda x: bool(int(x))) +sqlite3.register_adapter(bool, lambda x: "1" if x else "0") + +con = sqlite3.connect(":memory:") +con.isolation_level = None + +#Floor function +con.create_function("floor", 1, math.floor) + +#Mod function +tmp = fpdb_db.sqlitemath() +con.create_function("mod", 2, tmp.mod) + +# Aggregate function VARIANCE() +con.create_aggregate("variance", 1, fpdb_db.VARIANCE) + + +cur = con.cursor() + +def testSQLiteVarianceFunction(): + cur.execute("CREATE TABLE test(i)") + cur.execute("INSERT INTO test(i) values (1)") + cur.execute("INSERT INTO test(i) values (2)") + cur.execute("INSERT INTO test(i) values (3)") + cur.execute("SELECT variance(i) from test") + result = cur.fetchone()[0] + + print "DEBUG: Testing variance function" + print "DEBUG: result: %s expecting: 0.666666 (result-expecting ~= 0.0): %s" % (result, (result - 0.66666)) + cur.execute("DROP TABLE test") + assert (result - 0.66666) <= 0.0001 + +def testSQLiteFloorFunction(): + vars = [0.1, 1.5, 2.6, 3.5, 4.9] + cur.execute("CREATE TABLE test(i float)") + for var in vars: + cur.execute("INSERT INTO test(i) values(%f)" % var) + cur.execute("SELECT floor(i) from test") + result = cur.fetchall() + print "DEBUG: result: %s" % result + answer = 0 + for i in result: + print "DEBUG: int(var): %s" % int(i[0]) + assert answer == int(i[0]) + answer = answer + 1 + cur.execute("DROP TABLE test") + +def testSQLiteModFunction(): + vars = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ,17, 18] + cur.execute("CREATE TABLE test(i int)") + for var in vars: + cur.execute("INSERT INTO test(i) values(%i)" % var) + cur.execute("SELECT mod(i,13) from test") + result = cur.fetchall() + idx = 0 + for i in result: + print "DEBUG: int(var): %s" % i[0] + assert vars[idx]%13 == int(i[0]) + idx = idx+1 + + assert 0 == 1 + cur.execute("DROP TABLE test")