Best Python code snippet using tempest_python
similarity_by_role.py
Source:similarity_by_role.py
1from datetime import datetime2import pandas as pd3from itertools import combinations4from helpers import extract_players_with_role, transpose_features5from helpers_similarity import compute_max_distance, compute_relative_similarity6# load data7players = pd.read_csv("data/players_post_corr.csv")8scl_ftrs = pd.read_csv("data/scaled_features_post_corr.csv")9list_roles = players['Pos'].unique()10# keep only 1 roles (for now)11list_roles = [role for role in list_roles if not ("-" in role)]12# overall complementarity13df_overall = pd.read_csv("output_data/ovrl_distances.csv")14# transpose features15t_scl_ftrs = transpose_features(scl_ftrs)16# computation last about 5 seconds17list_players = [extract_players_with_role(players, elem) for elem in list_roles]18# use a dictionary to recognize list of which roles19dict_players_roles = dict(zip(list_roles, list_players))20# compute max distances per role21dict_max_distance = dict(zip(list_roles, [compute_max_distance(t_scl_ftrs, elem) for elem in dict_players_roles.values()]))22# compute combination for every role23comb_roles_players_values = [list(combinations(elem, 2)) for elem in dict_players_roles.values()]24# create dataframe of combinations per every role25dict_comb_roles_players = dict(zip(list_roles, [pd.DataFrame(elem, columns=['Player1', 'Player2']) for elem in comb_roles_players_values]))26# for every role, com27for role in dict_comb_roles_players.keys():28 dict_comb_roles_players[role]['similarity'] = list(29 map(lambda x, y: compute_relative_similarity(30 t_scl_ftrs,31 x,32 y,33 dict_max_distance[role]),34 dict_comb_roles_players[role]['Player1'],35 dict_comb_roles_players[role]['Player2']))36 dict_comb_roles_players[role]['complementarity'] = 1 - dict_comb_roles_players[role]['similarity']37# add role to every dataframe and concatenate38for role in dict_comb_roles_players.keys():39 dict_comb_roles_players[role].insert(0, 'Pos', [role]*len(dict_comb_roles_players[role]))40df_by_roles = pd.concat(dict_comb_roles_players.values())41# add_overall complementarity ###42# change column name of overall_df43df_overall.rename(columns={'similarity': 'similarity_ov', 'complementarity': 'complementarity_ov'}, inplace=True)44# merge by role and overall45df_by_roles_overall = df_by_roles.merge(df_overall, how='left', on=['Player1', 'Player2'])46# add column of delta between two method47df_by_roles_overall['delta_sim'] = df_by_roles_overall['similarity_ov'] - df_by_roles_overall['similarity']48df_by_roles_overall['delta_com'] = df_by_roles_overall['complementarity'] - df_by_roles_overall['complementarity_ov']49# save output to csv...
rolemanager.py
Source:rolemanager.py
1# coding: utf-82import argparse3import os4from discord.ext import commands5from base import BaseCog, Parser6# Discord roles allowed to be granted to users7DISCORD_ROLES = os.environ.get('DISCORD_ROLES')8class RoleManager(BaseCog):9 """10 Role manager bot11 """12 @commands.command(name='roles')13 @commands.guild_only()14 async def _roles(self, ctx, *args):15 """16 Permet de s'attribuer un ou plusieurs rôles.17 Usage : `!roles <role> [<role> ...]`18 """19 if ctx.channel and hasattr(ctx.channel, 'name'):20 await ctx.message.delete()21 user = await self.get_user(ctx.author)22 # Get roles23 list_roles = [r.split("=") for r in DISCORD_ROLES.split(",")] if DISCORD_ROLES else []24 help_roles = ",\n".join(f"- {rolename} ({shortcut})" for (shortcut, rolename) in list_roles)25 # Argument parser26 parser = Parser(27 prog=f'{ctx.prefix}{ctx.command.name}',28 description="Permet de s'attribuer un ou plusieurs rôles.",29 epilog=f"Rôles disponibles :\n{help_roles}",30 formatter_class=argparse.RawTextHelpFormatter)31 parser.add_argument('roles', metavar='role', type=str, nargs='*', help="Rôle")32 args = parser.parse_args(args)33 if parser.message:34 await ctx.author.send(f"```{parser.message}```")35 return36 # Collect all allowed roles37 roles = {}38 for role in ctx.guild.roles:39 for shortcut, rolename in list_roles:40 if role.name.lower() == rolename.lower():41 roles[shortcut] = role42 # Collect selected roles43 new_roles = []44 selected_roles = map(str.lower, args.roles)45 for shortcut, role in roles.items():46 if shortcut.lower() in selected_roles:47 new_roles.append(role)48 elif role.name.lower() in selected_roles:49 new_roles.append(role)50 if not new_roles:51 help_roles = ", ".join(f"**{rolename}** ({shortcut})" for (shortcut, rolename) in list_roles)52 await ctx.author.send(f":warning: Vous devez sélectionner un ou plusieurs rôles parmi : {help_roles}")53 return54 # Clear roles55 old_roles = list(roles.values())56 await ctx.author.remove_roles(*old_roles)57 # Add roles58 await ctx.author.add_roles(*new_roles)59 role_names = ', '.join(role.name for role in new_roles)...
test_user.py
Source:test_user.py
...33 user.set_password('')34 assert not user.check_password('')35def test_user_role():36 user = User('paper')37 assert user.list_roles() == []38 user.add_role('ADMIN')39 assert user.list_roles() == ['ADMIN']40 user.del_role('ADMIN')41 assert user.list_roles() == []42 # add twice to confirm set-ness43 user.add_role('ADMIN')44 user.add_role('ADMIN')...
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!!