예제 #1
0
파일: v1.py 프로젝트: raziqraif/fortune
def up(db):
    with db.atomic():
        migrator = PostgresqlMigrator(db)
        db.bind(MODELS, bind_refs=False, bind_backrefs=False)
        db.create_tables(MODELS)
        if Coin.get_or_none(Coin.id == 1) is None:
            Coin.create(name='Bitcoin', symbol='BTC')
            Coin.create(name='Ethereum', symbol='ETH')
            Coin.create(name='Litecoin', symbol='LTC')
            Coin.create(name='Coin 3', symbol='CO3')
            Coin.create(name='Coin 4', symbol='CO4')
            Coin.create(name='Coin 5', symbol='CO5')

        global_indef = Game.create(name='Global Indefinite',
                                   starting_cash=10000.00,
                                   shareable_link='INDEF',
                                   shareable_code='INDEF',
                                   ends_at=None)

        # insert achievements into database
        Achievement.create(
            name="Win", description="Finish in first place in a private game")
        Achievement.create(
            name="Double net worth",
            description="Achieved by doubling your net worth in a game")
        Achievement.create(name="Identity Crisis",
                           description="Change your username")

        # insert goals into database
        Goal.create(name="Entrepreneur", description="Create a private game")

        all_coins = Coin.select()
        for coin in all_coins:
            GameCoin.create(game=global_indef, coin=coin)

        global_timed = Game.create(name='Global Timed',
                                   starting_cash=10000.00,
                                   shareable_link='TIMED',
                                   shareable_code='TIMED',
                                   ends_at=datetime.utcnow() +
                                   timedelta(minutes=1))
        # CHANGEME for devel purposes, making it 1 min for now
        GameCoin.create(game=global_timed, coin=Coin.get())

        # from auth.services import register
        hashed = bcrypt.hashpw("admin".encode(), bcrypt.gensalt()).decode()
        admin = Profile.create(username="******",
                               hashed_password=hashed,
                               is_admin=True)
        # Required so that admin can still view graphs in the landing page
        GameProfile.create(profile=admin, game=global_indef, cash=0.0)
예제 #2
0
 def setUp(self):
     super().setUp()
     with db.atomic() as txn:
         #don't need to create a game, migrations/v1.py gets run before every test
         #Coin.create(id=1, name='Bitcoin', symbol='BTC')
         Game.create(name='Game',
                     starting_cash=10000.00,
                     shareable_link='aaaabbbbccccdddd',
                     shareable_code='aaaa',
                     ends_at=(datetime.utcnow().replace(tzinfo=pytz.utc) +
                              timedelta(days=7)).isoformat())
         profile = Profile.create(username='******',
                                  hashed_password='******')
         self.token = AuthToken.create(profile=profile,
                                       token='thevalidtoken').token
예제 #3
0
def create_game(log, platform: str, category: str, name: str, gist_file: GistFile) -> bool:
    # Проверяем, что игры с такой категорией нет в базе
    game = Game.get_or_none(name=name, platform=platform, category=category)
    if game:
        return False

    finish_datetime = None

    # Если игра уже добавлена как завершенная
    if is_finished(category):
        finish_datetime = gist_file.committed_at

    log.info(f'Added {name!r} ({platform} / {category})')
    Game.create(
        name=name,
        platform=platform,
        category=category,
        append_datetime=gist_file.committed_at,
        finish_datetime=finish_datetime,
    )

    return True
예제 #4
0
def create_game(name, starting_cash, shareable_link, shareable_code, ends_at,
                active_coins, profile):
    # bounds check, validate
    if ends_at < datetime.utcnow().replace(tzinfo=pytz.utc):
        raise BadRequest('Invalid game ending date')
    if starting_cash <= Decimal(0):
        raise BadRequest('Starting cash must be positive')
    game = Game.create(
        name=name,
        starting_cash=starting_cash,
        shareable_link=shareable_link,
        shareable_code=shareable_code,
        ends_at=ends_at,
    )
    create_gamecoins_for_game(game, active_coins)
    GameProfile.create(
        game=game,
        profile=profile,
        cash=game.starting_cash,
    )
    return game
예제 #5
0
 def setUp(self):
     super().setUp()
     with db.atomic() as txn:
         self.game = Game.create(
             name='Game',
             starting_cash=10000.00,
             shareable_link='aaaabbbbccccdddd',
             shareable_code='aaaa',
             ends_at=(datetime.utcnow().replace(tzinfo=pytz.utc) +
                      timedelta(days=7)).isoformat())
         profile = Profile.create(username='******',
                                  hashed_password='******')
         GameProfile.create(game=self.game, profile=profile, cash=-1.0)
         Message.create(
             game=self.game.id,
             profile=profile.id,
             content="first message",
             # use default value for created_on
         )
         self.token = AuthToken.create(profile=profile,
                                       token='thevalidtoken').token
예제 #6
0
def check_global_timed_game():
    game = Game.get(Game.shareable_link == 'TIMED')
    if game.ends_at < datetime.utcnow():
        # end global timed game, and start another
        profiles = []
        for game_profile in GameProfile.select().where(GameProfile.game == game):
            profiles.append(game_profile.profile)
            send_notification(game_profile.profile, 'The global timed game has expired')
            game_profile.delete_instance(recursive=True)
        game.delete_instance(recursive=True)
        global_timed = Game.create(name='Global Timed',
                        starting_cash=10000.00,
                        shareable_link='TIMED',
                        shareable_code='TIMED',
                        ends_at=datetime.utcnow() + timedelta(minutes=1))
        # CHANGEME for devel purposes, making it 1 min for now
        GameCoin.create(game=global_timed, coin=Coin.get())
        for profile in profiles:
            GameProfile.create(
                game=global_timed,
                profile=profile,
                cash=global_timed.starting_cash
            )
예제 #7
0
 def handle(self):
     self.redirect("/play/%s" % Game.create().gameId)