Best Python code snippet using autotest_python
helpers.py
Source:helpers.py
...23 return self.nfl.shield.query(op)24 @staticmethod25 def _standard_fields(obj: shield.AbstractEntity, type_):26 obj.__fields__(*DEFAULT_FIELDS.get(type_))27def apply_selector(obj, type_, select_fun: Callable[[types.Type], None] = None):28 if select_fun:29 select_fun(obj)30 else:31 Helper._standard_fields(obj, type_)32class ScheduleHelper(Helper):33 def current_week(self, date: datetime.datetime = None) -> shield.Week:34 op = Operation(shield.Viewer)35 if date is None:36 week: shield.Week = op.viewer.league.current.week()37 else:38 date = date.astimezone(pendulum.UTC)39 week: shield.Week = op.viewer.league.current(date=date).week()40 week.season_value()41 week.season_type()42 week.week_order()43 week.week_type()44 week.week_value()45 return self.query(op).viewer.league.current.week46 def week(self, date: datetime.datetime):47 return self.current_week(date)48class GameHelper(Helper):49 def week_games(self, week=None, season_type=None, season=None):50 if week is None or season_type is None or season is None:51 current_week = self.nfl.schedule.current_week()52 week = week if week is not None else current_week.week_value53 season_type = season_type or current_week.season_type54 season = season or current_week.season_value55 games = self.nfl.football.games_by_week(season, season_type=season_type, week=week)56 return games57 def by_id(self, game_id: str):58 return self.nfl.football.game_by_id(game_id)59 def game_detail_id_for_id(self, game_id: str):60 return self.nfl.football.game_detail_id_for_id(game_id)61class GameDetailHelper(Helper):62 def by_id(self, id, select_fun: Callable[[shield.GameDetail], None] = None):63 op = Operation(shield.Viewer)64 game_detail = op.viewer.game_detail(id=id)65 apply_selector(game_detail, shield.GameDetail, select_fun)66 game_detail = self.query(op).viewer.game_detail67 return game_detail68 def by_ids(self, ids, select_fun: Callable[[shield.GameDetail], None] = None):69 op = Operation(shield.Viewer)70 game_details = op.viewer.game_details_by_ids(ids=ids)71 apply_selector(game_details, shield.GameDetail, select_fun)72 return self.query(op).viewer.game_details_by_ids73class StandingsHelper(Helper):74 def get(self, week, season_type, season):75 result = self.nfl.football.standings_by_week(season, season_type, week)76 team_records = result.weeks[0].standings77 teams = {t.id: t for t in self.nfl.team.by_season(season)}78 return [(teams[team_record.team.id], team_record) for team_record in team_records]79 def current(self, date=None):80 current_week = self.nfl.schedule.current_week(date)81 week = current_week.week_value82 season_type = current_week.season_type83 season = current_week.season_value84 return self.get(week, season_type, season)85class TeamHelper(Helper):86 def get_all(self, season_value=0, select_fun: Callable[[shield.Team], None] = None) -> List[shield.Team]:87 op = Operation(shield.Viewer)88 teams = op.viewer.teams(first=100, season_value=season_value)89 team = teams.edges.node()90 apply_selector(team, shield.Team, select_fun)91 teams = self.query(op)92 return [t.node for t in teams.viewer.teams.edges]93 def lookup(self, abbreviation, season_value=0, select_fun: Callable[[shield.Team], None] = None):94 # There is no way to lookup teams by anything other than id95 # So we just get them all and pick it from the bunch :|96 def add_abbreviation(team):97 if select_fun:98 select_fun(team)99 team.abbreviation()100 all_teams = self.get_all(season_value, select_fun=add_abbreviation)101 return next(filter(lambda t: t.abbreviation == abbreviation, all_teams), None)102 def by_ids(self, ids: List[str], select_fun: Callable[[shield.Game], None] = None):103 op = Operation(shield.Viewer)104 teams = op.viewer.teams_by_ids(ids=ids)105 apply_selector(teams, shield.Team, select_fun)106 teams = self.query(op)107 return teams.viewer.teams_by_ids108 def by_season(self, season: int):109 return self.nfl.football.teams_by_season(season).teams110class RosterHelper(Helper):111 def lookup(self, abbreviation, select_fun: Callable[[shield.CurrentClubRoster], None] = None):112 def add_abbr_and_property_id(team):113 if select_fun:114 select_fun(team)115 team.abbreviation()116 team.franchise.property.id()117 all_teams = self.nfl.team.get_all(select_fun=add_abbr_and_property_id)118 the_team = next(filter(lambda t: t.abbreviation == abbreviation, all_teams), None)119 if not the_team:120 return None121 return self.by_id(the_team.franchise.property.id, select_fun)122 def by_id(self, id: str, select_fun: Callable[[shield.CurrentClubRoster], None] = None):123 # id param is team.franchise.property.id124 op = Operation(shield.Viewer)125 roster = op.viewer.clubs.current_club_roster(property_id=id)126 apply_selector(roster, shield.CurrentClubRoster, select_fun)127 roster = self.query(op)128 return roster.viewer.clubs.current_club_roster129 def by_team_id(self, team_id: str, select_fun: Callable[[shield.CurrentClubRoster], None] = None):130 def add_property_id(team):131 if select_fun:132 select_fun(team)133 team.franchise.property.id()134 the_team = self.nfl.team.by_ids(ids=[team_id], select_fun=add_property_id)135 if not len(the_team):136 return None137 else:138 the_team = the_team[0]139 return self.by_id(the_team.franchise.property.id, select_fun)140class CombineHelper(Helper):141 def participants(self, year: int = 0):142 return self.nfl.football.combine_profiles_by_year(year)143class PlayerHelper(Helper):144 def lookup(self, season: int = 0, player_name: str = None, team_id: str = None, status=None, first=100, after=None, select_fun: Callable[[shield.Player], None] = None):145 def add_team_person_fields(player):146 if select_fun:147 select_fun(player)148 else:149 apply_selector(player, shield.Player)150 person = player.person()151 apply_selector(person, shield.PlayerPerson)152 team = player.current_team()153 apply_selector(team, shield.Team)154 op = Operation(shield.Viewer)155 players = op.viewer.players(season_season=season, person_display_name_contains=player_name, current_team_id=team_id, first=first, after=after)156 players.edges.cursor()157 player = players.edges.node()158 apply_selector(player, shield.Player, select_fun=add_team_person_fields)159 players = self.query(op)160 player_list = []161 for p in players.viewer.players.edges:162 p.node.cursor = p.cursor163 player_list.append(p.node)164 return player_list165 def by_id(self, id: str, select_fun: Callable[[shield.Player], None] = None):166 def add_team_person_fields(player):167 if select_fun:168 select_fun(player)169 else:170 apply_selector(player, shield.Player)171 person = player.person()172 apply_selector(person, shield.PlayerPerson)173 team = player.current_team()174 apply_selector(team, shield.Team)175 op = Operation(shield.Viewer)176 player = op.viewer.player(id=id)177 apply_selector(player, shield.Player, select_fun=add_team_person_fields)178 player = self.query(op)179 return player.viewer.player180__all__ = [181 'ScheduleHelper',182 'GameHelper',183 'StandingsHelper',184 'TeamHelper',185 'GameDetailHelper',186 'RosterHelper',187 'PlayerHelper',188 'CombineHelper',...
identify_contigs.py
Source:identify_contigs.py
...71 other_align_columns = [c for c in table.columns if c.startswith('num_aln') and c not in chry_align_columns]72 select_y = table[chry_align_columns].sum(axis=1) > 073 no_other = table[other_align_columns].sum(axis=1) < 174 selector = select_y & no_other75 select, remain = apply_selector(selector, table, reason)76 return select, remain77def rule_select_y_specific_motif_hits(table, motif, reason):78 chry_align_columns = [c for c in table.columns if c.startswith('num_aln_chrY')]79 motif_hit_column = f'num_hits_hiq_{motif}'80 select_y = table[chry_align_columns].sum(axis=1) > 081 motif_hit = table[motif_hit_column] > 082 selector = select_y & motif_hit83 select, remain = apply_selector(selector, table, reason)84 return select, remain85def rule_select_many_unspecific_motif_hits(table, motif, reason):86 chry_primary_column = 'num_aln_chrY_PRI'87 motif_hit_column = f'num_hits_hiq_{motif}'88 select_y = table[chry_primary_column] > 089 motif_hit = table[motif_hit_column] > UNSPECIFIC_THRESHOLD90 selector = select_y & motif_hit91 select, remain = apply_selector(selector, table, reason)92 return select, remain93def rule_select_unaligned_specific_hits(table, motif, reason):94 align_columns = [c for c in table.columns if c.startswith('num_aln_')]95 motif_hit_column = f'num_hits_hiq_{motif}'96 select_y = table[align_columns].sum(axis=1) < 197 motif_hit = table[motif_hit_column] > 098 selector = select_y & motif_hit99 select, remain = apply_selector(selector, table, reason)100 return select, remain101def rule_select_majority_primary_alignment(table, reason, chrom):102 chrom_primary_column = f'pct_aln_{chrom}_PRI'103 selector = table[chrom_primary_column] > PRIMARY_ALN_THRESHOLD_PCT104 select, remain = apply_selector(selector, table, reason)105 return select, remain106def apply_selector(selector, table, reason):107 if not selector.any():108 selected_contigs = None109 remaining_contigs = table110 else:111 selected_contigs = table.loc[selector, :].copy()112 remaining_contigs = table.loc[~selector, :].copy()113 selected_contigs['reason'] = reason114 return selected_contigs, remaining_contigs115def merge_aggregated_tables(align, motifs, chrom):116 keep_motif_columns = [117 'target', # tig name118 'num_hits_hiq'119 ]120 df = pd.read_csv(align, sep='\t', header=0)...
generalise.py
Source:generalise.py
2# find coverage loss examples3# take html file paths as input4# for each file, apply selector and report coverage5import sys6def apply_selector(contents, pattern):7 return Selector(text=contents).css(pattern).extract()8matched = 09total = 010from statread import replace_extension, statuses11selector = sys.argv[1]12for fn in sys.stdin:13 fn = fn.rstrip()14 fn = fn.strip('"')15 with file(fn) as f:16 stat_fn = replace_extension(fn, 'stat')17 stats = list(statuses(file(stat_fn).readlines()))18 contents = f.read()19 result = apply_selector(contents, selector)20 print stats[-1].url21 print result22 print23 if result:24 matched += 125 total += 1...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!