示例#1
0
文件: train.py 项目: fortes23/xadrez
def calc_fitness(individual):
    fitness = 0

    json_file = os.path.dirname(os.path.realpath(__file__)) + '/test.json'
    with open(json_file, 'w') as fp:
        json.dump(individual, fp, ensure_ascii=False)

    bot1 = os.path.dirname(os.path.realpath(__file__)) + '/xouba.py'
    bot2 = os.path.dirname(os.path.realpath(__file__)) + '/../stockfishbot.py'
    # bot3 = os.path.dirname(os.path.realpath(__file__)) + '/../randombot.py'

    p1 = Pool(bot1=[bot1, '-j', json_file], bot2=[bot2], debug=True)
    p2 = Pool(bot1=[bot1, '-j', json_file], bot2=[bot2, '-l', '2'], debug=True)
    # p2 = Pool(bot1=[bot1, '-j', json_file], bot2=bot2, debug=True)
    # p3 = Pool(bot1=[bot1, '-j', json_file], bot2=bot3, debug=True)

    matches = [p1, p2]

    for p in matches:
        for _ in range(15):
            p.match()
            if p.last_result == p.RESULT_WIN_WHITE:
                fitness += 5
            elif p.last_result == p.RESULT_DRAW:
                fitness += 1
            p.reset_chess_board()
        del p

    return fitness
示例#2
0
    def get_blockchain_info(self):
        try:
            data = {'pool': Pool(self.pool_id_or_sym, invert=self.invert)}
            data['pool_object'] = data['pool']['object']
            data['pool_name'] = Asset(data['pool_object']['share_asset']).symbol
            data['asset_x'] = Asset(data['pool_object']['asset_a'])
            data['asset_y'] = Asset(data['pool_object']['asset_b'])
            data['amount_x'] = Amount(int(data['pool_object']['balance_a'])/10**data['asset_x'].precision, data['asset_x'])
            data['amount_y'] = Amount(int(data['pool_object']['balance_b'])/10**data['asset_y'].precision, data['asset_y'])
            self.amount_x = data['amount_x']
            self.amount_y = data['amount_y']
            data['market_ticker_object'] = Market(
                # python bitshares reverses base and quote
                base=data['asset_y'],
                quote=data['asset_x']
                ).ticker()
            data['market_orderbook'] = Market(
                base=data['asset_y'],
                quote=data['asset_x']
                ).orderbook(50)
            data['pool_invariant'] = int(data['pool_object']['virtual_value'])/(10**(data['asset_x'].precision + data['asset_y'].precision))
            #print(f"Invariant: {data['pool_invariant']}")

            # python bitshares reverses base and quote
            data['price_xy'] = Price(base=data['amount_y'], quote=data['amount_x'])
            data['price_yx'] = Price(base=data['amount_x'], quote=data['amount_y'])

            pub.sendMessage('update_gui', data=data)
        except Exception as err:
            print('Invalid pool selected. Error: {}'.format(err))
            pub.sendMessage('invalid_pool')
示例#3
0
def bestchallenge_comics():
    logger = logging.getLogger(__name__ + '.bestchallenge_comics')
    url_format = BESTCHALLENGE_LIST_URL + '?page={0}'
    last_url = url_format.format(999999)
    with urlfetch.fetch(last_url, cache, 120) as f:
        html = lxml.html.parse(f)
    logger.info(last_url)
    last = html.xpath('//*[@id="content"]//*[contains(concat(" ", @class,'
                      '" "), " paginate ")]//strong[@class="page"]/em/text()')
    last_html = html
    last = int(last[0])

    def get_html(page):
        if page == last:
            return last_html
        url = url_format.format(page)
        with urlfetch.fetch(url, cache, 120) as f:
            logger.info(url)
            html = lxml.html.parse(f)
        return html

    pool = Pool(POOL_SIZE)
    htmls = pool.map(get_html, xrange(1, last + 1))
    for html in htmls:
        links = html.xpath('//*[@id="content"]//table[@class="challengeList"]'
                           '//td/*[@class="fl"]/a')
        for a in links:
            href = a.attrib['href']
            query = href[href.index('?') + 1:]
            title_id = int(werkzeug.urls.url_decode(query)['titleId'])
            yield title_id, a.xpath('./img/@title')[0]
示例#4
0
    def __init__(self, pool_path, dfs_site=constants.dk, lineups=[]):
        self.dfs_site = DFS_Site(dfs_site)
        self.pool = Pool(pool_path)
        self.lineups = lineups
        self.memoized = {}

        self.start_logging()
示例#5
0
class Root(RestController):
    config = Config()
    crush = Crush()
    doc = Doc()
    mon = Mon()
    osd = Osd()
    pool = Pool()
    request = Request()
    server = Server()

    @expose(template='json')
    def get(self, **kwargs):
        """
        Show the basic information for the REST API
        This includes values like api version or auth method
        """
        return {
            'api_version':
            1,
            'auth':
            'Use "ceph tell mgr restful create_key <key>" to create a key pair, '
            'pass it as HTTP Basic auth to authenticate',
            'doc':
            'See /doc endpoint',
            'info':
            "Ceph Manager RESTful API server",
        }
示例#6
0
 def _given_pool_of_size(self, size: int):
     self.pool: Pool[int] = Pool(
         source=MockSource(),
         mutator=MockMutator(),
         evaluator=MockEvaluator(),
         size=size,
     )
示例#7
0
    def __init__(self, layer):
        """Creates renderer for provided map layer.

        :param layer: The image.
        :type layer: layer.Layer

        :param concurrent: The number of tiles to render concurrently.
        :type concurrent: int
        """
        self.max_zoom = 22
        self.size = 256
        self.buffer_size = 128

        if layer.concurrent:
            pool_size = multiprocessing.cpu_count()
        else:
            pool_size = 1
        self.pool = Pool(layer, map_size=self.size, pool_size=pool_size)

        map = mapnik.Map(256, 256, '+init=epsg:3857')
        layer.append_to(map)
        map.zoom_all()
        self.envelope = map.envelope()

        self.empty_tile = mapnik.Image(self.size, self.size)
        self.mercator = SphericalMercator(levels=self.max_zoom + 1, size=self.size)
示例#8
0
文件: job.py 项目: talaniz/peloton
    def __init__(
        self,
        job_file="test_job.yaml",
        client=None,
        config=None,
        pool=None,
        job_config=None,
        options=[],
        job_id=None,
    ):

        self.config = config or IntegrationTestConfig()
        self.client = client or Client()
        self.pool = pool or Pool(self.config, self.client)
        self.job_id = job_id
        if job_config is None:
            job_config_dump = load_test_config(job_file)
            job_config = job.JobConfig()
            json_format.ParseDict(job_config_dump, job_config)

        # apply options
        for o in options:
            o(job_config)

        self.job_config = job_config
示例#9
0
    def process(self, url):
        """ Downloads all requested files from specified server """
        self.ignored = 0
        self.not_selected = 0
        self.processed = 0

        api = API(url, self.user, self.password)

        if self.recording_id:
            recording = api.get(self.recording_id).get("recording")
            self._download(recording, api, Path(self.out_folder))
            return
        print("Querying server {0}".format(url))
        print("Limit is {0}".format(self.limit))
        print("Tag mode {0}".format(self.tag_mode))
        print("Dates are {0} - {1}".format(self.start_date, self.end_date))
        print("Required tags are {0}".format(self.only_tags))
        print("Ignore tags are {0}".format(self.ignore_tags))

        rows = api.query(
            limit=self.limit,
            startDate=self.start_date,
            endDate=self.end_date,
            tagmode=self.tag_mode,
            tags=self.only_tags,
        )

        if self.auto_delete:
            self.update_file_locations()

        pool = Pool(self.workers, self._downloader, api, Path(self.out_folder))
        for row in rows:
            pool.put(row)
        pool.stop()
示例#10
0
def test_pool():
    pool = Pool(5)
    logging.debug('queueing work')
    for i in range(10):
        pool.add_task(test, i)
    logging.debug('starting work')
    pool.start_workers(True)
    logging.debug('waiting')
    sleep(5)
    for result in pool.results():
        logging.debug('got result %s', str(result))
    logging.debug('cancel unstarted workers')
    pool.abort()
    logging.debug('waiting and restarting')
    pool.start_workers(True)
    logging.debug('restarted waiting for results')
    wait_for_results(pool)
    logging.debug('adding additional workers')
    for i in range(10, 15):
        pool.add_task(test, i)
    wait_for_results(pool)

    pool.done()

    """
示例#11
0
文件: execution.py 项目: runtimejs/v8
 def _RunInternal(self, jobs):
     pool = Pool(jobs)
     test_map = {}
     # TODO(machenbach): Instead of filling the queue completely before
     # pool.imap_unordered, make this a generator that already starts testing
     # while the queue is filled.
     queue = []
     queued_exception = None
     for test in sorted(self.tests, key=lambda t: t.duration, reverse=True):
         assert test.id >= 0
         test_map[test.id] = test
         try:
             command = self.GetCommand(test)
         except Exception, e:
             # If this failed, save the exception and re-raise it later (after
             # all other tests have had a chance to run).
             queued_exception = e
             continue
         timeout = self.context.timeout
         if ("--stress-opt" in test.flags
                 or "--stress-opt" in self.context.mode_flags
                 or "--stress-opt" in self.context.extra_flags):
             timeout *= 4
         if test.dependency is not None:
             dep_command = [
                 c.replace(test.path, test.dependency) for c in command
             ]
         else:
             dep_command = None
         job = Job(command, dep_command, test.id, timeout,
                   self.context.verbose)
         queue.append([job])
示例#12
0
    def __init__(
        self,
        job_file="test_stateless_job_spec.yaml",
        client=None,
        config=None,
        pool=None,
        job_config=None,
        job_id=None,
    ):

        self.config = config or IntegrationTestConfig(
            pool_file='test_stateless_respool.yaml')
        self.client = client or Client()
        self.pool = pool or Pool(self.config, client=self.client)
        self.job_id = job_id
        self.entity_version = None
        self.job_spec = None

        if job_config is not None:
            self.job_spec = job_config

        if job_id is not None:
            self.job_spec = self.get_spec()

        if self.job_spec is None:
            job_spec_dump = load_test_config(job_file)
            job_spec = stateless.JobSpec()
            json_format.ParseDict(job_spec_dump, job_spec)
            self.job_spec = job_spec
示例#13
0
文件: f5-cli.py 项目: zemmali/f5-cli
def get_object_connection(obj, connection, partition, parser):
    """
        get an object specific connection

        @param obj - the object type
        @param connection - the f5 connection to use
        @param partition - the partition to work with
        @param parser - our args parser for object specifc items

    """
    if obj == "pool":
        object_connection = Pool(connection, partition, parser)
    elif obj == "node":
        object_connection = Node(connection, partition, parser)
    elif obj == "virtual_server":
        object_connection = Virtual_server(connection, partition, parser)
    elif obj == "ssl_file":
        object_connection = Ssl_file(connection, partition, parser)
    elif obj == "ssl_profile":
        object_connection = Ssl_profile(connection, partition, parser)
    elif obj == "profile":
        object_connection = Profile(connection, partition, parser)
    else:
        raise Exception("Unknown object {}".format(obj))
    return object_connection
示例#14
0
    def __init__(self, job,
                 updated_job_file=None,
                 client=None,
                 config=None,
                 pool=None,
                 batch_size=None,
                 updated_job_spec=None,
                 roll_back_on_failure=None,
                 max_instance_attempts=None,
                 max_failure_instances=None,
                 start_paused=None,
                 ):

        self.config = config or IntegrationTestConfig()
        self.client = client or Client()
        self.pool = pool or Pool(self.config)
        if updated_job_spec is None:
            job_config_dump = load_test_config(updated_job_file)
            updated_job_spec = JobSpec()
            json_format.ParseDict(job_config_dump, updated_job_spec)
        self.updated_job_spec = updated_job_spec
        self.batch_size = batch_size or 0
        self.roll_back_on_failure = roll_back_on_failure or False
        self.max_instance_attempts = max_instance_attempts or 0
        self.max_failure_instances = max_failure_instances or 0
        self.start_paused = start_paused or False
        self.job = job
示例#15
0
    def create_pool(self, miner):
        """
        miner - instance of Miner that is creating a pool
        """
        assert isinstance(miner, Miner)

        miner.pool = Pool(miner)
        self.P.append(miner.pool)
示例#16
0
 def __insertPools(self):
     teamCount = 1
     interval = self.__getTeamLst(0)
     for i in range(self.__pools):
         tmpPool = Pool()
         tmpPool.createSchedule(self.__games, interval[i], teamCount)
         self.poolBracket.append(tmpPool)
         teamCount += interval[i]
示例#17
0
    def parse(self, diceString):
        def raiseValueError():
            raise ValueError("Invalid diceString value: {0}".format(diceString))

        if not diceString: raiseValueError()
        
        match = re.match(r"(\d*)d(\d+)([\+\-]\d+)?\s*(?:\(([\+\-]?\d+)\))?", diceString.strip())

        if not match: raiseValueError()

        dice, sides, modifier, showing = match.groups()

        sides = int(sides)

        if not dice: dice = 1
        else: dice = int(dice)

        if not modifier: modifier = 0
        else: modifier = int(modifier)


        if showing:
            showing = int(showing)

            if showing > sides * dice + modifier:
                raiseValueError()

            if showing < dice + modifier:
                raiseValueError()

            if sides > 1:
                numberAtMax = (showing - modifier - dice) / (sides - 1)
                remainder = (showing - modifier) - (numberAtMax * sides) - (dice - numberAtMax - 1)

                def getShowing(index):
                    if index < numberAtMax:
                        return sides
                    if index == numberAtMax:
                        return remainder
                    return 1

                return Pool([Die(sides=int(sides),
                    showing=getShowing(index)) for index in range(dice)], modifier=modifier, rolled=True)


        return Pool([Die(sides=int(sides)) for d in range(dice)], modifier=modifier)
示例#18
0
 def __init__(self, gameClass, opponents, rW, nWorkers=1, nSeeds=None):
     self._pool = Pool([EvalWorker(gameClass, opponents, rW) for _ in range(nWorkers)])
     self._pool.start()
     if nSeeds is not None:
         self._seeds = np.random.randint(np.iinfo(np.int32).max, size=(nSeeds,))
     else:
         self._seeds = [None]
     self._nSeeds = len(self._seeds)
def search(keywords):
    pool = Pool()
    while pool.pool:
        for name, pos in pool.items():
            if matchKey(getSoup(name, pos).text, keywords):
                print(getRootUrl(name, post))
            next_pos = getNextPos(name, pos)
            pool.update(name, next_pos)
示例#20
0
def read_csv_file(file_name):
    pools = []
    with open(file_name, 'r') as file:
        reader = csv.reader(file)

        for row in reader:
            pools.append(Pool(row[0], int(row[1]), int(row[2])))

    return pools
示例#21
0
def fullPool(spec):
    """Creates a pool and fills it with the world drawn from the provided specification, before returning it."""
    pool = Pool()

    data = sampleWorld(spec)
    for pair in data:
        pool.store(pair[0], pair[1])

    return pool
示例#22
0
def respool(request, pool_file):
    pool = Pool(config=IntegrationTestConfig(pool_file=pool_file))

    # teardown
    def delete_pool():
        pool.delete()

    request.addfinalizer(delete_pool)
    return pool
示例#23
0
 def testAdd(self):
     results = set()
     pool = Pool(3)
     for result in pool.imap_unordered(Run, [[x] for x in range(0, 10)]):
         results.add(result.value)
         if result.value < 30:
             pool.add([result.value + 20])
     self.assertEquals(set(range(0, 10) + range(20, 30) + range(40, 50)),
                       results)
示例#24
0
 def testException(self):
   results = set()
   pool = Pool(3)
   for result in pool.imap_unordered(Run, [[x] for x in range(0, 12)]):
     # Item 10 will not appear in results due to an internal exception.
     results.add(result)
   expect = set(range(0, 12))
   expect.remove(10)
   self.assertEquals(expect, results)
示例#25
0
def get_html(url):
    pool = Pool()
    proxies = pool.pool()
    headers={'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'}
    while True:
        try:
            req=requests.get(url,headers=headers, proxies = proxies, timeout=5)
            req.encoding='UTF-8'
            return html_str_util.filter_tags(req.text) 
        except requests.exceptions.RequestException:
            pass
示例#26
0
 def __init__(self, app, **kwargs):
     self.app = app or self.app
     super(Guard, self).init(**kwargs)
     self.rpc_server = PyroServer(GUARD_PORT)
     self.rpc_client = PyroClient(self.app.conf['HUB_IP'], HUB_PORT)
     self.pool = Pool(self.app)
     self.machine = Machine(healthy_mock=app.conf['HEALTHY_MOCK'],
                            labels=self.labels)
     self.__shutdown_guard = threading.Event()
     self.LOOP_INTERVAL = 10  # second
     self.alive = False
示例#27
0
 def __init__(self, sub, loo):
     self.sub = sub
     self.loo = loo
     self.data_file = './sub{}/pca_loo_tr{}'.format(self.sub, self.loo)
     self.data = pd.read_pickle(self.data_file)
     self.data_val = pd.read_pickle(self.data_file)
     self.costs = pd.Series(np.ones(32))
     self.pool = Pool(POOL_SIZE)  # 1.000.000
     self.env = Environment(self.data, self.costs, FEATURE_FACTOR)
     self.brain = Brain(self.pool)
     self.agent = Agent(self.env, self.pool, self.brain)
     self.log = Log(self.data_val, self.costs, FEATURE_FACTOR, self.brain)
示例#28
0
文件: pools.py 项目: rcespa/minotaur
  def load_config(self):
    for pool_name in Config().get('pools').keys():
      if Config().get('pools.%s.enable' % (pool_name)):
        try:
          self.pools[pool_name] = eval("%s.%s()" % (pool_name, pool_name.title()))
        except NameError:
          self.pools[pool_name] = Pool(pool_name)

        self.pools[pool_name].refresh_data()

    if len(self.pools) == 0:
      Log().add('fatal', 'no pools enabled - the config file format for pools has changed, please see minotaur.conf.example')
示例#29
0
    def _ReturnConnection(self):
        """
		Returns a connection back to the pool
		
		@author: Nick Verbeck
		@since: 9/7/2008
		"""
        if self.conn is not None:
            if self.connInfo.commitOnEnd is True or self.commitOnEnd is True:
                self.conn.Commit()

            Pool().returnConnection(self.conn)
            self.conn = None
示例#30
0
def run(IP, PORT):
    # Simulated "event queue"
    eventQueue = deque()
    
    # Process queue used for async rpc system.
    processQ = Queue()
    sessionManager = MasterSessionManager(IP, PORT, processQ)
    rpcManager = RPCManager(sessionManager, processQ)
    containerAllocator = RMContainerAllocator(eventQueue, sessionManager)
    committerEventHandler = CommitterEventHandler(eventQueue)
    printed = False;
    serverList = []
    assignedServers = []
    serverAssignments = defaultdict(list)
    
    pool = Pool()
    
    job = Job(work, pool, rpcManager, eventQueue)
    
    # Simulate Delayed Job init and start.
    eventQueue.append(("JOB_INIT", job))
    eventQueue.append(("JOB_START", job))
    
    while True:
        # Simulate "event delivery"
        containerAllocator.pushNewEvents(eventQueue)
        committerEventHandler.pushNewEvents(eventQueue)
        pool.pushNewEvents(eventQueue)
        eventQueue.clear()
        
        # Simulate async mechanisums
        sessionManager.poll()
        rpcManager.poll()
        containerAllocator.heartbeat()
        committerEventHandler.heartbeat()
        
        # For server failure
        for locator in serverList:
            if (locator not in sessionManager.serverList()):
                eventQueue.append(("JOB_UPDATED_NODES", locator))
        if serverList != sessionManager.serverList():
            print "serverList change"
        serverList = sessionManager.serverList()
    
        # Run tasks
        pool.poll()

        if job.getStatus() == "SUCCEEDED" and not printed:
            print "Job Complete"
            print job
            printed = True