async def get_league(schema_name: str) -> League: """ Parameters ---------- schema_name: str The name of the schema for the event (and also the event's unique identifier). Returns ------- League A League object for the event. """ params = (schema_name, ) async with DBConnect(commit=False) as cursor: cursor.execute( """ SELECT `leagues`.`league_name`, `leagues`.`number_of_races`, `leagues`.`is_best_of`, `leagues`.`ranked`, `leagues`.`gsheet_id`, `leagues`.`deadline`, `race_types`.`category`, `race_types`.`descriptor`, `race_types`.`seeded` FROM `leagues` LEFT JOIN `race_types` ON `leagues`.`race_type` = `race_types`.`type_id` WHERE `leagues`.`schema_name` = %s LIMIT 1 """, params) for row in cursor: if all(i is not None for i in row[6:9]): race_info = RaceInfo(Category.fromstr(row[6]), row[7], bool(row[8])) else: race_info = RaceInfo() match_info = MatchInfo( max_races=int(row[1]) if row[1] is not None else None, is_best_of=bool(row[2]) if row[2] is not None else None, ranked=bool(row[3]) if row[3] is not None else None, race_info=race_info) return League(commit_fn=write_league, schema_name=schema_name, league_name=row[0], match_info=match_info, gsheet_id=row[4], deadline=row[5]) raise necrobot.exception.LeagueDoesNotExist()
async def get_league(league_tag: str) -> League: """ Parameters ---------- league_tag: str The unique identifier for the league Returns ------- League A League object for the event. """ params = (league_tag, ) async with DBConnect(commit=False) as cursor: cursor.execute( """ SELECT {leagues}.`league_tag`, {leagues}.`league_name`, {leagues}.`number_of_races`, {leagues}.`is_best_of`, {leagues}.`worksheet_id`, `race_types`.`character`, `race_types`.`descriptor`, `race_types`.`seeded`, `race_types`.`amplified`, `race_types`.`seed_fixed` FROM {leagues} LEFT JOIN `race_types` ON `leagues`.`race_type` = `race_types`.`type_id` WHERE {leagues}.`league_tag` = %s LIMIT 1 """.format(leagues=tn('leagues')), params) for row in cursor: race_info = RaceInfo() if row[5] is not None: race_info.set_char(row[5]) if row[6] is not None: race_info.descriptor = row[6] if row[7] is not None: race_info.seeded = bool(row[7]) if row[8] is not None: race_info.amplified = bool(row[8]) if row[9] is not None: race_info.seed_fixed = bool(row[9]) match_info = MatchInfo( max_races=int(row[2]) if row[2] is not None else None, is_best_of=bool(row[3]) if row[3] is not None else None, ranked=None, race_info=race_info) return League(commit_fn=write_league, league_tag=row[0], league_name=row[1], match_info=match_info, worksheet_id=row[4]) raise necrobot.exception.LeagueDoesNotExist()
async def make_match_from_raw_db_data(row: list) -> Match: match_id = int(row[0]) if match_id in match_library: return match_library[match_id] match_info = MatchInfo(race_info=await racedb.get_race_info_from_type_id( int(row[1])) if row[1] is not None else RaceInfo(), ranked=bool(row[9]), is_best_of=bool(row[10]), max_races=int(row[11])) sheet_info = MatchGSheetInfo() sheet_info.wks_id = row[14] sheet_info.row = row[15] new_match = Match(commit_fn=matchdb.write_match, match_id=match_id, match_info=match_info, racer_1_id=int(row[2]), racer_2_id=int(row[3]), suggested_time=row[4], finish_time=row[16], r1_confirmed=bool(row[5]), r2_confirmed=bool(row[6]), r1_unconfirmed=bool(row[7]), r2_unconfirmed=bool(row[8]), cawmentator_id=row[12], channel_id=int(row[13]) if row[13] is not None else None, gsheet_info=sheet_info, autogenned=bool(row[17])) await new_match.initialize() match_library[new_match.match_id] = new_match return new_match
def copy(match_info): the_copy = MatchInfo() the_copy.max_races = match_info.max_races the_copy.is_best_of = match_info.is_best_of the_copy.ranked = match_info.ranked the_copy.race_info = RaceInfo.copy(match_info.race_info) return the_copy
def __init__(self, parent, race_info: RaceInfo, race_config: RaceConfig = RaceConfig()): self.race_id = None # After recording, the ID of the race in the DB self.parent = parent # The parent managing this race. Must implement write() and process(). self.race_info = RaceInfo.copy(race_info) self.racers = [] # A list of Racer self._status = RaceStatus.uninitialized # The status of this race self._config = race_config # The RaceConfig to use (determines some race behavior) self._countdown = int(0) # The current countdown self._start_datetime = None # UTC time for the beginning of the race self._adj_start_time = float( 0 ) # System clock time for the beginning of the race (modified by pause) self._last_pause_time = float( 0) # System clock time for last time we called pause() self._last_no_entrants_time = None # System clock time for the last time the race had zero entrants self._delay_record = False # If true, delay an extra config.FINALIZE_TIME_SEC before recording self._countdown_future = None # The Future object for the race countdown self._finalize_future = None # The Future object for the finalization countdown
def __init__(self, max_races: int = None, is_best_of: bool = None, ranked: bool = None, race_info: RaceInfo = None): self.max_races = max_races if max_races is not None else 3 self.is_best_of = is_best_of if is_best_of is not None else False self.ranked = ranked if ranked is not None else False self.race_info = race_info if race_info is not None else RaceInfo()
async def get_all_leagues() -> List[League]: async with DBConnect(commit=False) as cursor: cursor.execute(""" SELECT {leagues}.`league_tag`, {leagues}.`league_name`, {leagues}.`number_of_races`, {leagues}.`is_best_of`, {leagues}.`worksheet_id`, `race_types`.`character`, `race_types`.`descriptor`, `race_types`.`seeded`, `race_types`.`amplified`, `race_types`.`seed_fixed` FROM {leagues} LEFT JOIN `race_types` ON `leagues`.`race_type` = `race_types`.`type_id` """.format(leagues=tn('leagues'))) all_leagues = [] for row in cursor: race_info = RaceInfo() if row[5] is not None: race_info.set_char(row[5]) if row[6] is not None: race_info.descriptor = row[6] if row[7] is not None: race_info.seeded = bool(row[7]) if row[8] is not None: race_info.amplified = bool(row[8]) if row[9] is not None: race_info.seed_fixed = bool(row[9]) match_info = MatchInfo( max_races=int(row[2]) if row[2] is not None else None, is_best_of=bool(row[3]) if row[3] is not None else None, ranked=None, race_info=race_info) all_leagues.append( League(commit_fn=write_league, league_tag=row[0], league_name=row[1], match_info=match_info, worksheet_id=row[4])) return all_leagues
async def get_race_info_from_type_id(race_type: int) -> RaceInfo or None: params = (race_type,) async with DBConnect(commit=False) as cursor: cursor.execute( """ SELECT `category`, `descriptor`, `seeded` FROM `race_types` WHERE `type_id`=%s """, params ) row = cursor.fetchone() if row is not None: race_info = RaceInfo(Category.fromstr(row[0]), row[1], row[2]) return race_info else: return None
async def get_race_info_from_type_id(race_type: int) -> RaceInfo or None: params = (race_type, ) async with DBConnect(commit=False) as cursor: cursor.execute( """ SELECT `character`, `descriptor`, `seeded`, `amplified`, `seed_fixed` FROM `race_types` WHERE `type_id`=%s """, params) row = cursor.fetchone() if row is not None: race_info = RaceInfo() race_info.set_char(row[0]) race_info.descriptor = row[1] race_info.seeded = bool(row[2]) race_info.amplified = bool(row[3]) race_info.seed_fixed = bool(row[4]) return race_info else: return None
def get_raceinfo_for_keyword(keyword: str) -> Optional[RaceInfo]: # Change some default values for CoH race_info = RaceInfo() race_info.character = NDChar.Coh race_info.seeded = False race_info.amplified = False race_info.private_race = True # Keyword-specific values (custom descriptor) if keyword == 'story-any': race_info.descriptor = 'CoH: Story (any%)' elif keyword == 'story-nobs': race_info.descriptor = 'CoH: Story (all instruments)' elif keyword == 'permadeath': race_info.descriptor = 'CoH: Permadeath' elif keyword == 'doubletempo': race_info.descriptor = 'CoH: Double Tempo' elif keyword == 'fixedbeat': race_info.descriptor = 'CoH: Fixed Beat' else: return None return race_info