Merge branch 'master' of git://repo.or.cz/fpbd-bostik

Conflicts:
	pyfpdb/HandHistoryConverter.py
This commit is contained in:
Worros 2009-08-12 22:49:18 +08:00
commit cfd7b40ab6
5 changed files with 17 additions and 143 deletions

View File

@ -22,7 +22,6 @@ import gtk
import os
import fpdb_simple
import fpdb_import
import fpdb_db

View File

@ -76,11 +76,11 @@ follow : whether to tail -f the input"""
else:
# TODO: out_path should be sanity checked.
out_dir = os.path.dirname(self.out_path)
if not os.path.isdir(out_dir):
if not os.path.isdir(out_dir) and out_dir != '':
log.info("Creating directory '%s'" % out_dir)
os.makedirs(out_dir)
try:
self.out_fh = open(self.out_path, 'w')
self.out_fh = codecs.open(self.out_path, 'w', 'cp1252')
log.debug("out_path %s opened as %s" % (self.out_path, self.out_fh))
except:
log.error("out_path %s couldn't be opened" % (self.out_path))

View File

@ -37,7 +37,7 @@ class PokerStars(HandHistoryConverter):
mixes = { 'HORSE': 'horse', '8-Game': '8game', 'HOSE': 'hose'} # Legal mixed games
sym = {'USD': "\$", 'CAD': "\$", 'T$': "", "EUR": "\x80", "GBP": "\xa3"} # ADD Euro, Sterling, etc HERE
substitutions = {
'LEGAL_ISO' : "USD|EUR|GBP|CAD", # legal ISO currency codes
'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
'LS' : "\$|\x80|\xa3" # legal currency symbols ADD Euro, Sterling, etc HERE
}

View File

@ -1,9 +1,7 @@
#!/usr/bin/env python
"""SQL.py
Set up all of the SQL statements for a given game and database type.
"""Returns a dict of SQL statements used in fpdb.
"""
# Copyright 2008, Ray E. Barker
# Copyright 2008-2009, Ray E. Barker
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -35,134 +33,8 @@ import re
class Sql:
def __init__(self, game = 'holdem', type = 'PT3', db_server = 'mysql'):
def __init__(self, game = 'holdem', type = 'fpdb', db_server = 'mysql'):
self.query = {}
############################################################################
#
# Support for the ptracks database, a cut down PT2 stud database.
# You can safely ignore this unless you are me.
#
if game == 'razz' and type == 'ptracks':
self.query['get_table_name'] = "select table_name from game where game_id = %s"
self.query['get_last_hand'] = "select max(game_id) from game"
self.query['get_recent_hands'] = "select game_id from game where game_id > %(last_hand)d"
self.query['get_xml'] = "select xml from hand_history where game_id = %s"
self.query['get_player_id'] = """
select player_id from players
where screen_name = %(player)s
"""
self.query['get_hand_info'] = """
SELECT
game_id,
CONCAT(hole_card_1, hole_card_2, hole_card_3, hole_card_4, hole_card_5, hole_card_6, hole_card_7) AS hand,
total_won-total_bet AS net
FROM game_players
WHERE game_id = %s AND player_id = 3
"""
self.query['get_cards'] = """
select
seat_number,
screen_name,
hole_card_1,
hole_card_2,
hole_card_3,
hole_card_4,
hole_card_5,
hole_card_6,
hole_card_7
from game_players, players
where game_id = %s and game_players.player_id = players.player_id
order by seat_number
"""
self.query['get_stats_from_hand'] = """
SELECT player_id,
count(*) AS n,
sum(pre_fourth_raise_n) AS pfr,
sum(fourth_raise_n) AS raise_n_2,
sum(fourth_ck_raise_n) AS cr_n_2,
sum(fifth_bet_raise_n) AS br_n_3,
sum(fifth_bet_ck_raise_n) AS cr_n_3,
sum(sixth_bet_raise_n) AS br_n_4,
sum(sixth_bet_ck_raise_n) AS cr_n_4,
sum(river_bet_raise_n) AS br_n_5,
sum(river_bet_ck_raise_n) AS cr_n_5,
sum(went_to_showdown_n) AS sd,
sum(saw_fourth_n) AS saw_f,
sum(raised_first_pf) AS first_pfr,
sum(vol_put_money_in_pot) AS vpip,
sum(limp_with_prev_callers) AS limp_w_callers,
sum(ppossible_actions) AS poss_a_pf,
sum(pfold) AS fold_pf,
sum(pcheck) AS check_pf,
sum(praise) AS raise_pf,
sum(pcall) AS raise_pf,
sum(limp_call_reraise_pf) AS limp_call_pf,
sum(pfr_check) AS check_after_raise,
sum(pfr_call) AS call_after_raise,
sum(pfr_fold) AS fold_after_raise,
sum(pfr_bet) AS bet_after_raise,
sum(pfr_raise) AS raise_after_raise,
sum(folded_to_river_bet) AS fold_to_r_bet,
sum(fpossible_actions) AS poss_a_2,
sum(ffold) AS fold_2,
sum(fcheck) AS check_2,
sum(fbet) AS bet_2,
sum(fraise) AS raise_2,
sum(fcall) AS raise_2,
sum(fifpossible_actions) AS poss_a_3,
sum(fiffold) AS fold_3,
sum(fifcheck) AS check_3,
sum(fifbet) AS bet_3,
sum(fifraise) AS raise_3,
sum(fifcall) AS call_3,
sum(spossible_actions) AS poss_a_4,
sum(sfold) AS fold_4,
sum(scheck) AS check_4,
sum(sbet) AS bet_4,
sum(sraise) AS raise_4,
sum(scall) AS call_4,
sum(rpossible_actions) AS poss_a_5,
sum(rfold) AS fold_5,
sum(rcheck) AS check_5,
sum(rbet) AS bet_5,
sum(rraise) AS raise_5,
sum(rcall) AS call_5,
sum(cold_call_pf) AS cc_pf,
sum(saw_fifth_n) AS saw_3,
sum(saw_sixth_n) AS saw_4,
sum(saw_river_n) AS saw_5
FROM game_players
WHERE player_id in
(SELECT player_id FROM game_players
WHERE game_id = %s AND NOT player_id = %s)
GROUP BY player_id
"""
# alternate form of WHERE for above
# WHERE game_id = %(hand)d AND NOT player_id = %(hero)d)
# WHERE game_id = %s AND NOT player_id = %s)
self.query['get_players_from_hand'] = """
SELECT game_players.player_id, seat_number, screen_name
FROM game_players INNER JOIN players ON (game_players.player_id = players.player_id)
WHERE game_id = %s
"""
###############################################################################3
# Support for the Free Poker DataBase = fpdb http://fpdb.sourceforge.net/
#
@ -2899,7 +2771,7 @@ class Sql:
if __name__== "__main__":
# just print the default queries and exit
s = Sql(game = 'razz', type = 'ptracks')
s = Sql()
for key in s.query:
print "For query " + key + ", sql ="
print s.query[key]

View File

@ -25,6 +25,7 @@ import datetime
import time
import re
import sys
import locale
import Card
@ -37,6 +38,8 @@ MYSQL_INNODB = 2
PGSQL = 3
SQLITE = 4
(localename, encoding) = locale.getdefaultlocale()
class DuplicateError(Exception):
def __init__(self, value):
self.value = value
@ -543,7 +546,7 @@ def parseActionType(line):
#parses the ante out of the given line and checks which player paid it, updates antes accordingly.
def parseAnteLine(line, isTourney, names, antes):
for i, name in enumerate(names):
if line.startswith(name.encode("latin-1")):
if line.startswith(name.encode(encoding)):
pos = line.rfind("$") + 1
if not isTourney:
antes[i] += float2int(line[pos:])
@ -705,7 +708,7 @@ def parseHandStartTime(topline):
def findName(line):
pos1 = line.find(":") + 2
pos2 = line.rfind("(") - 1
return unicode(line[pos1:pos2], "latin-1")
return unicode(line[pos1:pos2], encoding)
def parseNames(lines):
return [findName(line) for line in lines]
@ -822,7 +825,7 @@ def parseTourneyNo(topline):
def parseWinLine(line, names, winnings, isTourney):
#print "parseWinLine: line:",line
for i,n in enumerate(names):
n = n.encode("latin-1")
n = n.encode(encoding)
if line.startswith(n):
if isTourney:
pos1 = line.rfind("collected ") + 10
@ -1033,13 +1036,13 @@ def recognisePlayerNo(line, names, atype):
#print "recogniseplayerno, names:",names
for i in xrange(len(names)):
if (atype=="unbet"):
if (line.endswith(names[i].encode("latin-1"))):
if (line.endswith(names[i].encode(encoding))):
return (i)
elif (line.startswith("Dealt to ")):
#print "recognisePlayerNo, card precut, line:",line
tmp=line[9:]
#print "recognisePlayerNo, card postcut, tmp:",tmp
if (tmp.startswith(names[i].encode("latin-1"))):
if (tmp.startswith(names[i].encode(encoding))):
return (i)
elif (line.startswith("Seat ")):
if (line.startswith("Seat 10")):
@ -1047,10 +1050,10 @@ def recognisePlayerNo(line, names, atype):
else:
tmp=line[8:]
if (tmp.startswith(names[i].encode("latin-1"))):
if (tmp.startswith(names[i].encode(encoding))):
return (i)
else:
if (line.startswith(names[i].encode("latin-1"))):
if (line.startswith(names[i].encode(encoding))):
return (i)
#if we're here we mustve failed
raise FpdbError ("failed to recognise player in: "+line+" atype:"+atype)