Пример #1
0
def get_results(url):
    # get response from url
    tables = []
    while len(tables) < index_min:
        # print(len(tables), end=' ')
        driver = webdriver.Chrome()
        driver.get(url)
        time.sleep(3)
        # driver.implicitly_wait(3)
        soup = BeautifulSoup(driver.page_source, 'lxml')
        tables = soup.find_all('table')
    # print(len(tables))

    # get race info per race
    info_panel = tables[1]
    info = list(map(lambda x: x.get_text(), info_panel.find_all('td')))
    race_info = {
        'tag': info[6],
        'name': info[9],
        'cond': info[7] + ' ' + info[8],
        'track': info[10] + ' ' + info[11]
    }
    # -------------------------
    # input and process results
    # -------------------------
    index = index_min
    table_results = make_list(tables[index_min])
    # try out the index of the awards table
    while len(table_results) == 0 or len(
            table_results[0]) == 0 or table_results[0][0] != "名次":
        index = index + 1
        table_results = make_list(tables[index])
    # filter valid rows
    table_results = list(filter(lambda x: len(x) > 10, table_results))
    for i, row in enumerate(table_results):
        if i == 0: continue
        # join the section positions into 1 slot
        table_results[i] = row

    # -----------------------------
    # input and process award rates
    # -----------------------------
    index = index_min
    table_awards = make_list(tables[index_min])
    # try out the index of the awards table
    while len(table_awards) == 0 or len(
            table_awards[0]) == 0 or table_awards[0][0] != "派彩":
        index = index + 1
        table_awards = make_list(tables[index])
    # process the awards table
    table_awards = table_awards[1:]
    for i, row in reversed(list(enumerate(table_awards))):
        if i == 0: continue
        if util.is_even(len(row)):
            table_awards[i - 1] += row
    table_awards = list(
        map(lambda x: [x[0], list(zip(x[1::2], x[2::2]))],
            list(filter(lambda x: not util.is_even(len(x)), table_awards))))
    # print_table(table_awards)
    return race_info, table_results, table_awards
Пример #2
0
    def find_target(self):
        """
        This method calculates the next move.
        Call it, if the walker is currently not moving
        """

        # Follows the potential if not in orientation phase.
        # Otherwise it tries to follow it's given initial direction.
        if self.orientation_time:
            target_dir = self.direction
        else:
            pot = self.grid.potentials[self.potential_name][tuple(self.pos)]
            target_dir = pot["d"]

        target_dir, target_pos = self.try_cell(target_dir)

        # here we have the following situation:
        # target_dir is either a direction or Direction.NONE
        # target_pos is either a valid position or None
        # both is okay, because moving to None simply means not moving.

        # after the loop, (target_dir, target_pos) either contains a valid direction-position-pair
        # or (Direction.NONE, None) which is both okay
        self.target = target_pos

        # if we have a target
        if target_pos is not None:
            assert self.grid.is_empty(target_pos)
            self.remaining = NONDIAG_COST if is_even(target_dir) else DIAG_COST

            if self.grid[self.target] == Cell.EMPTY:
                # only reserve, if the target cell is empty, otherwise
                # (in case of target cell) do nothing
                self.grid[self.target] = Cell.RESERVED
Пример #3
0
 def test_is_even(self):
     self.assertEqual(util.is_even(0), True)
     self.assertEqual(util.is_even(1), False)
     self.assertEqual(util.is_even(2), True)
     self.assertEqual(util.is_even(3), False)
     self.assertEqual(util.is_even(100), True)
     self.assertEqual(util.is_even(101), False)