def get_net_worth_by_game_profile_id(game_profile_id): gameProfile = GameProfile.get_or_none(GameProfile.id == game_profile_id) if not gameProfile: raise BadRequest('User not in game') netWorth = gameProfile.cash gameProfileCoins = get_game_profile_coins_by_game_profile_id( game_profile_id) for gameProfileCoin in gameProfileCoins: ticker = Ticker.select().where( Ticker.coin == gameProfileCoin.coin).order_by( Ticker.captured_at.desc()) if ticker.count() == 0: raise BadRequest('One coin did not have prices') ticker = ticker.get() if not ticker: raise BadRequest('One coin did not exist') netWorth += ticker.price * gameProfileCoin.coin_amount return netWorth
def get_game_profile_by_profile_id_and_game_id(profile_id, game_id): game_profile = GameProfile.get_or_none(GameProfile.game == game_id, GameProfile.profile == profile_id) if not game_profile: raise BadRequest('User not in game') return game_profile