Example #1
0
def view_game(request, game_id):
    game = _get_game_or_404(game_id)
    token_averages = [] # a list of token averages
    for token in game.tokens:
        token_averages.append(TokenAverage(token, 0))
        
    instances = GameInstance.objects(game=game) # get all instances for the specified game
    total = 0 # total is only for finished games
    
    # This looks ugly, needs refactoring at some point if possible
    # but this basically adds up all the modifiers from completed
    # games so it can be divided by the total afterwards
    for instance in instances:
        if instance.is_complete():
            total += 1
            for response in instance.responses:
                for modifier in response.question.token_modifiers:
                    delta = modifier.yes_modifier if response.response == 1 else modifier.no_modifier
                    for average in token_averages:
                        if average.token == modifier.token:
                            average.width += (delta * 5)
                
    # average division on all tokens
    for average in token_averages:
        average.width /= total
            
    return _respond('view', { "game":game, "total":total, "averages":token_averages }, request)
Example #2
0
def play_game(request, game_id):
    game = _get_game_or_404(game_id)
    instance = GameInstance(game=game) # Create a new game instance every time
    instance.save()
    return _respond('play', { "instance":instance }, request)