Total Complexity | 7 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import websockets |
||
2 | from websockets.client import WebSocketClientProtocol |
||
3 | from datetime import timedelta |
||
4 | from models.race import Race |
||
5 | import websockets |
||
6 | import logging |
||
7 | |||
8 | class Qualifier: |
||
9 | logger = logging.Logger("racetime-obs") |
||
10 | enabled = False |
||
11 | qualifier_cutoff = 3 |
||
12 | qualifier_par_source = "" |
||
13 | qualifier_score_source = "" |
||
14 | qualifier_par_text = " " |
||
15 | entrant_score = " " |
||
16 | |||
17 | def update_qualifier_text(self, race: Race, full_name: str): |
||
18 | if not self.enabled: |
||
19 | return |
||
20 | entrant = race.get_entrant_by_name(full_name) |
||
21 | self.logger.debug(entrant) |
||
22 | |||
23 | self.qualifier_par_text = " " |
||
24 | entrant_score = " " |
||
25 | if race.entrants_count_finished >= self.qualifier_cutoff: |
||
26 | par_time = timedelta(microseconds=0) |
||
27 | for i in range(1, self.qualifier_cutoff + 1): |
||
28 | if race.get_entrant_by_place(i).finish_time is None: |
||
29 | self.logger.error("error: qualifier finish time is None") |
||
30 | return |
||
31 | self.logger.debug( |
||
32 | f"finish time for rank {i} is {race.get_entrant_by_place(i).finish_time}") |
||
33 | par_time += race.get_entrant_by_place(i).finish_time |
||
34 | par_time = par_time / self.qualifier_cutoff |
||
35 | self.logger.debug(par_time) |
||
36 | self.qualifier_par_text = self.timer_to_str(par_time) |
||
37 | |||
38 | if entrant and entrant.finish_time is not None: |
||
39 | entrant_score = str(2 - (entrant.finish_time / par_time))[:4] |
||
40 | self.logger.debug(entrant_score) |