Пример #1
0
def get_coins_by_game_id(game_id):
    coins_query = Coin.select().join(GameCoin).where(GameCoin.game == game_id)
    if coins_query.count() == 0:
        raise BadRequest('Coins not found')
    coins = []
    for coin in coins_query:
        coins.append(coin)
    return coins
Пример #2
0
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)
Пример #3
0
 def test_get_coins_success(self):
     profile = Profile.get_or_none(Profile.username == 'theusername')
     GameProfile.create(game=1, profile=profile, cash=10000)
     GameCoin.create(
         game=1,
         coin=1,
     )
     for coin in Coin.select():
         Ticker.create(
             coin=coin,
             price=30.0,
             captured_at=(datetime.utcnow()).isoformat(),
             price_change_day_pct=1.1,
         )
     res = self.client.get(
         '/game/1/coins?timeSpan=1&sortBy=0&numPerPage=10&pageNum=1',
         headers={'Authorization': 'Bearer ' + self.token})
     self.assertEqual(int(HTTPStatus.OK), res._status_code)
Пример #4
0
def begin(cb=None):
    env = os.environ['FLASK_ENV']
    if env == 'testing':
        # TODO stubbed implementation
        return
    elif env == 'development':
        if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
            return
        while True:
            coins = Coin.select()
            tickers = list(stubbed(*coins))
            if cb is not None:
                cb(tickers)
            time.sleep(WAIT)
    elif env == 'production':
        while True:
            tickers = list(ping('BTC', 'ETH', 'LTC'))
            if cb is not None: cb(tickers)
            time.sleep(WAIT)
Пример #5
0
def get_coins_by_game_id_and_sorting(game_id, sorting_int, page_num,
                                     num_per_page):
    coins_query = Coin.select().join(GameCoin).where(GameCoin.game == game_id)
    if coins_query.count() == 0:
        raise BadRequest('Incorrect Sorting')
    if sorting_int == 1:
        coins_query = coins_query.order_by(+Coin.name)
    if sorting_int == 2:
        coins_query = coins_query.order_by(-Coin.name)
    if sorting_int == 3:
        coins_query = coins_query.order_by(
            -Coin.price)  # TODO: Double check if this should +/-
    if sorting_int == 4:
        coins_query = coins_query.order_by(
            +Coin.price)  # TODO: Double check if this should +/-

    coins_query = coins_query.paginate(page_num, num_per_page)
    coins = []
    for coin in coins_query:
        coins.append(coin)
    return coins
Пример #6
0
def get_coins():
    return jsonify(CoinsResponse.serialize(Coin.select(), many=True))