raise FpdbHandDuplicate error on duplicate insert attempt, catch it in import_file_dict, increment duplicates count

This commit is contained in:
Eric Blade 2010-01-28 05:56:17 -05:00
parent d36ac3f927
commit 3381527afc
2 changed files with 14 additions and 13 deletions

View File

@ -229,8 +229,7 @@ db: a connected Database object"""
# TourneysPlayers # TourneysPlayers
else: else:
log.info("Hand.insert(): hid #: %s is a duplicate" % hh['siteHandNo']) log.info("Hand.insert(): hid #: %s is a duplicate" % hh['siteHandNo'])
#Raise Duplicate exception? raise FpdbHandDuplicate(hh['siteHandNo'])
pass
def updateHudCache(self, db): def updateHudCache(self, db):
db.storeHudCache(self.dbid_gt, self.dbid_pids, self.starttime, self.stats.getHandsPlayers()) db.storeHudCache(self.dbid_gt, self.dbid_pids, self.starttime, self.stats.getHandsPlayers())
@ -618,7 +617,7 @@ class HoldemOmahaHand(Hand):
if builtFrom == "HHC": if builtFrom == "HHC":
hhc.readHandInfo(self) hhc.readHandInfo(self)
if self.gametype['type'] == 'tour': if self.gametype['type'] == 'tour':
self.tablename = "%s %s" % (self.tourNo, self.tablename) self.tablename = "%s %s" % (self.tourNo, self.tablename)
hhc.readPlayerStacks(self) hhc.readPlayerStacks(self)
hhc.compilePlayerRegexs(self) hhc.compilePlayerRegexs(self)
hhc.markStreets(self) hhc.markStreets(self)
@ -914,7 +913,7 @@ class DrawHand(Hand):
if builtFrom == "HHC": if builtFrom == "HHC":
hhc.readHandInfo(self) hhc.readHandInfo(self)
if self.gametype['type'] == 'tour': if self.gametype['type'] == 'tour':
self.tablename = "%s %s" % (self.tourNo, self.tablename) self.tablename = "%s %s" % (self.tourNo, self.tablename)
hhc.readPlayerStacks(self) hhc.readPlayerStacks(self)
hhc.compilePlayerRegexs(self) hhc.compilePlayerRegexs(self)
hhc.markStreets(self) hhc.markStreets(self)
@ -1110,7 +1109,7 @@ class StudHand(Hand):
if builtFrom == "HHC": if builtFrom == "HHC":
hhc.readHandInfo(self) hhc.readHandInfo(self)
if self.gametype['type'] == 'tour': if self.gametype['type'] == 'tour':
self.tablename = "%s %s" % (self.tourNo, self.tablename) self.tablename = "%s %s" % (self.tourNo, self.tablename)
hhc.readPlayerStacks(self) hhc.readPlayerStacks(self)
hhc.compilePlayerRegexs(self) hhc.compilePlayerRegexs(self)
hhc.markStreets(self) hhc.markStreets(self)
@ -1202,7 +1201,7 @@ Add a complete on [street] by [player] to [amountTo]
# showdownPot INT, /* pot size at sd/street7 */ # showdownPot INT, /* pot size at sd/street7 */
return (0,0,0,0,0) return (0,0,0,0,0)
def writeHand(self, fh=sys.__stdout__): def writeHand(self, fh=sys.__stdout__):
# PokerStars format. # PokerStars format.
@ -1597,4 +1596,3 @@ ORDER BY
return h return h

View File

@ -437,13 +437,15 @@ class Importer:
for hand in handlist: for hand in handlist:
if hand is not None: if hand is not None:
#try, except duplicates here?
hand.prepInsert(self.database) hand.prepInsert(self.database)
hand.insert(self.database) try:
hand.insert(self.database)
if self.callHud and hand.dbid_hands != 0: except Exceptions.FpdbHandDuplicate:
to_hud.append(hand.dbid_hands) duplicates += 1
else: else:
if self.callHud and hand.dbid_hands != 0:
to_hud.append(hand.dbid_hands)
else: # TODO: Treat empty as an error, or just ignore?
log.error("Hand processed but empty") log.error("Hand processed but empty")
self.database.commit() self.database.commit()
# Call hudcache update if not in bulk import mode # Call hudcache update if not in bulk import mode
@ -461,6 +463,7 @@ class Importer:
errors = getattr(hhc, 'numErrors') errors = getattr(hhc, 'numErrors')
stored = getattr(hhc, 'numHands') stored = getattr(hhc, 'numHands')
stored -= duplicates
else: else:
# conversion didn't work # conversion didn't work
# TODO: appropriate response? # TODO: appropriate response?