def fansiteTest():
    args = fansiteConfig.getArgs()
    print args
    simulators = loadSimulators()

    simulator = None
    if args.simulator in simulators:
        simulator = simulators[args.simulator]()
    else:
        print ("Unsupported simulator: " + args.simulator)
        return

    version = simulator.getVersion()

    if args.test:
        args.numSims = 1000
        args.runForever = 0

    print ("Using %s version %s with %s sims per deck" % (simulator.name, version, args.numSims))

    if not args.test:
        print ("Requesting session id...")
        sessId = startSession(args.token, version)
        if sessId is None:
            print ("No session started.")
            return
        print (" ... started session with id " + sessId)

    while 1:
        print ("Getting decks...")
        if not args.test:
            json_data = fansiteHttp.getDecks(sessId, args.limit)
            decks = json_data["decks"]
        else:
            decks = testRepo.loadTests(True)
        print (" ... " + str(len(decks)) + " decks retrieved")

        for deck in decks:
            deckId = deck["deckId"]
            try:
                results = simDeck(simulator, deck, args)
                if results is None:
                    print (" ... no result, skipped")
                if not args.test:
                    print (" ... result: %(wins)s/%(total)s, anp=%(anp)s, time=%(time)s" % results)
                    json_data = fansiteHttp.submitSimulation(
                        deckId, sessId, results["total"], results["wins"], results["time"], results["anp"]
                    )
                else:
                    testRepo.testKey(deck, "winrate", 100 * int(results["wins"]) / int(results["total"]))
                    testRepo.testKey(deck, "drawrate", 100 * int(results["draws"]) / int(results["total"]))
                    testRepo.testKey(deck, "lossrate", 100 * int(results["losses"]) / int(results["total"]))
            except NotImplementedError, e:
                print ("Error: Not Implemented: %s" % e)
            except Exception, e:
                traceback.print_exc()
def fansiteTest():
    args = fansiteConfig.getArgs()
    print args
    simulators = loadSimulators()

    if hasattr(args, 'proxy'):
        import urllib2
        urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler({'http': args.proxy})))
    simulator = None
    if(args.simulator in simulators):
        simulator = simulators[args.simulator]()
    else:
        print("Unsupported simulator: " + args.simulator)
        return

    version = simulator.getVersion()

    if(args.test):
        args.numSims = 1000
        args.runForever = 0

    print("Using %s version %s with %s sims per deck" % (simulator.name, version, args.numSims))

    if(not args.test):
        print("Requesting session id...")
        sessId = startSession(args.token, version)
        if(sessId is None):
            print("No session started.")
            return
        print(" ... started session with id " + sessId)

    while 1:
        print("Getting decks...")
        if(not args.test):
            json_data = fansiteHttp.getDecks(sessId, args.limit)
            decks = json_data["decks"]
        else:
            decks = testRepo.loadTests(False)
        print(" ... " + str(len(decks)) + " decks retrieved")

        for deck in decks:
            deckId = deck["deckId"]
            try:
                results = simDeck(simulator, deck, args)
                if results is None:
                    print(" ... no result, skipped")
                if not args.test:
                    if(results.has_key("ard")):
                        print(" ... result: %(wins)s/%(total)s, ard=%(ard)s, time=%(time)s" % results)
                    else:
                        print(" ... result: %(wins)s/%(total)s, time=%(time)s" % results)
                    json_data = fansiteHttp.submitSimulation(deckId, sessId, results["total"], results["wins"], results["time"], results.get("ard"))
                else:
                    testRepo.testKey(deck, "winrate", 100 * int(results["wins"]) / int(results["total"] if(results.get("wins") is not None) else None))
                    testRepo.testKey(deck, "drawrate", 100 * int(results["draws"]) / int(results["total"] if(results.get("draws") is not None) else None))
                    testRepo.testKey(deck, "lossrate", 100 * int(results["losses"]) / int(results["total"] if(results.get("losses") is not None) else None))
                    testRepo.testKey(deck, "ard", float(results["ard"]) if(results.get("ard") is not None) else None, 5)
            except NotImplementedError, e:
                print("Error: Not Implemented: %s" % e)
            except Exception, e:
                traceback.print_exc()