Best Python code snippet using dbt-osmosis_python
main.py
Source:main.py
1import json2import os3import pandas as pd4import matplotlib.pyplot as plt5import numpy as np6import datetime as dt7import torch8from easydict import EasyDict9import os10def main(path="./input/"):11 # PARSER12 global_args= EasyDict()13 contributors_name = []14 contributors_num_skills = []15 contributors_skills = {}16 project_name = []17 project_duration = []18 project_score = []19 project_date = []20 project_num_roles = []21 project_roles = {}22 line = 023 skill_list = []24 skill_to_contributor = {}25 skill_level_to_contributor = {}26 num_project_per_people = {}27 with open(path, 'r') as file_reader:28 first_args_list = file_reader.readline().split(' ')29 global_args["number_of_contributor"] = int(first_args_list[0])30 global_args["number_of_project"] = int(first_args_list[1])31 for i in range(global_args["number_of_contributor"]):32 next_args_1 = file_reader.readline().split(' ')33 contributors_name.append(next_args_1[0])34 num_project_per_people[next_args_1[0]] = 035 contributors_num_skills.append(int(next_args_1[1]))36 contributors_skills[next_args_1[0]] = {}37 for i in range(int(next_args_1[1])):38 next_args_2 = file_reader.readline().split(' ')39 level = int(next_args_2[1])40 skill_name = next_args_2[0]41 if skill_name not in skill_list:42 skill_list.append(skill_name)43 skill_to_contributor[skill_name] = []44 skill_level_to_contributor[skill_name] = {}45 for level_ in range(level+1):46 if level_ not in skill_level_to_contributor[skill_name].keys():47 skill_level_to_contributor[skill_name][level_] = []48 skill_level_to_contributor[skill_name][level].append(next_args_1[0]) 49 skill_to_contributor[skill_name].append(next_args_1[0])50 contributors_skills[next_args_1[0]][skill_name] = level51 52 for i in range(global_args["number_of_project"]):53 next_args_1 = file_reader.readline().split(' ')54 project_name.append(next_args_1[0])55 project_score.append(int(next_args_1[2]))56 project_date.append(int(next_args_1[3]))57 project_num_roles.append(int(next_args_1[4]))58 project_roles[next_args_1[0]] = []59 60 for i in range(int(next_args_1[4])):61 next_args_2 = file_reader.readline().split(' ')62 project_roles[next_args_1[0]].append((next_args_2[0],int(next_args_2[1])))63 ## More data processing64 ## Skills to people65 ## ALGO66 number_of_executed_project = global_args["number_of_project"]67 from copy import deepcopy68 project_to_tackle = deepcopy(project_name)69 _, indices = torch.sort(torch.Tensor(project_date))70 project_to_tackle = [project_to_tackle[i] for i in indices]71 project_list_in_order = []72 contributors = {}73 step = 074 while len(project_to_tackle) > 0:75 step += 176 if step > len(project_to_tackle):77 break78 project = project_to_tackle[0]79 project_to_tackle.remove(project)80 project_to_tackle.append(project)81 drop_project = False82 skills = deepcopy(project_roles[project])83 contributors[project] = deepcopy(skills)84 people_to_upgrade = []85 skills_backup = deepcopy(skills)86 if project=="PhoneUltrav1":87 a=088 while len(skills) > 0:89 availability = 10000090 num_item = 091 for num, (skill, level) in enumerate(skills):92 avail = count_number_available_dude(skill_level_to_contributor[skill], level)93 if avail < availability:94 availability = avail95 num_item = num96 97 skill, level = skills[num_item]98 num_item_backup = contributors[project].index((skill, level))99 if not drop_project:100 level_to_contributor = skill_level_to_contributor[skill]101 102 if level not in level_to_contributor.keys():103 # Skip this project (for now :) 104 drop_project = True105 break106 else:107 # Pick108 list_of_potential_contributors = []109 level_max = max(level_to_contributor.keys())110 candidate_for_mentorring = level_to_contributor[level-1]111 for i in range(level,level_max+1):112 list_of_potential_contributors += level_to_contributor[i]113 114 found_contributor = False115 #filter 1116 list_of_potential_contributors_2 = []117 for contrib_potential in list_of_potential_contributors:118 if not contrib_potential in contributors[project]:119 list_of_potential_contributors_2.append(contrib_potential)120 121 found_mentor = False122 for mentor in list_of_potential_contributors_2:123 if found_mentor:124 continue125 item_mentor = 0126 for iiiii, (skill__, level__) in enumerate(skills):127 if iiiii== num_item:128 continue129 if skill__ in contributors_skills[mentor]:130 if contributors_skills[mentor][skill__] >=level__:131 found_mentor = True132 mentor = mentor133 skill_mentor = skill__134 level_mentor = level__135 item_mentor = iiiii136 break137 138 if found_mentor and len(candidate_for_mentorring)>0:139 found_contributor = True140 item_mentor_back = contributors[project].index((skill_mentor, level_mentor))141 if num_item>=item_mentor:142 print(num_item, item_mentor)143 skills.pop(num_item)144 skills.pop(item_mentor)145 else:146 print(item_mentor)147 skills.pop(item_mentor)148 skills.pop(num_item)149 num_project_per_people[candidate_for_mentorring[0]]+=1150 151 contributors[project][num_item_backup] = candidate_for_mentorring[0]152 contributors[project][item_mentor_back] = mentor153 try:154 if contributors_skills[mentor][skill_mentor] == level_mentor:155 people_to_upgrade.append((mentor, skill_mentor))156 except:157 a=0158 people_to_upgrade.append((candidate_for_mentorring[0], skill))159 else:160 list_num_project = []161 if len(list_of_potential_contributors_2)>0:162 for contrib_potential in list_of_potential_contributors_2:163 list_num_project.append(num_project_per_people[contrib_potential])164 index = torch.argmin(torch.Tensor(list_num_project))165 # contrib_potential = list_of_potential_contributors_2[index.int().item()]166 contrib_potential = list_of_potential_contributors_2[0]167 found_contributor = True168 skills.pop(num_item)169 num_project_per_people[contrib_potential]+=1170 contributors[project][num_item_backup] = contrib_potential171 if contributors_skills[contrib_potential][skill] == level:172 people_to_upgrade.append((contrib_potential, skill))173 if not found_contributor:174 drop_project = True175 break176 if not drop_project:177 step = 0178 # Upgrade contributors skills.179 for people, skill in people_to_upgrade:180 old_level = contributors_skills[people][skill]181 contributors_skills[people][skill] += 1182 skill_level_to_contributor[skill][old_level].remove(people)183 if not old_level+1 in skill_level_to_contributor[skill].keys():184 skill_level_to_contributor[skill][old_level+1] = []185 skill_level_to_contributor[skill][old_level+1].append(people)186 project_to_tackle.remove(project)187 project_list_in_order.append(project)188 with open(path[:-4] + "_output.txt", 'w') as file_reader:189 file_reader.write(f"{len(project_list_in_order)}\n")190 for i, name in enumerate(project_list_in_order):191 file_reader.write(f"{name}\n")192 contrib = contributors[name]193 my_str = (" ").join(contrib)194 file_reader.write(f"{my_str}\n")195 print("done")196def count_number_available_dude(skill_level_to_contributor_skill, level):197 level_max = max(skill_level_to_contributor_skill.keys())198 reutrn_val = 0199 for i in range(level, level_max+1):200 reutrn_val += len(skill_level_to_contributor_skill[i])201 return reutrn_val202if __name__ == '__main__':203 main("./input/f_find_great_mentors.in.txt")204 main("./input/a_an_example.in.txt")205 main("./input/b_better_start_small.in.txt")206 main("./input/c_collaboration.in.txt")207 main("./input/d_dense_schedule.in.txt")...
gen3_deleter.py
Source:gen3_deleter.py
1"""Utility, deletes projects and nodes. Edit types array for your deployment."""2import os3import sys4import logging5from gen3_etl.utils.cli import default_argument_parser6from gen3_etl.utils.gen3 import delete_all, submission_client7DEFAULT_PROGRAM = None8DEFAULT_PROJECT = None9DEFAULT_CREDENTIALS_PATH = os.path.join('config', 'credentials.json')10DEFAULT_ENDPOINT = 'https://localhost'11DEFAULT_TYPES = ['submitted_methylation', 'submitted_somatic_mutation', 'read_group', 'demographic', 'aliquot', 'sample', 'bcc_diagnosis', 'diagnosis', 'bcc_demographic', 'demographic', 'bcc_participant', 'case', 'experiment']12DEFAULT_BATCH_SIZE = 10013DEFAULT_DROP_PROJECT = False14logger = logging.getLogger('gen3_deleter')15def delete(program, project, submission_client, types=DEFAULT_TYPES, batch_size=DEFAULT_BATCH_SIZE, drop_project=DEFAULT_DROP_PROJECT):16 """Delete all content from project."""17 delete_all(submission_client, program, project, types=types, batch_size=batch_size)18 try:19 if drop_project:20 print(submission_client.delete_project(program, project), file=sys.stderr)21 except Exception as e:22 print(e)23 # try:24 # print(submission_client.delete_program(program), file=sys.stderr)25 # except Exception as e:26 # print(e)27if __name__ == "__main__":28 parser = default_argument_parser(29 description='deletes all content for project'30 )31 parser.add_argument('--program', type=str,32 default=DEFAULT_PROGRAM,33 help='Name of existing gen3 program ({}).'.format(DEFAULT_PROGRAM))34 parser.add_argument('--project', type=str,35 default=DEFAULT_PROJECT,36 help='Name of existing gen3 project ({}).'.format(DEFAULT_PROJECT))37 parser.add_argument('--credentials_path', type=str,38 default=DEFAULT_CREDENTIALS_PATH,39 help='Location of gen3 path ({}).'.format(DEFAULT_CREDENTIALS_PATH))40 parser.add_argument('--endpoint', type=str,41 default=DEFAULT_ENDPOINT,42 help='gen3 host base url ({}).'.format(DEFAULT_ENDPOINT))43 parser.add_argument('--types', type=str,44 default=DEFAULT_TYPES,45 nargs='*',46 help='list of entitites to delete ({}).'.format(DEFAULT_TYPES))47 parser.add_argument('--batch_size', type=int,48 default=DEFAULT_BATCH_SIZE,49 help='Number of records to send to gen3 at a time({}).'.format(DEFAULT_BATCH_SIZE))50 parser.add_argument('--drop_project', type=bool,51 default=DEFAULT_DROP_PROJECT,52 help=f'Drop project ({DEFAULT_DROP_PROJECT}).')53 log_fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'54 logging.basicConfig(level=logging.INFO, format=log_fmt)55 args = parser.parse_args()56 delete(program=args.program,57 project=args.project,58 submission_client=submission_client(refresh_file=args.credentials_path, endpoint=args.endpoint),59 types=args.types,60 batch_size=args.batch_size,61 drop_project=args.drop_project...
projects.py
Source:projects.py
...4142@app.route('/projects/<string:project_id>', methods=['DELETE'])43def delete_project(project_id):44 try:45 drop_project(project_id)46 return jsonify(api_response(status="success")), 20047 except (ValueError, AttributeError, RuntimeError) as e:48 return jsonify(api_response(status="fail", error=str(e))), 500
...
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!!