Exemple #1
0
def ranks(context={}, gametype=None):
    context = {}
    context['page'] = 'ranks'
    context['ranks'] = rank.ranks
    context['fullserverstatus'] = twms.get_server_info()
    if context['fullserverstatus']:
        context['playernames'] = ", ".join([x['name'] for x in context['fullserverstatus']['players']])
        context['gametype'] = context['fullserverstatus']['gametype']

    return context
Exemple #2
0
def item_stats(context={}, gametype=None):
    #if not item in kill_mapping.keys() + pickup_mapping.keys():
    #    return "bad item"

    context['page'] = 'items'
    context['items'] = []
    context['fullserverstatus'] = twms.get_server_info()
    if context['fullserverstatus']:
        context['playernames'] = ", ".join([x['name'] for x in context['fullserverstatus']['players']])
        context['gametype'] = context['fullserverstatus']['gametype']


    context['itemlist'] = ['heart', 'shield', 'hammer', 'gun', 
             'shotgun', 'grenade', 'laser', 'ninja',]
    for item in context['itemlist']:
        context['items'].append(get_item_stats(item))
    return context
Exemple #3
0
    def wrapper(*args, **kwargs):
        # Pre-traitement
        context = {}
        session = request.environ.get("beaker.session")
        # Get gametype
        gametype = session.get("gametype", None)
        context["selected_gametype"] = gametype
        # Get server status
        context["fullserverstatus"] = twms.get_server_info()
        if context["fullserverstatus"]:
            context["playernames"] = ", ".join([x["name"] for x in context["fullserverstatus"]["players"]])
            context["gametype"] = context["fullserverstatus"]["gametype"]

        # Set args
        kwargs["context"] = context
        kwargs["gametype"] = gametype
        response = func(*args, **kwargs)
        # Post-traitement
        return response
Exemple #4
0
def index(context={}, gametype=None):
    context['page'] = 'home'
    context['server_alive'] = twms.is_alive()
    context['fullserverstatus'] = twms.get_server_info()
    
    # Get score
    stats_by_players = get_stats(selected_gametype=gametype)
    # Get old stats TODO use only get_stats
    #import pdb;pdb.set_trace()
    #stats_by_players = get_general_players_stats()
    stats_by_players = [(p, {'kills': sum(data['kills'].values()),
                             'suicides': data['suicides'],
                             'deaths': data['deaths'],
                             'score': data['score'],
                             'ratio': sum(data['kills'].values()) / float(data['deaths']) if data['deaths'] else 0,
                              }
                        )
                        for p, data in stats_by_players.items()]
    try:
        context['best_killer'] = sorted([(x, data['kills']) for x, data in stats_by_players],
                                    key=lambda x: x[1],
                                    reverse=True)[0]
    except:
        context['best_killer'] = ("Nostat", 0)
    if context['best_killer'][1] == 0:
        context['best_killer'] = ("Nostat", 0)

    try:
        context['best_score'] = sorted([(x, data['score']) for x, data in stats_by_players],
                                   key=lambda x: x[1],
                                   reverse=True)[0]
    except:
        context['best_score'] = ("Nostat", 0)
    if context['best_score'][1] == 0:
        context['best_score'] = ("Nostat", 0)

    try:
        context['best_ratio'] = sorted([(x, data['ratio']) for x, data in stats_by_players],
                                   key=lambda x: x[1],
                                   reverse=True)[0]
    except:
        context['best_ratio'] = ("Nostat", 0)
    if context['best_ratio'][1] == 0:
        context['best_ratio'] = ("Nostat", 0)

    try:
        context['best_suicider'] = sorted([(x, data['suicides']) for x, data in stats_by_players],
                                      key=lambda x: x[1],
                                      reverse=True)[0]
    except:
        context['best_suicider'] = ("Nostat", 0)
    if context['best_suicider'][1] == 0:
        context['best_suicider'] = ("Nostat", 0)

    try:
        context['best_victim'] = sorted([(x, data['deaths']) for x, data in stats_by_players],
                                    key=lambda x: x[1],
                                    reverse=True)[0]
    except:
        context['best_victim'] = ("Nostat", 0)
    if context['best_victim'][1] == 0:
        context['best_victim'] = ("Nostat", 0)


    try:
        hammer_victims = get_item_stats('hammer', gametype)['dead by Hammer']
        context['best_hammer_victim'] = sorted([(x, data) for x, data in hammer_victims.items()],
                                           key=lambda x: x[1],
                                           reverse=True)[0]
    except:
        context['best_hammer_victim'] = ("Nostat", 0)
    if context['best_hammer_victim'][1] == 0:
        context['best_hammer_victim'] = ("Nostat", 0)

    return context