Ejemplo n.º 1
0
def viewnetworkscores() -> Response:
    # Only load the last 100 results for the initial fetch, so we can render faster
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    network_scores = frontend.get_network_scores(limit=100)
    if len(network_scores['attempts']) > 10:
        network_scores['attempts'] = frontend.round_to_ten(
            network_scores['attempts'])

    return render_react(
        'Global MÚSECA Scores',
        'museca/scores.react.js',
        {
            'attempts': network_scores['attempts'],
            'songs': frontend.get_all_songs(),
            'players': network_scores['players'],
            'shownames': True,
            'shownewrecords': False,
        },
        {
            'refresh': url_for('museca_pages.listnetworkscores'),
            'player': url_for('museca_pages.viewplayer', userid=-1),
            'individual_score': url_for('museca_pages.viewtopscores',
                                        musicid=-1),
        },
    )
Ejemplo n.º 2
0
def listplayer(userid: UserID) -> Dict[str, Any]:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    info = frontend.get_all_player_info([userid])[userid]

    return {
        'player': info,
    }
Ejemplo n.º 3
0
def viewnetworkrecords() -> Response:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    network_records = frontend.get_network_records()
    versions = {
        version: name
        for (game, version, name) in frontend.all_games()
    }
    versions[0] = 'CS and Licenses'

    return render_react(
        'Global MÚSECA Records',
        'museca/records.react.js',
        {
            'records': network_records['records'],
            'songs': frontend.get_all_songs(),
            'players': network_records['players'],
            'versions': versions,
            'shownames': True,
            'showpersonalsort': False,
            'filterempty': False,
        },
        {
            'refresh': url_for('museca_pages.listnetworkrecords'),
            'player': url_for('museca_pages.viewplayer', userid=-1),
            'individual_score': url_for('museca_pages.viewtopscores',
                                        musicid=-1),
        },
    )
Ejemplo n.º 4
0
 def preload(cls, data: Data, config: Dict[str, Any]) -> None:
     cache = Cache(app,
                   config={
                       'CACHE_TYPE': 'filesystem',
                       'CACHE_DIR': config['cache_dir'],
                   })
     frontend = MusecaFrontend(data, config, cache)
     frontend.get_all_songs(force_db_load=True)
Ejemplo n.º 5
0
def viewplayers() -> Response:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    return render_react(
        'All MÚSECA Players',
        'museca/allplayers.react.js',
        {'players': frontend.get_all_players()},
        {
            'refresh': url_for('museca_pages.listplayers'),
            'player': url_for('museca_pages.viewplayer', userid=-1),
        },
    )
Ejemplo n.º 6
0
def viewtopscores(musicid: int) -> Response:
    # We just want to find the latest mix that this song exists in
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    versions = sorted(
        [version for (game, version, name) in frontend.all_games()],
        reverse=True,
    )
    name = None
    artist = None
    difficulties = [0, 0, 0, 0, 0]

    for version in versions:
        for omniadd in [0, 10000]:
            for chart in [0, 1, 2, 3, 4]:
                details = g.data.local.music.get_song(GameConstants.MUSECA,
                                                      version + omniadd,
                                                      musicid, chart)
                if details is not None:
                    if name is None:
                        name = details.name
                    if artist is None:
                        artist = details.artist
                    if difficulties[chart] == 0:
                        difficulties[chart] = details.data.get_int(
                            'difficulty')

    if name is None:
        # Not a real song!
        abort(404)

    top_scores = frontend.get_top_scores(musicid)

    return render_react(
        f'Top MÚSECA Scores for {artist} - {name}',
        'museca/topscores.react.js',
        {
            'name': name,
            'artist': artist,
            'difficulties': difficulties,
            'players': top_scores['players'],
            'topscores': top_scores['topscores'],
        },
        {
            'refresh': url_for('museca_pages.listtopscores', musicid=musicid),
            'player': url_for('museca_pages.viewplayer', userid=-1),
        },
    )
Ejemplo n.º 7
0
def viewsettings() -> Response:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    userid = g.userID
    info = frontend.get_all_player_info([userid])[userid]
    if not info:
        abort(404)

    return render_react(
        'MÚSECA Game Settings',
        'museca/settings.react.js',
        {
            'player': info,
            'versions':
            {version: name
             for (game, version, name) in frontend.all_games()},
        },
        {
            'updatename': url_for('museca_pages.updatename'),
        },
    )
Ejemplo n.º 8
0
def viewscores(userid: UserID) -> Response:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    info = frontend.get_latest_player_info([userid]).get(userid)
    if info is None:
        abort(404)

    scores = frontend.get_scores(userid, limit=100)
    if len(scores) > 10:
        scores = frontend.round_to_ten(scores)

    return render_react(
        f'{info["name"]}\'s MÚSECA Scores',
        'museca/scores.react.js',
        {
            'attempts': scores,
            'songs': frontend.get_all_songs(),
            'players': {},
            'shownames': False,
            'shownewrecords': True,
        },
        {
            'refresh': url_for('museca_pages.listscores', userid=userid),
            'player': url_for('museca_pages.viewplayer', userid=-1),
            'individual_score': url_for('museca_pages.viewtopscores',
                                        musicid=-1),
        },
    )
Ejemplo n.º 9
0
def viewrecords(userid: UserID) -> Response:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    info = frontend.get_latest_player_info([userid]).get(userid)
    if info is None:
        abort(404)
    versions = {
        version: name
        for (game, version, name) in frontend.all_games()
    }

    return render_react(
        f'{info["name"]}\'s MÚSECA Records',
        'museca/records.react.js',
        {
            'records': frontend.get_records(userid),
            'songs': frontend.get_all_songs(),
            'players': {},
            'versions': versions,
            'shownames': False,
            'showpersonalsort': True,
            'filterempty': True,
        },
        {
            'refresh': url_for('museca_pages.listrecords', userid=userid),
            'player': url_for('museca_pages.viewplayer', userid=-1),
            'individual_score': url_for('museca_pages.viewtopscores',
                                        musicid=-1),
        },
    )
Ejemplo n.º 10
0
def viewplayer(userid: UserID) -> Response:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    info = frontend.get_all_player_info([userid])[userid]
    if not info:
        abort(404)
    latest_version = sorted(info.keys(), reverse=True)[0]

    return render_react(
        f'{info[latest_version]["name"]}\'s MÚSECA Profile',
        'museca/player.react.js',
        {
            'playerid': userid,
            'own_profile': userid == g.userID,
            'player': info,
            'versions':
            {version: name
             for (game, version, name) in frontend.all_games()},
        },
        {
            'refresh': url_for('museca_pages.listplayer', userid=userid),
            'records': url_for('museca_pages.viewrecords', userid=userid),
            'scores': url_for('museca_pages.viewscores', userid=userid),
        },
    )
Ejemplo n.º 11
0
def listscores(userid: UserID) -> Dict[str, Any]:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    return {
        'attempts': frontend.get_scores(userid),
        'players': {},
    }
Ejemplo n.º 12
0
def listnetworkscores() -> Dict[str, Any]:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    return frontend.get_network_scores()
Ejemplo n.º 13
0
def listplayers() -> Dict[str, Any]:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    return {
        'players': frontend.get_all_players(),
    }
Ejemplo n.º 14
0
def listtopscores(musicid: int) -> Dict[str, Any]:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    return frontend.get_top_scores(musicid)
Ejemplo n.º 15
0
def listrecords(userid: UserID) -> Dict[str, Any]:
    frontend = MusecaFrontend(g.data, g.config, g.cache)
    return {
        'records': frontend.get_records(userid),
        'players': {},
    }