Пример #1
0
 def create_tournament(cls, attrs):
     """Create the tournament in database
     attrs are the attributes collected by the view
     """
     id = Tournament.set_tournament_id()
     attrs["id"] = id
     Tournament.create(attrs)
Пример #2
0
 def get_player_info(cls, player_choice=None):
     """send either informations about every players of the data base
     If the player_choice is not specified, all players in database are returned
     If the player_choice is specified with its id it only returns the concerned one
      """
     if not player_choice:
         players = Tournament.get_all_players()
         return players
     player_info = Tournament.get_player_info(player_choice)
     return player_info
Пример #3
0
async def update_tournament(tournament_id: int,
                            tournament: TournamentIn_Pydantic,
                            user: User = Depends(
                                fastapi_users.get_current_active_user)):
    await Tournament.filter(id=tournament_id
                            ).update(**tournament.dict(exclude_unset=True))
    return await Tournament_Pydantic.from_queryset_single(
        Tournament.get(id=tournament_id))
Пример #4
0
 def set_tour_results(cls,
                      matchs_results,
                      round_id,
                      tournament_id_user_choice,
                      match_id,
                      player_one_score=None,
                      player_two_score=None):
     """Allowes to register a round result
     matchs_results is a list of matches
     round_id is the concerned round
     tournament_id_user_choice is the concerned tournament
     match_id is the id of a match in the round
     player_one_score/player_two_score are the resuls of the match refered by match_id
     """
     Tournament.enter_results(tournament_id_user_choice, round_id, match_id,
                              player_one_score, player_two_score,
                              matchs_results)
     Tournament.save_results(matchs_results, round_id,
                             tournament_id_user_choice)
Пример #5
0
 def get_report(cls,
                choice=0,
                tournament_choice=None,
                sorting=None,
                round_choice=None,
                choosing=None):
     """Return informations about a required subject
     5 kind of reports are possible:
             - All players in database sorted alphabetically or by rank
             - The list of all tournaments in database
             - The list of player in a tournament sorted alphabetically or by rank
             - The list of played and ongoing rounds in a tournament
             - The list of games in a round for a specified tournament
     """
     return Tournament.get_report(choice, tournament_choice, sorting,
                                  round_choice, choosing)
Пример #6
0
    db_session.add(facility_2)
    db_session.add(facility_3)
    db_session.commit()
    # -------------------- CREATE TOURNAMENTS --------------------
    mylogger.info("Creating default tournaments...")
    week_period = datetime.timedelta(weeks=1)
    day_period = datetime.timedelta(days=1)

    tournament_1 = Tournament(
        created_at=datetime.datetime(2020, 1, 1, 0, 1, 1),
        name="Torneig de Matats",
        start_register_date=datetime.datetime.now() - (week_period * 3),
        finish_register_date=datetime.datetime.now() - (week_period * 1),
        start_date=datetime.datetime.now() + (week_period * 1),
        finish_date=datetime.datetime.now() + (week_period * 2),
        price_1=20,
        price_2=8,
        description=
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam libero ex, rhoncus non lectus sit amet, tincidunt scelerisque nulla. Curabitur aliquet justo non facilisis volutpat. Vestibulum suscipit odio leo, sed rutrum erat euismod sollicitudin. Quisque nisi massa, volutpat ut faucibus eget, accumsan et ligula. Pellentesque vestibulum, nisi non dapibus auctor, tellus magna tempor leo, volutpat ullamcorper eros sem vel quam. Phasellus ullamcorper sem ut arcu eleifend, eget euismod nibh viverra. Nulla facilisi. Suspendisse sed sem et eros faucibus lacinia. Duis rhoncus ante laoreet ante ultrices consectetur. Suspendisse bibendum varius velit, sed viverra dui porttitor sed. In pulvinar lectus et leo porttitor interdum. Phasellus hendrerit ac lorem eget euismod. Quisque posuere et dui sit amet fringilla. Curabitur malesuada convallis mauris. Sed malesuada quis neque quis vehicula. Suspendisse viverra mi quis tortor pharetra fermentum.",
        type=TournamentTypeEnum.draft,
        inscription_type=TournamentPrivacyTypeEnum.public,
        facility_id=1,
        categories=[cat_1, cat_2, cat_3],
        owner_id=1)

    tournament_2 = Tournament(
        created_at=datetime.datetime(2020, 1, 1, 0, 1, 1),
        name="Torneig de Matats 2",
        start_register_date=datetime.datetime.now() + (week_period * 3),
        finish_register_date=datetime.datetime.now() + (week_period * 4),
        start_date=datetime.datetime.now() + (week_period * 5),
        finish_date=datetime.datetime.now() + (week_period * 6),
Пример #7
0
### test lol
from scraper.methods import get_player_name
from methods import get_player_representation, get_pvp_representation, get_vector
from db.models import Tournament, Match
from sklearn.externals import joblib
from model.help import removed_keys
from model.train_nn import make_keras
import numpy as np

tournament = Tournament()
tournament.week = 1
tournament.year = 2019
tournament.country = "ENG"
start_date = 6
end_date = 10
name = "ONEX ALL ENGLAND OPEN BADMINTON CHAMPIONSHIPS 2019"
prizemoney = 1000000
city = "BIRMINGHAM"
url = "https://bwfworldtour.bwfbadminton.com/tournament/3376/yonex-all-england-open-badminton-championships-2019/"

clf = joblib.load('data/dnn.pkl')


def dopred(p1_name, p2_name, round_no):
    match = Match()
    match.tournament = tournament
    match.round_no = round_no

    try:
        p1_name = p1_name.lower()
        p2_name = p2_name.lower()
Пример #8
0
async def get_tournament():
    tournament = Tournament.all()
    return await Tournament_Pydantic.from_queryset(tournament)
Пример #9
0
 def get_game_list(cls, tournament_id):
     """Return the games list of the ongoing round for the specified tournament"""
     return Tournament.get_game_list(tournament_id)
Пример #10
0
 def set_player_elo(cls, player, new_elo):
     """Allows the user to update a player's elo
     It takes the id of the player and the new value as arguments
     """
     Tournament.change_player_elo(player, new_elo)
Пример #11
0
 def get_provisional_ranking(cls, tournament_id_user_choice):
     """Used to send the ranking of a tournament
     It returns a sorted by tournament_score list for the wished tournament
     """
     players = Tournament.get_players(tournament_id_user_choice)
     return players
Пример #12
0
 def generate_tour(cls, tournament_id_user_choice):
     """Generate a new round for an ongoing tournament
     The wished tournament is entered with the attribute tournament_id_user_choice
     """
     round = Tournament.generate_round(tournament_id_user_choice)
     return round
Пример #13
0
 def create_player(cls, attrs):
     """Create a new player in database
     attrs are the attributes collected by the view"""
     id = Tournament.set_player_id()
     attrs["id"] = id
     Player.create(attrs)
Пример #14
0
import sys
from scraper.methods import get_player_name
from methods import get_player_representation, get_pvp_representation
from db.models import Tournament
import pprint

p1_name = "Viktor Axelsen".lower()
p2_name = "Lin Dan".lower()

tournament = Tournament()
tournament.week = 1
tournament.country = "den"

p1 = get_player_name(p1_name)
p2 = get_player_name(p2_name)

p1_model = get_player_representation(p1, tournament)
p2_model = get_player_representation(p2, tournament)

rep = get_pvp_representation(p1_model, p2_model)

pp = pprint.PrettyPrinter()
pp.pprint(rep)
Пример #15
0
def make_scrape_page(year):
    url = make_url(year)

    r = requests.get(url, verify=False)
    soup = BeautifulSoup(r.content, "html.parser")

    rows = soup.findAll("tr")

    for tr in rows[1:]:
        tds = tr.findAll("td")

        week = tds[0].contents[0].strip()

        try:
            country = tds[1].findChildren()[0].findChildren(
            )[0].contents[0].strip()
        except IndexError:
            continue

        dates = tds[2].contents[0].strip()
        name = tds[3].findChildren()[0].findChildren()[0].contents[0].strip()
        url = tds[3].findChildren()[0].findChildren()[0].attrs['href']
        money = tds[4].findChildren()[0].contents[0].strip()

        if not "bwfbadminton.com" in url:
            continue

        if money == "-":
            prizemoney = 0
        else:
            prizemoney = int(re.sub(r'[^\d.]', '', money))

        category = tds[5].findChildren()[0].findChildren(
        )[0].contents[0].strip()
        city = tds[6].findChildren()[0].contents[0].strip()

        tours = db.query(Tournament).filter(Tournament.name == name,
                                            Tournament.year == year).all()
        has_tournament = len(tours) > 0

        if has_tournament:
            continue

        t = Tournament()
        t.week = week
        t.start_date = dates.split("-")[0]
        t.end_date = dates.split("-")[1]
        t.name = name
        t.url = url
        t.country = country
        t.prizemoney = prizemoney
        t.category = category
        t.city = city
        t.year = year

        print "new tournament", t.name
        print t.url

        def go(t):

            try:
                make_scrape_tournament(t)
            except requests.exceptions.SSLError:
                print "bwfbadminton.com is down 1"
                return False
            except requests.exceptions.ConnectionError:
                # does not exist
                print "bad connection"
                return False
            except Exception as e:
                # e.g., timeout ...

                print "<<<<TRY AGAIN>>>>>"
                traceback.print_exc()

                # try again
                return go(t)

            return True

        success = go(t)
        if success:
            db.add(t)
            db.commit()
        else:
            db.rollback()