def __init__(self, settings, config, sql = None, parent = None, cli = False):
        self.importtimer = 0
        self.settings = settings
        self.config = config
        self.sql = sql
        self.parent = parent

        imp = self.config.get_import_parameters()

        self.input_settings = {}
        self.pipe_to_hud = None

        self.importer = fpdb_import.Importer(self, self.settings, self.config, self.sql)
        self.importer.setCallHud(True)
        self.importer.setQuiet(False)
        self.importer.setFailOnError(False)
        self.importer.setHandCount(0)

        self.server = settings['db-host']
        self.user = settings['db-user']
        self.password = settings['db-password']
        self.database = settings['db-databaseName']

        if cli == False:
            self.setupGui()
        else:
            # TODO: Separate the code that grabs the directories from config
            #       Separate the calls to the Importer API
            #       Create a timer interface that doesn't rely on GTK
            pass
Ejemplo n.º 2
0
def testFlopImport():
    db.recreate_tables()
    importer = fpdb_import.Importer(False, settings, config)
    importer.setDropIndexes("don't drop")
    importer.setFailOnError(True)
    importer.setThreads(-1)
    importer.addBulkImportImportFileOrDir(
            """regression-test-files/cash/Betfair/Flop/PLO-6max-USD-0.05-0.10-200909.All.in.river.splitpot.txt""", site="Betfair")
    importer.setCallHud(False)
    (stored, dups, partial, errs, ttime) = importer.runImport()
    importer.clearFileList()

    # Should actually do some testing here
    assert 1 == 1
Ejemplo n.º 3
0
def testStudImport():
    db.recreate_tables()
    importer = fpdb_import.Importer(False, settings, config)
    importer.setDropIndexes("don't drop")
    importer.setFailOnError(True)
    importer.setThreads(-1)
    importer.addBulkImportImportFileOrDir(
            """regression-test-files/cash/Stars/Stud/7-Stud-USD-0.04-0.08-200911.txt""", site="PokerStars")
    importer.addBulkImportImportFileOrDir(
            """regression-test-files/cash/Stars/Stud/7-StudHL-USD-0.04-0.08-200911.txt""", site="PokerStars")
    importer.addBulkImportImportFileOrDir(
            """regression-test-files/cash/Stars/Stud/Razz-USD-0.04-0.08-200911.txt""", site="PokerStars")
    importer.setCallHud(False)
    (stored, dups, partial, errs, ttime) = importer.runImport()
    importer.clearFileList()

    # Should actually do some testing here
    assert 1 == 1
Ejemplo n.º 4
0
def testDrawImport():
    try:
        db.recreate_tables()
        importer = fpdb_import.Importer(False, settings, config)
        importer.setDropIndexes("don't drop")
        importer.setFailOnError(True)
        importer.setThreads(-1)
        importer.addBulkImportImportFileOrDir(
                """regression-test-files/cash/Stars/Draw/3-Draw-Limit-USD-0.10-0.20-200911.txt""", site="PokerStars")
        importer.addBulkImportImportFileOrDir(
                """regression-test-files/cash/Stars/Draw/5-Carddraw-USD-0.10-0.20-200911.txt""", site="PokerStars")
        importer.setCallHud(False)
        (stored, dups, partial, errs, ttime) = importer.runImport()
        importer.clearFileList()
    except FpdbError:
        assert 0 == 1

    # Should actually do some testing here
    assert 1 == 1
Ejemplo n.º 5
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    config = Configuration.Config(file = "HUD_config.test.xml")
    db = Database.Database(config)
    sql = SQL.Sql(db_server = 'sqlite')
    settings = {}
    settings.update(config.get_db_parameters())
    settings.update(config.get_import_parameters())
    settings.update(config.get_default_paths())
    db.recreate_tables()
    importer = fpdb_import.Importer(False, settings, config)
    importer.setDropIndexes("don't drop")
    importer.setFailOnError(True)
    importer.setThreads(-1)
    importer.setCallHud(False)
    importer.setFakeCacheHHC(True)

    PokerStarsErrors = FpdbError('PokerStars')
    FTPErrors        = FpdbError('Full Tilt Poker')
    PartyPokerErrors = FpdbError('Party Poker')
    BetfairErrors    = FpdbError('Betfair')
    
    walk_testfiles("regression-test-files/cash/Stars/", compare, importer, PokerStarsErrors, "PokerStars")
    walk_testfiles("regression-test-files/cash/FTP/", compare, importer, FTPErrors, "Full Tilt Poker")
    #walk_testfiles("regression-test-files/cash/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
    walk_testfiles("regression-test-files/cash/Betfair/", compare, importer, BetfairErrors, "Betfair")

    totalerrors = PokerStarsErrors.errorcount + FTPErrors.errorcount + PartyPokerErrors.errorcount + BetfairErrors.errorcount

    print "---------------------"
    print "Total Errors: %d" % totalerrors
    print "---------------------"
    PokerStarsErrors.print_histogram()
    FTPErrors.print_histogram()
    PartyPokerErrors.print_histogram()
    BetfairErrors.print_histogram()
Ejemplo n.º 6
0
def testFlopImport():
    db.recreate_tables()
    importer = fpdb_import.Importer(False, settings, config)
    importer.setDropIndexes("don't drop")
    importer.setFailOnError(True)
    importer.setThreads(-1)
    importer.addBulkImportImportFileOrDir(
        """regression-test-files/cash/Stars/Flop/NLHE-6max-EUR-0.05-0.10-200911.txt""",
        site="PokerStars")
    importer.addBulkImportImportFileOrDir(
        """regression-test-files/cash/Stars/Flop/NLHE-6max-USD-0.05-0.10-200911.txt""",
        site="PokerStars")
    #importer.addBulkImportImportFileOrDir(
    #        """regression-test-files/tour/Stars/Flop/NLHE-USD-MTT-5r-200710.txt""", site="PokerStars")
    importer.addBulkImportImportFileOrDir(
        """regression-test-files/cash/Stars/Flop/PLO8-6max-USD-0.01-0.02-200911.txt""",
        site="PokerStars")
    #HID - 36185273365
    # Besides the horrible play it contains lots of useful cases
    # Preflop: raise, then 3bet chance for seat 2
    # Flop: Checkraise by hero, 4bet chance not taken by villain
    # Turn: Turn continuation bet by hero, called
    # River: hero (continuation bets?) all-in and is not called
    importer.addBulkImportImportFileOrDir(
        """regression-test-files/cash/Stars/Flop/NLHE-6max-USD-0.05-0.10-200912.Stats-comparision.txt""",
        site="PokerStars")
    importer.addBulkImportImportFileOrDir(
        """regression-test-files/cash/Stars/Flop/NLHE-6max-USD-0.05-0.10-200912.Allin-pre.txt""",
        site="PokerStars")
    importer.setCallHud(False)
    (stored, dups, partial, errs, ttime) = importer.runImport()
    print "DEBUG: stored: %s dups: %s partial: %s errs: %s ttime: %s" % (
        stored, dups, partial, errs, ttime)
    importer.clearFileList()

    col = {'sawShowdown': 2, 'street0Aggr': 3}

    q = """SELECT
    s.name,
    p.name,
    hp.sawShowdown,
    hp.street0Aggr
FROM
    Hands as h,
    Sites as s,
    Gametypes as g,
    HandsPlayers as hp,
    Players as p
WHERE
    h.siteHandNo = 36185273365
and g.id = h.gametypeid
and hp.handid = h.id
and p.id = hp.playerid
and s.id = p.siteid"""
    c = db.get_cursor()
    c.execute(q)
    result = c.fetchall()
    for row, data in enumerate(result):
        print "DEBUG: result[%s]: %s" % (row, result[row])
        # Assert if any sawShowdown = True
        assert result[row][col['sawShowdown']] == 0

    q = """SELECT
    s.name,
    p.name,
    hp.sawShowdown,
    hp.street0Aggr
FROM
    Hands as h,
    Sites as s,
    Gametypes as g,
    HandsPlayers as hp,
    Players as p
WHERE
    h.siteHandNo = 37165169101
and g.id = h.gametypeid
and hp.handid = h.id
and p.id = hp.playerid
and s.id = p.siteid"""
    c = db.get_cursor()
    c.execute(q)
    result = c.fetchall()
    pstats = {
        u'Kinewma': 0,
        u'Arbaz': 0,
        u's0rrow': 1,
        u'bys7': 0,
        u'AAALISAAAA': 1,
        u'Bl\xe5veis': 0
    }
    for row, data in enumerate(result):
        print "DEBUG: result[%s]: %s == %s" % (row, result[row],
                                               pstats[data[1]])
        assert result[row][col['sawShowdown']] == pstats[data[1]]

    assert 0 == 1
Ejemplo n.º 7
0
    def __init__(self, settings, config, sql, parent):
        self.importtimer = 0
        self.settings = settings
        self.config = config
        self.sql = sql
        self.parent = parent

        imp = self.config.get_import_parameters()

#        print "Import parameters"
#        print imp

        self.input_settings = {}
        self.pipe_to_hud = None

        self.importer = fpdb_import.Importer(self, self.settings, self.config, self.sql)
        self.importer.setCallHud(True)
        self.importer.setMinPrint(settings['minPrint'])
        self.importer.setQuiet(False)
        self.importer.setFailOnError(False)
        self.importer.setHandCount(0)
#        self.importer.setWatchTime()

        self.server = settings['db-host']
        self.user = settings['db-user']
        self.password = settings['db-password']
        self.database = settings['db-databaseName']

        self.mainVBox = gtk.VBox(False,1)

        hbox = gtk.HBox(True, 0) # contains 2 equal vboxes
        self.mainVBox.pack_start(hbox, False, False, 0)

        vbox1 = gtk.VBox(True, 0)
        hbox.pack_start(vbox1, True, True, 0)
        vbox2 = gtk.VBox(True, 0)
        hbox.pack_start(vbox2, True, True, 0)

        self.intervalLabel = gtk.Label(_("Time between imports in seconds:"))
        self.intervalLabel.set_alignment(xalign=1.0, yalign=0.5)
        vbox1.pack_start(self.intervalLabel, False, True, 0)

        hbox = gtk.HBox(False, 0)
        vbox2.pack_start(hbox, False, True, 0)
        self.intervalEntry = gtk.Entry()
        self.intervalEntry.set_text(str(self.config.get_import_parameters().get("interval")))
        hbox.pack_start(self.intervalEntry, False, False, 0)
        lbl1 = gtk.Label()
        hbox.pack_start(lbl1, expand=False, fill=True)

        lbl = gtk.Label('')
        vbox1.pack_start(lbl, expand=False, fill=True)
        lbl = gtk.Label('')
        vbox2.pack_start(lbl, expand=False, fill=True)

        self.addSites(vbox1, vbox2)
        self.textbuffer = gtk.TextBuffer()
        self.textview = gtk.TextView(self.textbuffer)

        hbox = gtk.HBox(False, 0)
        self.mainVBox.pack_start(hbox, expand=True, padding=3)

        hbox = gtk.HBox(False, 0)
        self.mainVBox.pack_start(hbox, expand=False, padding=3)

        lbl1 = gtk.Label()
        hbox.pack_start(lbl1, expand=True, fill=False)

        self.doAutoImportBool = False
        self.startButton = gtk.ToggleButton(_("  Start _Auto Import  "))
        self.startButton.connect("clicked", self.startClicked, "start clicked")
        hbox.pack_start(self.startButton, expand=False, fill=False)


        lbl2 = gtk.Label()
        hbox.pack_start(lbl2, expand=True, fill=False)

        hbox = gtk.HBox(False, 0)
        hbox.show()

        self.mainVBox.pack_start(hbox, expand=True, padding=3)

        scrolledwindow = gtk.ScrolledWindow()
        scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.mainVBox.pack_end(scrolledwindow, expand=True)
        scrolledwindow.add(self.textview)

        self.mainVBox.show_all()
        self.addText(_("Auto Import Ready."))
Ejemplo n.º 8
0
    def importhand(self, handnumber=1):
        """Temporary function that grabs a Hand object from a specified file. Obviously this will
        be replaced by a function to select a hand from the db in the not so distant future.
        This code has been shamelessly stolen from Carl
        """
        if False:
            settings = {}
            settings.update(self.conf.get_db_parameters())
            settings.update(self.conf.get_import_parameters())
            settings.update(self.conf.get_default_paths())

            importer = fpdb_import.Importer(False, settings, self.conf, None)
            importer.setDropIndexes("don't drop")
            importer.setFailOnError(True)
            importer.setThreads(-1)
            importer.setCallHud(False)
            importer.setFakeCacheHHC(True)

            print "DEBUG: self.filename: '%s' self.site: '%s'" % (
                self.filename, self.site)
            importer.addBulkImportImportFileOrDir(self.filename,
                                                  site=self.site)
            (stored, dups, partial, errs, ttime) = importer.runImport()

            hhc = importer.getCachedHHC()
            handlist = hhc.getProcessedHands()

            return handlist[0]
        else:
            # Fetch hand info
            # We need at least sitename, gametype, handid
            # for the Hand.__init__

            ####### Shift this section in Database.py for all to use ######
            handid = 1
            q = self.sql.query['get_gameinfo_from_hid']
            q = q.replace('%s', self.sql.query['placeholder'])

            c = self.db.get_cursor()

            c.execute(q, (handid, ))
            res = c.fetchone()
            gametype = {
                'category': res[1],
                'base': res[2],
                'type': res[3],
                'limitType': res[4],
                'hilo': res[5],
                'sb': res[6],
                'bb': res[7],
                'currency': res[10]
            }
            #FIXME: smallbet and bigbet are res[8] and res[9] respectively
            ###### End section ########
            print "DEBUG: gametype: %s" % gametype
            if gametype['base'] == 'hold':
                h = HoldemOmahaHand(config=self.conf,
                                    hhc=None,
                                    sitename=res[0],
                                    gametype=gametype,
                                    handText=None,
                                    builtFrom="DB",
                                    handid=handid)
                h.select(self.db, handid)
            elif gametype['base'] == 'stud':
                print "DEBUG: Create stud hand here"
            elif gametype['base'] == 'draw':
                print "DEBUG: Create draw hand here"
            return h
Ejemplo n.º 9
0
def main(argv=None):
    """main can also be called in the python interpreter, by supplying the command line as the argument."""
    if argv is None:
        argv = sys.argv[1:]

    def destroy(*args):  # call back for terminating the main eventloop
        gtk.main_quit()

    parser = OptionParser()
    parser.add_option("-f",
                      "--file",
                      dest="filename",
                      metavar="FILE",
                      default=None,
                      help=_("Input file"))
    parser.add_option(
        "-c",
        "--convert",
        dest="filtername",
        default=None,
        metavar="FILTER",
        help=_("Site") +
        " (Absolute, Merge, Everleaf, Full Tilt Poker, PokerStars, ...)"
    )  #TODO: dynamically generate list
    parser.add_option(
        "-x",
        "--failOnError",
        action="store_true",
        default=False,
        help=
        _("If this option is used it quits with an extended error message if it encounters any error"
          ))
    parser.add_option("-u",
                      "--usage",
                      action="store_true",
                      dest="usage",
                      default=False,
                      help=_("Print some useful one liners"))
    parser.add_option(
        "-s",
        "--starsarchive",
        action="store_true",
        dest="starsArchive",
        default=False,
        help=
        _("Do the required conversion for %s archive format (ie. as provided by support)"
          ) % "PokerStars")
    parser.add_option(
        "-F",
        "--ftparchive",
        action="store_true",
        dest="ftpArchive",
        default=False,
        help=
        _("Do the required conversion for %s archive format (ie. as provided by support)"
          ) % "Full Tilt Poker")
    parser.add_option(
        "-t",
        "--testdata",
        action="store_true",
        dest="testData",
        default=False,
        help=_("Generate and print test data for regression testing"))
    parser.add_option("-C",
                      "--configFile",
                      dest="config",
                      default=None,
                      help=_("Specifies a configuration file."))
    (options, argv) = parser.parse_args(args=argv)

    if options.usage == True:
        #Print usage examples and exit
        print _("USAGE:")
        print('PokerStars ' + _('converter') +
              ': ./GuiBulkImport.py -c PokerStars -f filename')
        print('Full Tilt  ' + _('converter') +
              ': ./GuiBulkImport.py -c "Full Tilt Poker" -f filename')
        print('Everleaf   ' + _('converter') +
              ': ./GuiBulkImport.py -c Everleaf -f filename')
        print('Absolute   ' + _('converter') +
              ': ./GuiBulkImport.py -c Absolute -f filename')
        print('PartyPoker ' + _('converter') +
              ': ./GuiBulkImport.py -c PartyPoker -f filename')
        sys.exit(0)

    Configuration.set_logfile("GuiBulkImport-log.txt")
    if options.config:
        config = Configuration.Config(options.config)
    else:
        config = Configuration.Config()

    settings = {}
    if os.name == 'nt': settings['os'] = 'windows'
    else: settings['os'] = 'linuxmac'

    settings.update(config.get_db_parameters())
    settings.update(config.get_import_parameters())
    settings.update(config.get_default_paths())

    if not options.filename:
        i = GuiBulkImport(settings, config, None)
        main_window = gtk.Window()
        main_window.connect('destroy', destroy)
        main_window.add(i.vbox)
        main_window.show()
        gtk.main()
    else:
        if not options.filtername:
            print _(
                "You have to select a site with the -c parameter. E.g.:"
            ), "Everleaf   converter: ./GuiBulkImport.py -c Everleaf -f filename"
        #Do something useful
        importer = fpdb_import.Importer(False, settings, config, None)
        # importer.setDropIndexes("auto")
        importer.setDropIndexes(_("don't drop"))
        importer.setFailOnError(options.failOnError)
        importer.setThreads(-1)
        importer.addBulkImportImportFileOrDir(os.path.expanduser(
            options.filename),
                                              site=options.filtername)
        importer.setCallHud(False)
        if options.starsArchive:
            importer.setStarsArchive(True)
        if options.ftpArchive:
            importer.setFTPArchive(True)
        if options.testData:
            importer.setPrintTestData(True)
        (stored, dups, partial, errs, ttime) = importer.runImport()
        importer.clearFileList()
        print(_('Bulk import done: Stored: %d, Duplicates: %d, Partial: %d, Errors: %d, Time: %s seconds, Stored/second: %.0f')\
                     % (stored, dups, partial, errs, ttime, (stored+0.0) / ttime))
Ejemplo n.º 10
0
    def __init__(self, settings, config, sql=None, parent=None):
        self.settings = settings
        self.config = config
        self.parent = parent

        self.importer = fpdb_import.Importer(self, self.settings, config, sql,
                                             parent)

        self.vbox = gtk.VBox(False, 0)
        self.vbox.show()

        self.chooser = gtk.FileChooserWidget()
        self.chooser.set_filename(self.settings['bulkImport-defaultPath'])
        self.chooser.set_select_multiple(True)
        self.vbox.add(self.chooser)
        self.chooser.show()

        #    Table widget to hold the settings
        self.table = gtk.Table(rows=5, columns=5, homogeneous=False)
        self.vbox.add(self.table)
        self.table.show()

        #    checkbox - print start/stop?
        self.chk_st_st = gtk.CheckButton(_('Print Start/Stop Info'))
        self.table.attach(self.chk_st_st,
                          0,
                          1,
                          0,
                          1,
                          xpadding=10,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.chk_st_st.show()
        self.chk_st_st.set_active(True)

        #    label - status
        self.lab_status = gtk.Label(_("Hands/status print:"))
        self.table.attach(self.lab_status,
                          1,
                          2,
                          0,
                          1,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.lab_status.show()
        self.lab_status.set_justify(gtk.JUSTIFY_RIGHT)
        self.lab_status.set_alignment(1.0, 0.5)

        #    spin button - status
        status_adj = gtk.Adjustment(
            value=100,
            lower=0,
            upper=300,
            step_incr=10,
            page_incr=1,
            page_size=0)  #not sure what upper value should be!
        self.spin_status = gtk.SpinButton(adjustment=status_adj,
                                          climb_rate=0.0,
                                          digits=0)
        self.table.attach(self.spin_status,
                          2,
                          3,
                          0,
                          1,
                          xpadding=10,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.spin_status.show()

        #    label - threads
        self.lab_threads = gtk.Label(_("Number of threads:"))
        self.table.attach(self.lab_threads,
                          3,
                          4,
                          0,
                          1,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.lab_threads.show()
        if not self.allowThreads:
            self.lab_threads.set_sensitive(False)
        self.lab_threads.set_justify(gtk.JUSTIFY_RIGHT)
        self.lab_threads.set_alignment(1.0, 0.5)

        #    spin button - threads
        threads_adj = gtk.Adjustment(
            value=0, lower=0, upper=32, step_incr=1, page_incr=1,
            page_size=0)  #not sure what upper value should be!
        self.spin_threads = gtk.SpinButton(adjustment=threads_adj,
                                           climb_rate=0.0,
                                           digits=0)
        self.table.attach(self.spin_threads,
                          4,
                          5,
                          0,
                          1,
                          xpadding=10,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.spin_threads.show()
        if not self.allowThreads:
            self.spin_threads.set_sensitive(False)


#    checkbox - archive file?
        self.is_archive = gtk.CheckButton(_('Archive File'))
        self.table.attach(self.is_archive,
                          0,
                          1,
                          1,
                          2,
                          xpadding=10,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.is_archive.show()

        #    label - hands
        self.lab_hands = gtk.Label(_("Hands/file:"))
        self.table.attach(self.lab_hands,
                          1,
                          2,
                          1,
                          2,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.lab_hands.show()
        self.lab_hands.set_justify(gtk.JUSTIFY_RIGHT)
        self.lab_hands.set_alignment(1.0, 0.5)

        #    spin button - hands to import
        hands_adj = gtk.Adjustment(
            value=0, lower=0, upper=10, step_incr=1, page_incr=1,
            page_size=0)  #not sure what upper value should be!
        self.spin_hands = gtk.SpinButton(adjustment=hands_adj,
                                         climb_rate=0.0,
                                         digits=0)
        self.table.attach(self.spin_hands,
                          2,
                          3,
                          1,
                          2,
                          xpadding=10,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.spin_hands.show()

        #    label - drop indexes
        self.lab_drop = gtk.Label(_("Drop indexes:"))
        self.table.attach(self.lab_drop,
                          3,
                          4,
                          1,
                          2,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.lab_drop.show()
        self.lab_drop.set_justify(gtk.JUSTIFY_RIGHT)
        self.lab_drop.set_alignment(1.0, 0.5)

        #    ComboBox - drop indexes
        self.cb_dropindexes = gtk.combo_box_new_text()
        self.cb_dropindexes.append_text(_('auto'))
        self.cb_dropindexes.append_text(_("don't drop"))
        self.cb_dropindexes.append_text(_('drop'))
        self.cb_dropindexes.set_active(0)
        self.table.attach(self.cb_dropindexes,
                          4,
                          5,
                          1,
                          2,
                          xpadding=10,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.cb_dropindexes.show()

        self.cb_testmode = gtk.CheckButton(_('HUD Test mode'))
        self.table.attach(self.cb_testmode,
                          0,
                          1,
                          2,
                          3,
                          xpadding=10,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.cb_testmode.show()

        #    label - filter
        self.lab_filter = gtk.Label(_("Site filter:"))
        self.table.attach(self.lab_filter,
                          1,
                          2,
                          2,
                          3,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.lab_filter.show()
        self.lab_filter.set_justify(gtk.JUSTIFY_RIGHT)
        self.lab_filter.set_alignment(1.0, 0.5)

        #    ComboBox - filter
        self.cbfilter = gtk.combo_box_new_text()
        disabled_sites = []  # move disabled sites to bottom of list
        self.cbfilter.append_text(_("Please select site"))
        for w in self.config.hhcs:
            try:
                if self.config.supported_sites[
                        w].enabled:  # include enabled ones first
                    print w
                    self.cbfilter.append_text(w)
                else:
                    disabled_sites.append(w)
            except:  # self.supported_sites[w] may not exist if hud_config is bad
                disabled_sites.append(w)
        for w in disabled_sites:  # then disabled ones
            print w
            self.cbfilter.append_text(w)
        self.cbfilter.set_active(0)
        self.table.attach(self.cbfilter,
                          2,
                          3,
                          2,
                          3,
                          xpadding=10,
                          ypadding=1,
                          yoptions=gtk.SHRINK)
        self.cbfilter.show()

        #    label - drop hudcache
        self.lab_hdrop = gtk.Label(_("Drop HudCache:"))
        self.table.attach(self.lab_hdrop,
                          3,
                          4,
                          2,
                          3,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.lab_hdrop.show()
        self.lab_hdrop.set_justify(gtk.JUSTIFY_RIGHT)
        self.lab_hdrop.set_alignment(1.0, 0.5)

        #    ComboBox - drop hudcache
        self.cb_drophudcache = gtk.combo_box_new_text()
        self.cb_drophudcache.append_text(_('auto'))
        self.cb_drophudcache.append_text(_("don't drop"))
        self.cb_drophudcache.append_text(_('drop'))
        self.cb_drophudcache.set_active(0)
        self.table.attach(self.cb_drophudcache,
                          4,
                          5,
                          2,
                          3,
                          xpadding=10,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.cb_drophudcache.show()

        #    button - Import
        self.load_button = gtk.Button(
            _('_Bulk Import'))  # todo: rename variables to import too
        self.load_button.connect('clicked', self.load_clicked,
                                 _('Import clicked'))
        self.table.attach(self.load_button,
                          2,
                          3,
                          4,
                          5,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.load_button.show()

        #    label - spacer (keeps rows 3 & 5 apart)
        self.lab_spacer = gtk.Label()
        self.table.attach(self.lab_spacer,
                          3,
                          5,
                          3,
                          4,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.lab_spacer.show()

        #    label - info
        #        self.lab_info = gtk.Label()
        #        self.table.attach(self.lab_info, 3, 5, 4, 5, xpadding = 0, ypadding = 0, yoptions=gtk.SHRINK)
        #        self.lab_info.show()
        self.progressbar = gtk.ProgressBar()
        self.table.attach(self.progressbar,
                          3,
                          5,
                          4,
                          5,
                          xpadding=0,
                          ypadding=0,
                          yoptions=gtk.SHRINK)
        self.progressbar.set_text(_("Waiting..."))
        self.progressbar.set_fraction(0)
        self.progressbar.show()

        #    see how many hands are in the db and adjust accordingly
        tcursor = self.importer.database.cursor
        tcursor.execute("Select count(1) from Hands")
        row = tcursor.fetchone()
        tcursor.close()
        self.importer.database.rollback()
        self.n_hands_in_db = row[0]
        if self.n_hands_in_db == 0:
            self.cb_dropindexes.set_active(2)
            self.cb_dropindexes.set_sensitive(False)
            self.lab_drop.set_sensitive(False)
            self.cb_drophudcache.set_active(2)
            self.cb_drophudcache.set_sensitive(False)
            self.lab_hdrop.set_sensitive(False)
Ejemplo n.º 11
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    (options, argv) = Options.fpdb_options()

    test_all_sites = True

    if options.usage == True:
        usage()

    single_file_test = False

    if options.sitename:
        options.sitename = Options.site_alias(options.sitename)
        if options.sitename == False:
            usage()
        if options.filename:
            print "Testing single hand: '%s'" % options.filename
            single_file_test = True
        else:
            print "Only regression testing '%s' files" % (options.sitename)
        test_all_sites = False

    config = Configuration.Config(file = "HUD_config.test.xml")
    db = Database.Database(config)
    sql = SQL.Sql(db_server = 'sqlite')
    settings = {}
    settings.update(config.get_db_parameters())
    settings.update(config.get_import_parameters())
    settings.update(config.get_default_paths())
    db.recreate_tables()
    importer = fpdb_import.Importer(False, settings, config, None)
    importer.setDropIndexes("don't drop")
    importer.setFailOnError(True)
    importer.setThreads(-1)
    importer.setCallHud(False)
    importer.setFakeCacheHHC(True)

    PacificPokerErrors= FpdbError('PacificPoker')
    PokerStarsErrors  = FpdbError('PokerStars')
    FTPErrors         = FpdbError('Full Tilt Poker')
    PartyPokerErrors  = FpdbError('Party Poker')
    BetfairErrors     = FpdbError('Betfair')
    OnGameErrors      = FpdbError('OnGame')
    AbsoluteErrors    = FpdbError('Absolute Poker')
    UltimateBetErrors = FpdbError('Ultimate Bet')
    EverleafErrors    = FpdbError('Everleaf Poker')
    EverestErrors     = FpdbError('Everest Poker')
    CarbonErrors      = FpdbError('Carbon')
    PKRErrors         = FpdbError('PKR')
    iPokerErrors      = FpdbError('iPoker')
    Win2dayErrors     = FpdbError('Win2day')
    WinamaxErrors     = FpdbError('Winamax')

    ErrorsList = [
                    PacificPokerErrors, PokerStarsErrors, FTPErrors, PartyPokerErrors,
                    BetfairErrors, OnGameErrors, AbsoluteErrors,
                    EverleafErrors, CarbonErrors, PKRErrors,
                    iPokerErrors, WinamaxErrors, UltimateBetErrors,
                    Win2dayErrors, EverestErrors,
                ]

    sites = {
                'PacificPoker' : False,
                'PokerStars' : False,
                'Full Tilt Poker' : False,
                'PartyPoker' : False,
                'Betfair' : False,
                'OnGame' : False,
                'Absolute' : False,
                'UltimateBet' : False,
                'Everleaf' : False,
                'Carbon' : False,
                #'PKR' : False,
                'iPoker' : False,
                'Win2day' : False,
                'Winamax' : False,
                'Everest' : False,
            }

    if test_all_sites == True:
        for s in sites:
            sites[s] = True
    else:
        sites[options.sitename] = True

    if sites['PacificPoker'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/PacificPoker/", compare, importer, PacificPokerErrors, "PacificPoker")
    elif sites['PacificPoker'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, PacificPokerErrors, "PacificPoker")

    if sites['PokerStars'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/Stars/", compare, importer, PokerStarsErrors, "PokerStars")
        walk_testfiles("regression-test-files/tour/Stars/", compare, importer, PokerStarsErrors, "PokerStars")
    elif sites['PokerStars'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, PokerStarsErrors, "PokerStars")

    if sites['Full Tilt Poker'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/FTP/", compare, importer, FTPErrors, "Full Tilt Poker")
        walk_testfiles("regression-test-files/tour/FTP/", compare, importer, FTPErrors, "Full Tilt Poker")
    elif sites['Full Tilt Poker'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, FTPErrors, "Full Tilt Poker")
    if sites['PartyPoker'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
        walk_testfiles("regression-test-files/tour/PartyPoker/", compare, importer, PartyPokerErrors, "PartyPoker")
    elif sites['PartyPoker'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, PartyPokerErrors, "PartyPoker")
    if sites['Betfair'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/Betfair/", compare, importer, BetfairErrors, "Betfair")
    elif sites['Betfair'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, BetfairErrors, "Betfair")
    if sites['OnGame'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/OnGame/", compare, importer, OnGameErrors, "OnGame")
        walk_testfiles("regression-test-files/tour/ongame/", compare, importer, OnGameErrors, "OnGame")
    elif sites['OnGame'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, OnGameErrors, "OnGame")
    if sites['Absolute'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/Absolute/", compare, importer, AbsoluteErrors, "Absolute")
        walk_testfiles("regression-test-files/tour/Absolute/", compare, importer, AbsoluteErrors, "Absolute")
    elif sites['Absolute'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, AbsoluteErrors, "Absolute")
    if sites['UltimateBet'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/UltimateBet/", compare, importer, UltimateBetErrors, "Absolute")
    elif sites['UltimateBet'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, UltimateBetErrors, "Absolute")
    if sites['Everleaf'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/Everleaf/", compare, importer, EverleafErrors, "Everleaf")
        walk_testfiles("regression-test-files/tour/Everleaf/", compare, importer, EverleafErrors, "Everleaf")
    elif sites['Everleaf'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, EverleafErrors, "Everleaf")
    if sites['Carbon'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/Carbon/", compare, importer, CarbonErrors, "Carbon")
    elif sites['Carbon'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, CarbonErrors, "Carbon")
    #if sites['PKR'] == True and not single_file_test:
    #    walk_testfiles("regression-test-files/cash/PKR/", compare, importer, PKRErrors, "PKR")
    if sites['iPoker'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/iPoker/", compare, importer, iPokerErrors, "iPoker")
    elif sites['iPoker'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, iPokerErrors, "iPoker")
    if sites['Winamax'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/Winamax/", compare, importer, WinamaxErrors, "Winamax")
        walk_testfiles("regression-test-files/tour/Winamax/", compare, importer, WinamaxErrors, "Winamax")
    elif sites['Winamax'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, WinamaxErrors, "Winamax")
    if sites['Win2day'] == True and not single_file_test:
        walk_testfiles("regression-test-files/cash/Win2day/", compare, importer, Win2dayErrors, "Win2day")
    elif sites['Win2day'] == True and single_file_test:
        walk_testfiles(options.filename, compare, importer, Win2dayErrors, "Win2day")

    totalerrors = 0

    for i, site in enumerate(ErrorsList):
        totalerrors += ErrorsList[i].errorcount

    for i, site in enumerate(ErrorsList):
        ErrorsList[i].print_histogram()

    # Merge the dicts of stats from the various error objects
    statdict = {}
    for i, site in enumerate(ErrorsList):
        tmp = ErrorsList[i].statcount
        for stat in tmp:
            if stat in statdict:
                statdict[stat] += tmp[stat]
            else:
                statdict[stat] = tmp[stat]

    print "\n"
    print "---------------------"
    print "Errors by stat:"
    print "---------------------"
    #for stat in statdict:
    #    print "(%3d) : %s" %(statdict[stat], stat)

    sortedstats = sorted([(value,key) for (key,value) in statdict.items()])
    for num, stat in sortedstats:
        print "(%3d) : %s" %(num, stat)

    print "---------------------"
    print "Total Errors: %d" % totalerrors
    print "---------------------"
Ejemplo n.º 12
0
def main(argv=None):
    """main can also be called in the python interpreter, by supplying the command line as the argument."""
    if argv is None:
        argv = sys.argv[1:]

    def destroy(*args):  # call back for terminating the main eventloop
        gtk.main_quit()

    parser = OptionParser()
    parser.add_option("-f",
                      "--file",
                      dest="filename",
                      metavar="FILE",
                      default=None,
                      help=_("Input file in quiet mode"))
    parser.add_option(
        "-q",
        "--quiet",
        action="store_false",
        dest="gui",
        default=True,
        help=_("don't start gui; deprecated (just give a filename with -f)."))
    parser.add_option(
        "-c",
        "--convert",
        dest="filtername",
        default="PokerStars",
        metavar="FILTER",
        help=
        _("Conversion filter (*Full Tilt Poker, PokerStars, Everleaf, Absolute)"
          ))
    parser.add_option(
        "-x",
        "--failOnError",
        action="store_true",
        default=False,
        help=_(
            "If this option is passed it quits when it encounters any error"))
    parser.add_option(
        "-m",
        "--minPrint",
        "--status",
        dest="minPrint",
        default="0",
        type="int",
        help=
        _("How often to print a one-line status report (0 (default) means never)"
          ))
    parser.add_option("-u",
                      "--usage",
                      action="store_true",
                      dest="usage",
                      default=False,
                      help=_("Print some useful one liners"))
    parser.add_option(
        "-s",
        "--starsarchive",
        action="store_true",
        dest="starsArchive",
        default=False,
        help=
        _("Do the required conversion for Stars Archive format (ie. as provided by support"
          ))
    parser.add_option(
        "-t",
        "--testdata",
        action="store_true",
        dest="testData",
        default=False,
        help=
        _("Output the pprinted version of the HandsPlayer hash for regresion testing"
          ))
    (options, argv) = parser.parse_args(args=argv)

    if options.usage == True:
        #Print usage examples and exit
        print _("USAGE:")
        print _(
            'PokerStars converter: ./GuiBulkImport.py -c PokerStars -f filename'
        )
        print _(
            'Full Tilt  converter: ./GuiBulkImport.py -c "Full Tilt Poker" -f filename'
        )
        print _(
            "Everleaf   converter: ./GuiBulkImport.py -c Everleaf -f filename")
        print _(
            "Absolute   converter: ./GuiBulkImport.py -c Absolute -f filename")
        print _(
            "PartyPoker converter: ./GuiBulkImport.py -c PartyPoker -f filename"
        )
        sys.exit(0)

    config = Configuration.Config()

    settings = {}
    settings['minPrint'] = options.minPrint
    if os.name == 'nt': settings['os'] = 'windows'
    else: settings['os'] = 'linuxmac'

    settings.update(config.get_db_parameters())
    settings.update(config.get_import_parameters())
    settings.update(config.get_default_paths())

    if not options.gui:
        print _('-q is deprecated. Just use "-f filename" instead')
        # This is because -q on its own causes an error, so -f is necessary and sufficient for cmd line use
    if not options.filename:
        i = GuiBulkImport(settings, config)
        main_window = gtk.Window()
        main_window.connect('destroy', destroy)
        main_window.add(i.vbox)
        main_window.show()
        gtk.main()
    else:
        #Do something useful
        importer = fpdb_import.Importer(False, settings, config)
        # importer.setDropIndexes("auto")
        importer.setDropIndexes(_("don't drop"))
        importer.setFailOnError(options.failOnError)
        importer.setThreads(-1)
        importer.addBulkImportImportFileOrDir(os.path.expanduser(
            options.filename),
                                              site=options.filtername)
        importer.setCallHud(False)
        if options.starsArchive:
            importer.setStarsArchive(True)
        if options.testData:
            importer.setPrintTestData(True)
        (stored, dups, partial, errs, ttime) = importer.runImport()
        importer.clearFileList()
        print _('GuiBulkImport done: Stored: %d \tDuplicates: %d \tPartial: %d \tErrors: %d in %s seconds - %.0f/sec')\
                     % (stored, dups, partial, errs, ttime, (stored+0.0) / ttime)