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()
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
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 `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
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`.`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`.`schema_name` = %s LIMIT 1 """, params ) for row in cursor: race_info = RaceInfo() if row[6] is not None: race_info.set_char(row[6]) if row[7] is not None: race_info.descriptor = row[7] if row[8] is not None: race_info.seeded = bool(row[8]) if row[9] is not None: race_info.amplified = bool(row[9]) if row[10] is not None: race_info.seed_fixed = bool(row[10]) 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()