Beispiel #1
0
def app(request):
    config = copy(Config)
    config.TESTING = True
    config.APP_TYPE = 'admin' if 'admin_api' in request.keywords else 'public'
    app = create_app(config)

    if 'unit' in request.keywords:
        yield app
    else:
        fixtures = Fixtures(app)
        fixtures.setup()
        yield app
        fixtures.teardown()
Beispiel #2
0
def app(request):
    Config.TESTING = True
    app = create_app(Config)

    if 'unit' in request.keywords:
        # unit tests don't get data fixtures
        yield app
    else:
        # other tests need the test data set
        fixtures = Fixtures(app)
        fixtures.setup()
        yield app
        fixtures.teardown()
Beispiel #3
0
def main():
    # initialize instances and print intro.
    #todo: make sure you only print intro (def initalize) once
    database = DatabaseSearcher()
    validate = Validation()
    option = Options()
    initialize()

    #first menu
    print_message("[1] Play a new game\n[2] Continue with a league")

    #get user input from first menu above
    users_pick = get_inputs("Enter choice: ", ['1', '2'])

    # starting new tournament
    if users_pick == '1':
        #create new instance of a tournament, using the database instance
        new_game = Tournament(database=database, new=True)

        #the type of sport to have the option to scale the software
        while True:
            type = new_game.get_type()
            if type in ['Soccer', 'UFC', 'Darts']:
                break
            else:
                print("Stay focused")

        if type == 'Soccer':
            #get all inputs from user
            new_game.get_tournament_name()
            new_game.get_total_players()
            new_game.get_rounds()
            new_game.set_players_name()
            new_game.set_total_games()

            #checks if user wants password in his tournament
            encryption = get_inputs("You want password protection [y/N] ", ['y', 'Y', 'N', 'n', ""])
            if encryption.lower() == "y":
                new_game.get_password()

            # if form returns an emptylist, user doesn't want fixed teams
            # else it a a list of random teams to put in database
            form = new_game.get_form()
            if form == []:
                fixed = False
            else:
                fixed = True

            #from the instance, init total_games and game_counter variables for the playLOOP
            total_games = new_game.total_games
            game_counter = new_game.game_counter

            #database insertion, insert into tournament and insert into sport table
            tournament_id = database.create_new_tournament(name=new_game.name,
                                                total_players=new_game.total_players,
                                                total_rounds=new_game.total_rounds,
                                                password=new_game.password,
                                                namelist=new_game.players_list,
                                                fixed=fixed,
                                                rand_list=form)

            database.add_to_sport_table(type, database.get_newest_id('Tournament'))

            #todo: refactor this part

            #new instance of fixtures
            fixtures = Fixtures(database)

            #generate fixtures as list and then adding to dictionary
            the_fixtures = fixtures.generate_fixture_list(new_game.players_list, new_game.total_rounds)
            fixt_dixt = fixtures.insert_fixture_into_dict(the_fixtures)

            #insert into database
            database.insert_fixtures(the_fixtures, tournament_id)

            #assigning the fixt_dixt to the new_game instance self.fixtures
            new_game.fixtures = fixt_dixt

            #showing all fixtures before tournament starts
            fixtures.show_fixtures(tournament_id=database.get_newest_id('Tournament'))

        elif type == 'UFC':
            freeze_screen(1, "UFC not ready. Application closing ...")
            quit()

        elif type == 'Darts':
            freeze_screen(1, "Darts not ready. Application closing ...")
            quit()

    #below is playing a league that already exists
    elif users_pick == '2':
        freeze_screen(2, "Reading from database ...")
        if database.is_not_empty():
            freeze_screen(2, "No leagues in the database")
            main()
        else:
            print_message("Available leagues:")
            database.print_available_leagues()

        #picking tournament tournament_id from a list
        while True:
            tournament_id = input("Enter the ID for the league you want to play? ")
            if database.get_tournament_by_id(tournament_id):
                name, players, rounds, game_counter = database.get_tournament_by_id(tournament_id)
                type = database.get_type(tournament_id)
                print("LeagueName:", name, "\nTotal Players: ", players, "\nTotal Rounds: ", rounds)
                players_dict = database.get_players_data(tournament_id=tournament_id)
                print(players_dict, "þetta er elísa")
                break

        #password protection
        while True:
            if database.is_password_protected(tournament_id=tournament_id) is True:
                password = input("Enter password: "******"Collecting data from database ...")
                    break
                else:
                    print_message("Incorrect password! Try again!")

            else:
                print("\n\nMaybe you should use a password next time.\n ")
                break


        #create players list

        #setting up new instance of tournament as new.game
        new_game = Tournament(database=database,
                              tournament_id=tournament_id,
                              type=type,
                              name=name,
                              rounds=rounds,
                              players=players,
                              game_counter=game_counter,
                              players_list=None,
                              new=False)

        #inserting into team instances
        new_game.set_players_name(players_dict=players_dict)


        print(LINES)
        print_message(f"WELCOME BACK TO {new_game.name}")
        print(LINES)

        #getting the total games for the play loop
        total_games = new_game.total_games

        # new instance of fixtures
        fixtures = Fixtures(database=database,
                            tournament_id=new_game.tournament_id)


        #generate one list of fixtures from team instances in players list and excludes the day off
        the_fixtures = fixtures.generate_fixture_list(new_game.players_list, new_game.total_rounds)
        fixt_dixt = fixtures.insert_fixture_into_dict(the_fixtures, tournament_id=tournament_id)

        new_game.fixtures = fixt_dixt

        print(new_game.fixtures)

        fixtures.show_fixtures(tournament_id=tournament_id)

    else:
        exit("You don´t deserve us")

    #playing a game with new_game as instance of Tournament
    while game_counter < total_games:
        print(option.show())
        the_option = option.get()
        if validate.limit(the_option, 1, 4) or the_option == "":
            if the_option == '':
                print(LINES)
                home, away = new_game.play_next_game(tournament_id=new_game.tournament_id,
                                                     game_counter=new_game.game_counter)
                print("\n", LINES)

                # getting the score for the game
                while True:
                    score = input("Enter results, two integers with space between: ")
                    if validate.scores(score):
                        score = score.split()
                        a_game = Game(game_counter, score[0], score[1], home, away)
                        score_list = [int(a_game.home_score), int(a_game.away_score)]


                        fixtures.insert_score_to_fixture(score_list, game_counter)
                        database.update_fixture_table(game_id=a_game.id,
                                                      tournament_id=tournament_id,
                                                      home_id=home.id,
                                                      away_id=away.id,
                                                      scores=score_list)
                        a_game.handle_scores()
                        #updating fixtures
                        database.updated_played(tournament_id=tournament_id,
                                                game_id=game_counter)
                        game_counter += 1
                        new_game.game_counter += 1
                        database.update_played_games_in_tournament_by_id(tournament_id=int(new_game.tournament_id)+1,
                                                                         played_games=game_counter)


                        database.update_players_attributes(tournament_id=tournament_id,
                                                           team_id=home.id,
                                                           points=home.points,
                                                           scored=home.scored_goals,
                                                           conceded=home.conceded_goals,
                                                           played=home.played_games)

                        database.update_players_attributes(tournament_id= tournament_id,
                                                           team_id=away.id,
                                                           points=away.points,
                                                           scored=away.scored_goals,
                                                           conceded=away.conceded_goals,
                                                           played=away.played_games)
                        break

            elif the_option == '1':
                print(LINES)
                print(f"           ~~~~~ {new_game.name} ~~~~~")
                print(f'\nYou are playing {new_game.total_rounds} rounds of the following games')
                print(LINES)

                #todo: print only unplayed games or games with scores
                fixtures.show_fixtures(tournament_id=tournament_id)
                print(LINES)
                freeze_screen(2)


            elif the_option == '2':
                print(new_game)
                freeze_screen(2)

            elif the_option == '3':
                print(option.show_stats())
                stat_option = input("Pick your stat: ")

                if stat_option == '1':
                    print(new_game.get_biggest_win())

                elif stat_option == '2':
                    print("Biggest loss(Birnir): X vs Y, 5 - 1.")

                elif stat_option == '3':
                    print("Most games won in a row(Þórarinn): 6")

                else:
                    freeze_screen(2, "NOT AN OPTION")

            elif the_option == '4':
                print("Writing out data...")
                time.sleep(2)
                print("All set! See you soon!")
                exit()

    # the end of the loop, it shows the league standings
    print(new_game)
    print("\n\n\n", LINES)
    print("CONGRATULATIONS\n", end=" ")
    #needs some fine tuning, get the tie, tiebreakers...
    print(new_game.get_winner())


    print("\n\n", LINES)
Beispiel #4
0
if __name__ == '__main__':
    '''Container objects'''

    app.coaches = Coaches2(app)
    app.coaching = Coaching2(app)
    app.teams = Teams(app)
    app.players = Players(app)
    app.countries = Countries(app)
    app.leagues = Leagues(app)
    app.stadiums = Stadiums(app)
    app.officials = Officials(app)
    app.seasons = Seasons2(app)
    app.matches = Matches(app)
    app.statisticsTeam = StatisticsT(app)
    app.statisticsPlayer = StatisticsP(app)
    app.fixtures = Fixtures(app)
    app.squads = Squads(app)
    app.transfers = Transfers(app)

    VCAP_APP_PORT = os.getenv('VCAP_APP_PORT')
    if VCAP_APP_PORT is not None:
        port, debug = int(VCAP_APP_PORT), False
    else:
        port, debug = 5000, True

    VCAP_SERVICES = os.getenv('VCAP_SERVICES')
    if VCAP_SERVICES is not None:
        app.config['dsn'] = get_elephantsql_dsn(VCAP_SERVICES)
    else:
        app.config['dsn'] = """user='******' password='******'
                            host='localhost' port=54321 dbname='itucsdb'"""
Beispiel #5
0
import yaml
from fixtures import Fixtures, ColorGroups
from colorLib import Colors, DynamicColors
import copy


scene = {'00_version': '0.1'}
name = ''
strobe = None

led_bar_01 = Fixtures(dmx_adress =  1, dimmer_channel= 1, strobe_channel = 2, color_group_size = 6, number_of_color_groups = 12, color_groups_start_channel = 3)
led_bar_02 = Fixtures(dmx_adress = 75, dimmer_channel= 1, strobe_channel = 2, color_group_size = 6, number_of_color_groups = 12, color_groups_start_channel = 3)
fogger_01 = Fixtures(dmx_adress = 149, dimmer_channel= 2, strobe_channel = 4, color_group_size = 3, number_of_color_groups = 1, color_groups_start_channel = 5, fog_channel = 1)
fogger_02 = Fixtures(dmx_adress = 156, dimmer_channel= 2, strobe_channel = 4, color_group_size = 3, number_of_color_groups = 1, color_groups_start_channel = 5, fog_channel = 1)

#set overall faders
faders = {led_bar_01.get_dimmer_adress(): {'value': 255, 'type': 'default'},  led_bar_02.get_dimmer_adress(): {'value': 255, 'type': 'default'}}


def main():

    '''static functions'''
    #strobe = 0
    #color1 = Colors('red')
    #color2 = Colors('white_plain')
    #name = set_full_color(color1, strobe, left = True, right = True)       #left and right can be specified optionally
    #name = set_cross_colors(color1, color2, strobe)
    #name = set_top_color(color1, strobe, left = True, right = True)
    #name = set_bottom_color(color1, strobe, left = True, right = True)
    #name = set_rise_color(color1, strobe, rise_number = 2, left = True, right = False)
    #name = set_seconds_colors(color1, color2, strobe)
Beispiel #6
0
    def __init__(self,
                 database,
                 tournament_id=None,
                 type=None,
                 name=None,
                 rounds=None,
                 players=None,
                 game_counter=None,
                 players_list=None,
                 new=False):
        self.database = database

        if tournament_id is None:
            self.tournament_id = self.database.get_newest_id('Tournament')
        else:
            self.tournament_id = tournament_id

        if type:
            self.type = type
        else:
            self.type = ""

        if name:
            self.name = name
        else:
            self.name = ""

        if rounds:
            self.total_rounds = rounds
        else:
            self.total_rounds = 0

        if players:
            self.total_players = players
        else:
            self.total_players = 0

        if game_counter:
            self.game_counter = game_counter
        else:
            self.game_counter = 0

        if players_list:
            self.players_list = players_list
            for team in players_list:
                self.player = Team(team.name, team.points, team.played_games,
                                   team.scored_goals, team.conceded_goals)
        else:
            self.players_list = []

        self.total_games = self.set_total_games()

        self.password = None
        self.options = Options()
        self.validate = Validation()

        if new:
            self.fixtures = Fixtures(database)
        else:
            self.fixtures = self.get_fixtures_from_db()

        self.randomlist = [
            'Real Madrid', 'Barcelona', 'Liverpool', 'Iceland', 'Brazil',
            'PSG', '1 star', '2 star', 'Spain', '3 star', '4 star',
            'Lowest star', 'Everton', 'Chelsea', 'Basel', 'Manchester City',
            'IcelanderTeam', 'Manchester United', 'Arsenal', 'Leicester',
            'Ajax', 'Atletico Madrid', 'Tottenham', 'Bayern Munchen',
            'B. Dortmund', 'Juventus', 'Roma', 'Inter Milan', 'Colombia',
            'England', 'Sweden', 'Scandinavia', 'Italy', 'Burnley', 'Sevilla'
        ]