Ejemplo n.º 1
0
def get_concentration(driver, url):
    """Gets concentration from url"""
    soup = uf.get_soup(url)
    res = []

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

    #: getting list of matches lost recently
    history = []
    for i in soup.findAll(attrs={'class': "match__team__tournirs"}):
        history.append(i)
    loses = []
    for cnt, i in zip(range(len(names)), history):
        loses.append(get_loses(names[cnt], i))

    #: getting last lose to loser
    losers_loses = [0, 0]
    for team, cnt in zip(loses, range(2)):
        for match in team:
            statto = uf.get_statto_soup(driver, match['date'])
            teams = [uf.championat_statto[names[cnt]], uf.championat_statto[match['rival']]]
            statto_info = uf.get_statto_teams_info(teams[0], teams[1], statto)[:2]
            if uf.get_statto_teams_pos_diff(statto_info[0], statto_info[1]) < -7:
                losers_loses[cnt] = 6 - match['total'] + match['match']

    #: getting answer
    coef = [1 - x / 5 for x in losers_loses]
    res += coef
    return res
Ejemplo n.º 2
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
def get_form(url):
    """Gets teams and their forms from url"""
    soup = uf.get_soup(url)
    res = []

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

    # : counting form
    history = []
    for i in soup.findAll(
            attrs={'class': re.compile('(_win)|(_tie)|(_lose)')}):
        history.append(i['class'])
    if len(history) < 10:
        return None
    elif len(history) < 12:
        start1 = 0
        start2 = 5
    else:
        start1 = 1
        start2 = 7
    form1 = 0
    form2 = 0
    for i in range(start1, start1 + 5):
        if history[i] == ['_win']:
            form1 += 2
        elif history[i] == ['_tie']:
            form1 += 1
    for i in range(start2, start2 + 5):
        if history[i] == ['_win']:
            form2 += 2
        elif history[i] == ['_tie']:
            form2 += 1
    form1 /= 10
    form2 /= 10
    res = res + [form1] + [form2]

    #: adding result
    res += uf.get_results(soup)

    return res
def get_form(url):
    """Gets teams and their forms from url"""
    soup = uf.get_soup(url)
    res = []

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

    # : counting form
    history = []
    for i in soup.findAll(attrs={"class": re.compile("(_win)|(_tie)|(_lose)")}):
        history.append(i["class"])
    if len(history) < 10:
        return None
    elif len(history) < 12:
        start1 = 0
        start2 = 5
    else:
        start1 = 1
        start2 = 7
    form1 = 0
    form2 = 0
    for i in range(start1, start1 + 5):
        if history[i] == ["_win"]:
            form1 += 2
        elif history[i] == ["_tie"]:
            form1 += 1
    for i in range(start2, start2 + 5):
        if history[i] == ["_win"]:
            form2 += 2
        elif history[i] == ["_tie"]:
            form2 += 1
    form1 /= 10
    form2 /= 10
    res = res + [form1] + [form2]

    #: adding result
    res += uf.get_results(soup)

    return res