Exemple #1
0
def getMatchesInCompetition(stage = None, competitionID = None):
    if competitionID:
        response = Match.getByCompetitionID(competitionID)
    else:
        response = Match.all()
        
    all_matches = {}
    aux = []
    if stage is not None:
        aux = [match for match in response if match['round'] == int(stage) or match['round'] == int(stage)+1]
    else:
        aux = response
    
    response = aux
    for match in response:
        r = match['round']
        match['result'] = Result.getByMatchID(match['match_id'])
        if r not in all_matches.keys():
            all_matches[r] = []
#         match['offset'] = 2**(match['round'] - 1) - 1
#         match['height'] = 2**match['round'] - 1
#         match['offset'] = 2**(len(all_matches) - 1) - 1
#         match['height'] = 2**len(all_matches) - 1
        match['offset'] = 2**(len(all_matches) - 1) - 1
        match['height'] = len(all_matches)**2 - len(all_matches)
        all_matches[r].append(match)
    return prepare_response(all_matches)
Exemple #2
0
def check_results(matchID = None):
    if matchID is None:
        matches = Match.all()
    else:
        matches = Match.getById(matchID)
         
    for match in matches:
        match['results'] = Result.getByMatchID(match['match_id'])
        calculate_winner(match['player_a'], match['player_b'], match['results'], match['match_id'])
        
    return prepare_response(True)