mods to use insert_id() instead of repeated selects and get postgres working
This commit is contained in:
parent
30e61901d6
commit
71a587faca
|
@ -48,7 +48,8 @@ class fpdb_db:
|
||||||
import psycopg2
|
import psycopg2
|
||||||
# If DB connection is made over TCP, then the variables
|
# If DB connection is made over TCP, then the variables
|
||||||
# host, user and password are required
|
# host, user and password are required
|
||||||
if self.host or self.user:
|
print "host=%s user=%s pass=%s." % (host, user, password)
|
||||||
|
if self.host and self.user and self.password:
|
||||||
self.db = psycopg2.connect(host = host,
|
self.db = psycopg2.connect(host = host,
|
||||||
user = user,
|
user = user,
|
||||||
password = password,
|
password = password,
|
||||||
|
|
|
@ -75,8 +75,8 @@ class Importer:
|
||||||
if not pgsqlLibFound:
|
if not pgsqlLibFound:
|
||||||
raise fpdb_simple.FpdbError("interface library psycopg2 not found but PostgreSQL selected as backend - please install the library or change the config file")
|
raise fpdb_simple.FpdbError("interface library psycopg2 not found but PostgreSQL selected as backend - please install the library or change the config file")
|
||||||
print self.settings
|
print self.settings
|
||||||
if not self.settings.has_key('db-host') or \
|
if self.settings.has_key('db-host') and \
|
||||||
not self.settings.has_key('db-user'):
|
self.settings.has_key('db-user'):
|
||||||
self.db = psycopg2.connect(host = self.settings['db-host'],
|
self.db = psycopg2.connect(host = self.settings['db-host'],
|
||||||
user = self.settings['db-user'],
|
user = self.settings['db-user'],
|
||||||
password = self.settings['db-password'],
|
password = self.settings['db-password'],
|
||||||
|
@ -243,7 +243,8 @@ class Importer:
|
||||||
self.hand=hand
|
self.hand=hand
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handsId=fpdb_parse_logic.mainParser(self.db, self.cursor, site, category, hand)
|
handsId=fpdb_parse_logic.mainParser(self.settings['db-backend'], self.db
|
||||||
|
,self.cursor, site, category, hand)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
stored+=1
|
stored+=1
|
||||||
|
|
|
@ -21,7 +21,7 @@ import fpdb_simple
|
||||||
import fpdb_save_to_db
|
import fpdb_save_to_db
|
||||||
|
|
||||||
#parses a holdem hand
|
#parses a holdem hand
|
||||||
def mainParser(db, cursor, site, category, hand):
|
def mainParser(backend, db, cursor, site, category, hand):
|
||||||
if (category=="holdem" or category=="omahahi" or category=="omahahilo"):
|
if (category=="holdem" or category=="omahahi" or category=="omahahilo"):
|
||||||
base="hold"
|
base="hold"
|
||||||
else:
|
else:
|
||||||
|
@ -48,7 +48,7 @@ def mainParser(db, cursor, site, category, hand):
|
||||||
#print "found small blind line:",smallBlindLine
|
#print "found small blind line:",smallBlindLine
|
||||||
break
|
break
|
||||||
#print "small blind line:",smallBlindLine
|
#print "small blind line:",smallBlindLine
|
||||||
gametypeID=fpdb_simple.recogniseGametypeID(db, cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
gametypeID=fpdb_simple.recogniseGametypeID(backend, db, cursor, hand[0], hand[smallBlindLine], siteID, category, isTourney)
|
||||||
if isTourney:
|
if isTourney:
|
||||||
if site!="ps":
|
if site!="ps":
|
||||||
raise fpdb_simple.FpdbError("tourneys are only supported on PS right now")
|
raise fpdb_simple.FpdbError("tourneys are only supported on PS right now")
|
||||||
|
@ -148,25 +148,41 @@ def mainParser(db, cursor, site, category, hand):
|
||||||
payin_amounts=fpdb_simple.calcPayin(len(names), buyin, fee)
|
payin_amounts=fpdb_simple.calcPayin(len(names), buyin, fee)
|
||||||
|
|
||||||
if base=="hold":
|
if base=="hold":
|
||||||
result = fpdb_save_to_db.tourney_holdem_omaha(db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries, prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteID,
|
result = fpdb_save_to_db.tourney_holdem_omaha(
|
||||||
siteHandNo, gametypeID, handStartTime, names, playerIDs, startCashes, positions, cardValues, cardSuits, boardValues, boardSuits, winnings, rakes, actionTypes, allIns, actionAmounts, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
backend, db, cursor, base, category, siteTourneyNo, buyin
|
||||||
|
, fee, knockout, entries, prizepool, tourneyStartTime
|
||||||
|
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
|
||||||
|
, gametypeID, handStartTime, names, playerIDs, startCashes
|
||||||
|
, positions, cardValues, cardSuits, boardValues, boardSuits
|
||||||
|
, winnings, rakes, actionTypes, allIns, actionAmounts
|
||||||
|
, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
||||||
elif base=="stud":
|
elif base=="stud":
|
||||||
result = fpdb_save_to_db.tourney_stud(db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries, prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteID,
|
result = fpdb_save_to_db.tourney_stud(
|
||||||
siteHandNo, gametypeID, handStartTime, names, playerIDs, startCashes, antes, cardValues, cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
backend, db, cursor, base, category, siteTourneyNo
|
||||||
|
, buyin, fee, knockout, entries, prizepool, tourneyStartTime
|
||||||
|
, payin_amounts, ranks, tourneyTypeId, siteID, siteHandNo
|
||||||
|
, gametypeID, handStartTime, names, playerIDs, startCashes
|
||||||
|
, antes, cardValues, cardSuits, winnings, rakes, actionTypes
|
||||||
|
, allIns, actionAmounts, actionNos, hudImportData, maxSeats
|
||||||
|
, tableName, seatNos)
|
||||||
else:
|
else:
|
||||||
raise fpdb_simple.FpdbError ("unrecognised category")
|
raise fpdb_simple.FpdbError ("unrecognised category")
|
||||||
else:
|
else:
|
||||||
if base=="hold":
|
if base=="hold":
|
||||||
result = fpdb_save_to_db.ring_holdem_omaha(db, cursor, base, category, siteHandNo
|
result = fpdb_save_to_db.ring_holdem_omaha(
|
||||||
,gametypeID, handStartTime, names, playerIDs
|
backend, db, cursor, base, category, siteHandNo
|
||||||
,startCashes, positions, cardValues, cardSuits
|
, gametypeID, handStartTime, names, playerIDs
|
||||||
,boardValues, boardSuits, winnings, rakes
|
, startCashes, positions, cardValues, cardSuits
|
||||||
,actionTypes, allIns, actionAmounts, actionNos
|
, boardValues, boardSuits, winnings, rakes
|
||||||
,hudImportData, maxSeats, tableName, seatNos)
|
, actionTypes, allIns, actionAmounts, actionNos
|
||||||
|
, hudImportData, maxSeats, tableName, seatNos)
|
||||||
elif base=="stud":
|
elif base=="stud":
|
||||||
result = fpdb_save_to_db.ring_stud(db, cursor, base, category, siteHandNo, gametypeID,
|
result = fpdb_save_to_db.ring_stud(
|
||||||
handStartTime, names, playerIDs, startCashes, antes, cardValues,
|
backend, db, cursor, base, category, siteHandNo, gametypeID
|
||||||
cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts, actionNos, hudImportData, maxSeats, tableName, seatNos)
|
, handStartTime, names, playerIDs, startCashes, antes
|
||||||
|
, cardValues, cardSuits, winnings, rakes, actionTypes, allIns
|
||||||
|
, actionAmounts, actionNos, hudImportData, maxSeats, tableName
|
||||||
|
, seatNos)
|
||||||
else:
|
else:
|
||||||
raise fpdb_simple.FpdbError ("unrecognised category")
|
raise fpdb_simple.FpdbError ("unrecognised category")
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
|
@ -18,77 +18,110 @@
|
||||||
#This file contains methods to store hands into the db. decides to move this
|
#This file contains methods to store hands into the db. decides to move this
|
||||||
#into a seperate file since its ugly, fairly long and just generally in the way.
|
#into a seperate file since its ugly, fairly long and just generally in the way.
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
|
||||||
import fpdb_simple
|
import fpdb_simple
|
||||||
|
|
||||||
#stores a stud/razz hand into the database
|
#stores a stud/razz hand into the database
|
||||||
def ring_stud(db, cursor, base, category, site_hand_no, gametype_id, hand_start_time, names, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes, action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos):
|
def ring_stud(backend, db, cursor, base, category, site_hand_no, gametype_id, hand_start_time
|
||||||
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
,names, player_ids, start_cashes, antes, card_values, card_suits, winnings, rakes
|
||||||
|
,action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName
|
||||||
hands_id=fpdb_simple.storeHands(db, cursor, site_hand_no, gametype_id, hand_start_time, names, tableName, maxSeats)
|
,seatNos):
|
||||||
|
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
||||||
#print "before calling store_hands_players_stud, antes:", antes
|
|
||||||
hands_players_ids=fpdb_simple.store_hands_players_stud(db, cursor, hands_id, player_ids,
|
hands_id=fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
||||||
start_cashes, antes, card_values, card_suits, winnings, rakes, seatNos)
|
,hand_start_time, names, tableName, maxSeats)
|
||||||
|
|
||||||
fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData)
|
#print "before calling store_hands_players_stud, antes:", antes
|
||||||
|
hands_players_ids=fpdb_simple.store_hands_players_stud(backend, db, cursor, hands_id, player_ids
|
||||||
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
,start_cashes, antes, card_values
|
||||||
return hands_id
|
,card_suits, winnings, rakes, seatNos)
|
||||||
|
|
||||||
|
fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData)
|
||||||
|
|
||||||
|
fpdb_simple.storeActions(cursor, hands_players_ids, action_types
|
||||||
|
,allIns, action_amounts, actionNos)
|
||||||
|
return hands_id
|
||||||
#end def ring_stud
|
#end def ring_stud
|
||||||
|
|
||||||
def ring_holdem_omaha(db, cursor, base, category, site_hand_no, gametype_id, hand_start_time, names, player_ids, start_cashes, positions, card_values, card_suits, board_values, board_suits, winnings, rakes, action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos):
|
def ring_holdem_omaha(backend, db, cursor, base, category, site_hand_no, gametype_id
|
||||||
"""stores a holdem/omaha hand into the database"""
|
,hand_start_time, names, player_ids, start_cashes, positions, card_values
|
||||||
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
,card_suits, board_values, board_suits, winnings, rakes, action_types, allIns
|
||||||
fpdb_simple.fill_board_cards(board_values, board_suits)
|
,action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos):
|
||||||
|
"""stores a holdem/omaha hand into the database"""
|
||||||
|
t0 = time()
|
||||||
|
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
||||||
|
t1 = time()
|
||||||
|
fpdb_simple.fill_board_cards(board_values, board_suits)
|
||||||
|
t2 = time()
|
||||||
|
|
||||||
hands_id=fpdb_simple.storeHands(db, cursor, site_hand_no, gametype_id, hand_start_time, names, tableName, maxSeats)
|
hands_id=fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
||||||
|
,hand_start_time, names, tableName, maxSeats)
|
||||||
hands_players_ids=fpdb_simple.store_hands_players_holdem_omaha(db, cursor, category, hands_id, player_ids, start_cashes, positions, card_values, card_suits, winnings, rakes, seatNos)
|
t3 = time()
|
||||||
|
hands_players_ids=fpdb_simple.store_hands_players_holdem_omaha(
|
||||||
fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData)
|
backend, db, cursor, category, hands_id, player_ids, start_cashes
|
||||||
|
, positions, card_values, card_suits, winnings, rakes, seatNos)
|
||||||
fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits)
|
t4 = time()
|
||||||
|
fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData)
|
||||||
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
t5 = time()
|
||||||
return hands_id
|
fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits)
|
||||||
|
t6 = time()
|
||||||
|
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
||||||
|
t7 = time()
|
||||||
|
print "cards=%4.3f board=%4.3f hands=%4.3f plyrs=%4.3f hudcache=%4.3f board=%4.3f actions=%4.3f" \
|
||||||
|
% (t1-t0, t2-t1, t3-t2, t4-t3, t5-t4, t6-t5, t7-t6)
|
||||||
|
return hands_id
|
||||||
#end def ring_holdem_omaha
|
#end def ring_holdem_omaha
|
||||||
|
|
||||||
def tourney_holdem_omaha(db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries, prizepool, tourney_start, payin_amounts, ranks, tourneyTypeId, siteId, #end of tourney specific params
|
def tourney_holdem_omaha(backend, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout
|
||||||
site_hand_no, gametype_id, hand_start_time, names, player_ids, start_cashes, positions, card_values, card_suits, board_values, board_suits, winnings, rakes, action_types, allIns, action_amounts, actionNos, hudImportData, maxSeats, tableName, seatNos):
|
,entries, prizepool, tourney_start, payin_amounts, ranks, tourneyTypeId
|
||||||
"""stores a tourney holdem/omaha hand into the database"""
|
,siteId #end of tourney specific params
|
||||||
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
,site_hand_no, gametype_id, hand_start_time, names, player_ids
|
||||||
fpdb_simple.fill_board_cards(board_values, board_suits)
|
,start_cashes, positions, card_values, card_suits, board_values
|
||||||
|
,board_suits, winnings, rakes, action_types, allIns, action_amounts
|
||||||
tourney_id=fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourney_start)
|
,actionNos, hudImportData, maxSeats, tableName, seatNos):
|
||||||
tourneys_players_ids=fpdb_simple.store_tourneys_players(cursor, tourney_id, player_ids, payin_amounts, ranks, winnings)
|
"""stores a tourney holdem/omaha hand into the database"""
|
||||||
|
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
|
||||||
hands_id=fpdb_simple.storeHands(db, cursor, site_hand_no, gametype_id, hand_start_time, names, tableName, maxSeats)
|
fpdb_simple.fill_board_cards(board_values, board_suits)
|
||||||
|
|
||||||
hands_players_ids=fpdb_simple.store_hands_players_holdem_omaha_tourney(db, cursor, category, hands_id, player_ids, start_cashes, positions, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids)
|
tourney_id=fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourney_start)
|
||||||
|
tourneys_players_ids=fpdb_simple.store_tourneys_players(cursor, tourney_id, player_ids, payin_amounts, ranks, winnings)
|
||||||
fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData)
|
|
||||||
|
hands_id=fpdb_simple.storeHands(backend, db, cursor, site_hand_no, gametype_id
|
||||||
fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits)
|
,hand_start_time, names, tableName, maxSeats)
|
||||||
|
|
||||||
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
hands_players_ids=fpdb_simple.store_hands_players_holdem_omaha_tourney(
|
||||||
return hands_id
|
backend, db, cursor, category, hands_id, player_ids, start_cashes, positions
|
||||||
|
, card_values, card_suits, winnings, rakes, seatNos, tourneys_players_ids)
|
||||||
|
|
||||||
|
fpdb_simple.storeHudCache(cursor, base, category, gametype_id, player_ids, hudImportData)
|
||||||
|
|
||||||
|
fpdb_simple.store_board_cards(cursor, hands_id, board_values, board_suits)
|
||||||
|
|
||||||
|
fpdb_simple.storeActions(cursor, hands_players_ids, action_types, allIns, action_amounts, actionNos)
|
||||||
|
return hands_id
|
||||||
#end def tourney_holdem_omaha
|
#end def tourney_holdem_omaha
|
||||||
|
|
||||||
def tourney_stud(db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries, prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteId,
|
def tourney_stud(backend, db, cursor, base, category, siteTourneyNo, buyin, fee, knockout, entries
|
||||||
siteHandNo, gametypeId, handStartTime, names, playerIds, startCashes, antes, cardValues, cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts, actionNos, hudImportData, maxSeats, tableName, seatNos):
|
,prizepool, tourneyStartTime, payin_amounts, ranks, tourneyTypeId, siteId
|
||||||
|
,siteHandNo, gametypeId, handStartTime, names, playerIds, startCashes, antes
|
||||||
|
,cardValues, cardSuits, winnings, rakes, actionTypes, allIns, actionAmounts
|
||||||
|
,actionNos, hudImportData, maxSeats, tableName, seatNos):
|
||||||
#stores a tourney stud/razz hand into the database
|
#stores a tourney stud/razz hand into the database
|
||||||
fpdb_simple.fillCardArrays(len(names), base, category, cardValues, cardSuits)
|
fpdb_simple.fillCardArrays(len(names), base, category, cardValues, cardSuits)
|
||||||
|
|
||||||
tourney_id=fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourneyStartTime)
|
tourney_id=fpdb_simple.store_tourneys(cursor, tourneyTypeId, siteTourneyNo, entries, prizepool, tourneyStartTime)
|
||||||
|
|
||||||
tourneys_players_ids=fpdb_simple.store_tourneys_players(cursor, tourney_id, playerIds, payin_amounts, ranks, winnings)
|
tourneys_players_ids=fpdb_simple.store_tourneys_players(cursor, tourney_id, playerIds, payin_amounts, ranks, winnings)
|
||||||
|
|
||||||
hands_id=fpdb_simple.storeHands(db, cursor, siteHandNo, gametypeId, handStartTime, names, tableName, maxSeats)
|
hands_id=fpdb_simple.storeHands(backend, db, cursor, siteHandNo, gametypeId, handStartTime, names, tableName, maxSeats)
|
||||||
|
|
||||||
hands_players_ids=fpdb_simple.store_hands_players_stud_tourney(db, cursor, hands_id, playerIds, startCashes, antes, cardValues, cardSuits, winnings, rakes, seatNos, tourneys_players_ids)
|
hands_players_ids=fpdb_simple.store_hands_players_stud_tourney(backend, db, cursor, hands_id
|
||||||
|
, playerIds, startCashes, antes, cardValues, cardSuits
|
||||||
fpdb_simple.storeHudCache(cursor, base, category, gametypeId, playerIds, hudImportData)
|
, winnings, rakes, seatNos, tourneys_players_ids)
|
||||||
|
|
||||||
fpdb_simple.storeActions(cursor, hands_players_ids, actionTypes, allIns, actionAmounts, actionNos)
|
fpdb_simple.storeHudCache(cursor, base, category, gametypeId, playerIds, hudImportData)
|
||||||
return hands_id
|
|
||||||
|
fpdb_simple.storeActions(cursor, hands_players_ids, actionTypes, allIns, actionAmounts, actionNos)
|
||||||
|
return hands_id
|
||||||
#end def tourney_stud
|
#end def tourney_stud
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user