def create_from_id(id_: str, session=None) -> List['PredictedRank']: """ :param id_: Replay id :param session: :return: List of PredictedRanksTable """ if model_holder is None: print("Not using ML, model holder is None.") # raise Exception('ML not loaded for predicted ranks.') game: Game = session.query(Game).filter(Game.hash == id_).first() accepted_playlists = [ 1, # unranked duels 2, # unranked doubles 3, # unranked standard 6, # custom, 10, # ranked duels 11, # doubles 13, # standard 27, # hoops 28, # rumble 29, # dropshot 30, # snow day ] if game.playlist not in accepted_playlists: raise UnsupportedPlaylist playergames = session.query(PlayerGame).filter( PlayerGame.game == id_).all() adjusted_playlist_map = { 1: 10, 10: 10, 2: 11, 11: 11, 3: 13, 6: 13, 13: 13, 27: 27, 28: 28, 29: 29, 30: 30 } playlist = adjusted_playlist_map[game.playlist] if game.playlist == 6 and len(game.players) == 4: playlist = 11 elif game.playlist == 6 and len(game.players) == 2: playlist = 10 if is_local_dev(): import random ranks = [ PredictedRank(pg.player, random.randint(0, 19)) for pg in playergames ] else: ranks = [ PredictedRank(pg.player, model_holder.predict_rank(pg, playlist=playlist)) for pg in playergames ] return ranks
def create_from_id(id_: str, session=None) -> List['PredictedRank']: """ :param id_: Replay id :param session: :return: List of PredictedRanksTable """ if model_holder is None: print("Not using ML, model holder is None.") # raise Exception('ML not loaded for predicted ranks.') game: Game = session.query(Game).filter(Game.hash == id_).first() accepted_playlists = [ 13, # standard 3, # unranked standard 6, # custom ] if game.playlist not in accepted_playlists: raise UnsupportedPlaylist playergames = session.query(PlayerGame).filter(PlayerGame.game == id_).all() if is_local_dev(): import random ranks = [ PredictedRank(pg.player, random.randint(0, 19)) for pg in playergames ] else: ranks = [ PredictedRank(pg.player, model_holder.predict_rank(pg)) for pg in playergames ] return ranks
def get_global_stats_by_rank(self, session, query_filter: QueryFilterBuilder, stats_query, stds_query, player_rank=None, redis=None, ids=None, playlist=13): """ Returns the global stats based on the rank of a player. Does modify the query_filter only setting rank. :param session: Session :param query_filter: a query filter. :param stats_query: A list of global stats :param stds_query: A list of global stats for standard deviations :param player_rank: The player that stats are associated with. Uses unranked if rank is not found :param redis: The local cache :return: """ if ids is None: # Set the correct rank index if player_rank is not None: if isinstance(player_rank, dict) or isinstance(player_rank, list): rank_index = get_rank_tier(player_rank, playlist=playlist) else: rank_index = player_rank else: rank_index = 0 stat_list = self.get_player_stat_list() # Check to see if we have redis available (it usually is) if redis is not None: stat_string = redis.get('global_stats_by_rank') # Check to see if the key exists and if so load it if stat_string is not None: stats_dict = json.loads(stat_string) if playlist is not None: playlist = str(playlist) if playlist not in stats_dict: raise UnsupportedPlaylist(404, 'Playlist does not exist in global stats') stats_dict = stats_dict[playlist] global_stats = [] global_stds = [] for stat in stat_list: if stat.get_field_name() in stats_dict: global_stats.append(stats_dict[stat.get_field_name()][rank_index]['mean']) global_stds.append(stats_dict[stat.get_field_name()][rank_index]['std']) else: global_stats.append(1) global_stds.append(1) return global_stats, global_stds if is_local_dev(): rank_index = 0 stats = self.get_global_stats(session, with_rank=False) global_stats = [stats[stat.get_field_name()][rank_index]['mean'] for stat in stat_list] global_stds = [stats[stat.get_field_name()][rank_index]['std'] for stat in stat_list] return global_stats, global_stds raise CalculatedError(500, "Global stats unavailable or have not been calculated yet.") else: query_filter.clean().with_replay_ids(ids) return (query_filter.with_stat_query(stats_query).build_query(session).first(), query_filter.with_stat_query(stds_query).build_query(session).first())
def ping(session=None): r = get_redis() result = r.get('global_stats') if result is not None: return jsonify({'result': json.loads(result)}) elif is_local_dev(): wrapper = global_stats_wrapper.GlobalStatWrapper() result = wrapper.get_global_stats(sess=session, with_rank=False) return jsonify(result)
def update_self(code): if code != update_code or not is_admin(): raise AuthorizationException() script = os.path.join(BASE_FOLDER, 'update_run.sh') if update_code == 1234 or is_local_dev(): subprocess.call([script, 'test']) else: subprocess.call([script])
def ping(): r = current_app.config['r'] result = r.get('global_stats') if result is not None: return jsonify({'result': json.loads(result)}) elif is_local_dev(): wrapper = global_stats_wrapper.GlobalStatWrapper() session = current_app.config['db']() result = wrapper.get_global_stats(sess=session, with_rank=False) session.close() return jsonify(result)
def create() -> 'LoggedInUser': if is_local_dev(): mock_steam_profile = get_steam_profile_or_random_response( "TESTLOCALUSER")['response']['players'][0] name = mock_steam_profile['personaname'] id_ = mock_steam_profile['steamid'] avatar_link = mock_steam_profile['avatarfull'] return LoggedInUser(name, id_, avatar_link, True, True, True) if g.user is None: raise CalculatedError(404, "User is not logged in.") return LoggedInUser(g.user.platformname, g.user.platformid, g.user.avatar, g.admin, g.alpha, g.beta)
def lookup_current_user(session=None): g.user = None if 'openid' in flask_session: openid = flask_session['openid'] g.user = session.query(Player).filter( Player.platformid == openid).first() if g.user is None: del flask_session['openid'] return redirect('/') g.admin = ids['admin'] in g.user.groups g.alpha = ids['alpha'] in g.user.groups g.beta = ids['beta'] in g.user.groups elif is_local_dev(): g.user = create_default_player(session=session) g.admin = True
def lookup_current_user(session=None): g.user = None if 'openid' in flask_session: openid = flask_session['openid'] if len(ALLOWED_STEAM_ACCOUNTS ) > 0 and openid not in ALLOWED_STEAM_ACCOUNTS: return render_template('login.html') g.user = session.query(Player).filter( Player.platformid == openid).first() if g.user is None: del flask_session['openid'] return redirect('/') g.admin = ids['admin'] in g.user.groups g.alpha = ids['alpha'] in g.user.groups g.beta = ids['beta'] in g.user.groups elif is_local_dev(): g.user = create_default_player(session=session) g.admin = True