Returns the deserialized version of a single match.
(cur, round_num: int, match_index: int)
| 74 | |
| 75 | |
| 76 | def serialize_match(cur, round_num: int, match_index: int): |
| 77 | ''' |
| 78 | Returns the deserialized version of a single match. |
| 79 | ''' |
| 80 | match = {} |
| 81 | match['index'] = match_index |
| 82 | match['replays'] = [] |
| 83 | match['winner_ids'] = [] |
| 84 | |
| 85 | cur.execute('SELECT red_team, blue_team, status, replay \ |
| 86 | FROM {} WHERE round={} AND index={} \ |
| 87 | AND (status=\'redwon\' or status=\'bluewon\');' |
| 88 | .format(TABLE_NAME, round_num, match_index)) |
| 89 | |
| 90 | matches = cur.fetchall() |
| 91 | if len(matches) != 3: |
| 92 | return None |
| 93 | |
| 94 | red_team, blue_team, _, _ = matches[0] |
| 95 | |
| 96 | if red_team is None or blue_team is None: |
| 97 | return None |
| 98 | |
| 99 | match['Red'] = serialize_team(red_team) |
| 100 | match['Blue'] = serialize_team(blue_team) |
| 101 | |
| 102 | match_winners = { |
| 103 | red_team: 0, |
| 104 | blue_team: 0 |
| 105 | } |
| 106 | |
| 107 | for _, _, status, replay in matches: |
| 108 | match['replays'].append(REPLAY_PREFIX + re.search('replays/(.+\.bc18z)$', replay).group(1)) |
| 109 | |
| 110 | if status == 'redwon': |
| 111 | match['winner_ids'].append(red_team) |
| 112 | match_winners[red_team] += 1 |
| 113 | elif status == 'bluewon': |
| 114 | match['winner_ids'].append(blue_team) |
| 115 | match_winners[blue_team] += 1 |
| 116 | else: |
| 117 | raise Exception("Match should be finished.") |
| 118 | |
| 119 | if match_winners[red_team] == 2: |
| 120 | match['winner_id'] = red_team |
| 121 | break |
| 122 | if match_winners[blue_team] == 2: |
| 123 | match['winner_id'] = blue_team |
| 124 | break |
| 125 | |
| 126 | return match |
| 127 | |
| 128 | def serialize_round(cur, round_num: int): |
| 129 | ''' |
no test coverage detected