File size: 763 Bytes
641009d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from collections import defaultdict

def calculate_win_probability(games_sorted, username):
    """Calculate win probability based on game position in a day."""
    wins_by_position = defaultdict(int)
    games_by_position = defaultdict(int)
    current_day = None
    game_position = 1

    for game in games_sorted:
        end_time = game.get('end_time')
        if not end_time:
            continue

        result = get_game_result(game, username)

        if result == 'win':
            wins_by_position[game_position] += 1
        games_by_position[game_position] += 1

        game_position += 1

    probabilities = {pos: (wins / games_by_position[pos] * 100) for pos, wins in wins_by_position.items()}
    return probabilities