Example #1
0
def get_goal_pos_diff(driver, url):
    """Getting score and difference"""
    res = []
    soup = uf.get_soup(url)

    #: getting match date and team names
    date = uf.get_date(soup)
    teams = uf.get_names(soup)
    res += teams

    #: moving to statto url
    statto = uf.get_statto_soup(driver, date)
    statto_teams = [uf.championat_statto[x] for x in teams]

    #: getting teams goal_diff and score_diff
    values = [0, 0]
    values[0], values[1], first, last, first_goals, last_goals = \
        uf.get_statto_teams_info(statto_teams[0], statto_teams[1], statto)

    #: getting actual numbers from string values
    for i in range(len(values)):
        values[i] = get_values(values[i])
    first = get_values(first)
    last = get_values(last)
    first_goals = get_values(first_goals)
    last_goals = get_values(last_goals)

    #: counting result
    goal_diff = 0.5 + (values[0][0] - values[1][0]) / (2 * (first_goals[0] - last_goals[0]))
    pos_diff = 0.5 + (values[0][1] - values[1][1]) / (2 * (first[1] - last[1]))

    res += [goal_diff, pos_diff]
    return res
def get_motivation(url, driver):
    """Getting motivation for the match"""
    soup = uf.get_soup(url)
    res = []

    #: adding names
    res += uf.get_names(soup)
    teams = res

    #: magic with names and derbies
    for i in {0, 1}:
        if res[i] in derbies and res[1 - i] in derbies[res[i]]:
            res = res + [1, 1]
            return res

    #: season end or start
    tour = uf.get_tour_number(soup)
    if tour > 33:
        res += [1, 1]
        return res
    if tour < 16:
        res += [0, 0]
        return res

    #: moving to statto
    date = uf.get_date(soup)
    statto = uf.get_statto_soup(driver, date)
    statto_all = statto.findAll('form')[1].findAll('tr')
    statto_teams = [uf.championat_statto[x] for x in teams]

    #: getting teams scores and key positions points
    info = uf.get_statto_teams_info(statto_teams[0], statto_teams[1], statto)
    team1_score = uf.get_statto_score(info[0])
    team2_score = uf.get_statto_score(info[1])
    key_pos_scores = get_key_pos_scores(statto_all)

    #: getting min distance to key position for each team
    dist1 = min(
        list(
            filter(lambda x: x,
                   [abs(x - team1_score) for x in key_pos_scores])))
    dist2 = min(
        list(
            filter(lambda x: x,
                   [abs(x - team2_score) for x in key_pos_scores])))

    #: finally getting res
    left = TOURS - tour
    val = 1 - (dist1 / 3) / left
    if val < 0 or val > 1:
        res.append(0)
    else:
        res.append(val)
    val = 1 - (dist2 / 3) / left
    if val < 0 or val > 1:
        res.append(0)
    else:
        res.append(val)
    return res
def get_motivation(url, driver):
    """Getting motivation for the match"""
    soup = uf.get_soup(url)
    res = []

    #: adding names
    res += uf.get_names(soup)
    teams = res

    #: magic with names and derbies
    for i in {0, 1}:
        if res[i] in derbies and res[1 - i] in derbies[res[i]]:
            res = res + [1, 1]
            return res

    #: season end or start
    tour = uf.get_tour_number(soup)
    if tour > 33:
        res += [1, 1]
        return res
    if tour < 16:
        res += [0, 0]
        return res

    #: moving to statto
    date = uf.get_date(soup)
    statto = uf.get_statto_soup(driver, date)
    statto_all = statto.findAll('form')[1].findAll('tr')
    statto_teams = [uf.championat_statto[x] for x in teams]

    #: getting teams scores and key positions points
    info = uf.get_statto_teams_info(statto_teams[0], statto_teams[1], statto)
    team1_score = uf.get_statto_score(info[0])
    team2_score = uf.get_statto_score(info[1])
    key_pos_scores = get_key_pos_scores(statto_all)

    #: getting min distance to key position for each team
    dist1 = min(list(filter(lambda x: x, [abs(x - team1_score) for x in key_pos_scores])))
    dist2 = min(list(filter(lambda x: x, [abs(x - team2_score) for x in key_pos_scores])))

    #: finally getting res
    left = TOURS - tour
    val = 1 - (dist1 / 3) / left
    if val < 0 or val > 1:
        res.append(0)
    else:
        res.append(val)
    val = 1 - (dist2 / 3) / left
    if val < 0 or val > 1:
        res.append(0)
    else:
        res.append(val)
    return res