コード例 #1
0
ファイル: round.py プロジェクト: ABKorotky/chess
 def make_games(self):
     for game_data in self.games_data:
         game = Game(tournament=self.tournament, round=self.tournament.current_round + 1)
         game.save()
         game.gameresult_set.add(GameResult(player_id=game_data[0]), GameResult(player_id=game_data[1]))
     for tech_game_data in self.technical_games_data:
         tech_game = TechnicalGameResult(tournament=self.tournament, round=self.tournament.current_round + 1, player_id=tech_game_data)
         tech_game.save()
コード例 #2
0
    def _create_games(afl_match_ups, legends_match_ups, game_index=1):
        """
            Create games for each match up.
        """

        for afl_game, legends_game in zip(afl_match_ups, legends_match_ups):
            args = {
                'afl_away': afl_game[1],
                'afl_home': afl_game[0],
                'finals_game': game_index,
                'legends_away': legends_game[1],
                'legends_home': legends_game[0],
                'round': rnd,
                'status': 'Scheduled',
                'ground': ground
            }
            game = Game(**args)
            game.save()

            game_index += 1
コード例 #3
0
ファイル: populate.py プロジェクト: Servesus/CosasAII
def populateGames():
    print("Loading games...")
        
    with open(path+"\\steam.csv", encoding="utf8") as csv_file:
        csv_reader = list(csv.reader(csv_file, delimiter=','))
        #count = len(csv_reader)
        count = 5000
        for i in range(1, count):
            row = csv_reader[i]
            tags = []
            g = Game(idGame=row[0], name=row[1])
            g.save()
            g.tags.clear()
            tagNames = row[10].split(';')
            for t in tagNames:
                tag, _ = Tag.objects.get_or_create(name=t)
                tags.append(tag)

            g.tags.set(tags)
            g.save()
            print("Added game " + str(i) + "/" + str(count))
    
    print("Games inserted: " + str(Game.objects.count()))
    print("Tags inserted: " + str(Tag.objects.count()))
    print("---------------------------------------------------------")
コード例 #4
0
ファイル: views.py プロジェクト: ejucovy/mvsim
def games_index(request):
    sections = CourseSection.objects.filter(users=request.user, 
                                            course=request.course)
    try:
        section = sections[0]
    except IndexError:
        section = CourseSection.objects.filter(course=request.course)[0]
        section.users.add(request.user)
        section.save()

    if request.method == "POST":
        state = section.starting_states.get(
            id=request.POST['starting_state_id'])
        game = Game.initialize_from_state(
            user=request.user,
            configuration=Configuration.objects.get(pk=1),
            user_input=UserInput.objects.get(pk=1),
            course=request.course,
            starting_state=state)
        return redirect(game.show_game_url())

    games = Game.objects.filter(user=request.user,
                                course=request.course)
    return {'games': games, 'section': section}
コード例 #5
0
def seed():
    """Seeds the database with dummy data"""
    print("Seeding the database")

    # ------------------- #
    # --- RANDOM DATA --- #
    # ------------------- #

    random_data = {

        # Descriptions
        'descriptions': [
            'Nullam sit amet ex volutpat, accumsan ex eu, ullamcorper libero. Nunc libero sapien, volutpat at ex a, vulputate viverra sem. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aenean quis efficitur arcu',
            'Nullam molestie dapibus libero volutpat viverra. Etiam sit amet nulla leo.',
            'Etiam velit tortor, venenatis a leo commodo, feugiat scelerisque erat. Curabitur sed dui ac urna congue vestibulum vitae ut enim. Quisque at tellus finibus orci pretium laoreet.',
            'Quisque vulputate eros nisi, ut fermentum tellus lobortis eget',
            'Etiam vel mi vitae magna congue malesuada.'
        ],

        # Users
        'users': [],

        # Users
        'games':
        ['Tic-Tac-Toe', 'Guess the word', 'Whack-A-Mole', 'Pong', 'Othello'],
        'game_ids': [],
    }

    # ------------------ #
    # --- SEED USERS --- #
    # ------------------ #

    # Loop 25 times
    for i in range(125, 150):

        # Generate random description
        random_description = random_data['descriptions'][random.randint(
            0,
            len(random_data['descriptions']) - 1)]

        # Create a random User
        user = User(username='******'.format(i),
                    picture_url='via.placeholder.com/100x100',
                    description=random_description)
        # Use the hash_password() method on the User object (Model)
        user.hash_password('password{0}'.format(i))

        # Add the user to the database
        db.session.add(user)
        db.session.commit()

        # Add the user to the users list
        random_data['users'].append(user)

    # ------------------ #
    # --- SEED GAMES --- #
    # ------------------ #

    # Loop random_data['games'] size times
    for i in range(0, len(random_data['games'])):

        # Generate random description
        random_description = random_data['descriptions'][random.randint(
            0,
            len(random_data['descriptions']) - 1)]

        # Create a random Game
        game = Game(name=random_data['games'][i],
                    description=random_description)

        # Add the game to the database
        db.session.add(game)
        db.session.commit()

        # Add the user to the users list
        random_data['game_ids'].append(game.id)

    # ------------------------ #
    # --- SEED FRIENDSHIPS --- #
    # ------------------------ #

    # Loop 50 times
    for i in range(0, 50):

        # The same user can never befriend itself so if id1 and id2 are the same, keep looping
        same_id = True
        while same_id:
            # Generate random user id's
            random_user_id1 = random_data['users'][random.randint(
                0,
                len(random_data['users']) - 1)].id
            random_user_id2 = random_data['users'][random.randint(
                0,
                len(random_data['users']) - 1)].id

            # If the id's are different OR if the random_user_id1 is empty
            if random_user_id1 != random_user_id2 or random_user_id1 == None:
                same_id = False

        # Create a random Friendship
        friendship = Friendship(user_id_1=random_user_id1,
                                user_id_2=random_user_id2)

        # Add the friendship to the database
        db.session.add(friendship)
        db.session.commit()

    # ------------------------- #
    # --- SEED ACHIEVEMENTS --- #
    # ------------------------- #

    for i in range(0, 50):

        # Generate a random game id & description
        random_description = random_data['descriptions'][random.randint(
            0,
            len(random_data['descriptions']) - 1)]
        random_game_id = random_data['game_ids'][random.randint(
            0,
            len(random_data['game_ids']) - 1)]

        # Create a random Achievement
        achievement = Achievement(name='Achievement {0}'.format(i),
                                  description=random_description,
                                  game_id=random_game_id)

        # Add the friendship to the database
        db.session.add(achievement)
        db.session.commit()

    print("Done seeding the database")