def get_all_project_managers(): ''' it comes handy to see all project managers hired (read operation) ''' json_data = read_from(FILE_PATH) if json_data: for obj in json_data: print("\t {} ".format(obj["name"])) else: print('\t There are no project managers at all!')
def list_developer_projects(): ''' It's nice to know on what projects developer is working on ''' json_data = read_from(FILE_PATH) if json_data: name = input("\t Enter developer's name: ") for obj in json_data: if obj["name"] == name: developer_projects = "" for project in obj["list_of_projects"]: developer_projects += project + "," print("\t Developer {} is working on projects: {}".format( name, developer_projects[:-1])) else: print("\t No such developer")
def get_least_experienced_developer(): ''' read and select ''' json_data = read_from(FILE_PATH) experience_years = [] if json_data: for obj in json_data: experience_years.append(int(obj["years_of_experience"])) min_experience = min(experience_years) for obj in json_data: if int(obj["years_of_experience"]) == min_experience: print("\t The least experienced developer is: {}".format( obj["name"])) else: print("\t File is empty. You haven't engaged any developer")
def get_highest_payed_developer(): ''' Let's see who has the best results and thus the highest payed developer ''' json_data = read_from(FILE_PATH) developers_salaries = [] if json_data: for obj in json_data: developers_salaries.append(float(obj["salary"])) max_payed = max(developers_salaries) for obj in json_data: if float(obj["salary"]) == max_payed: print("\t The highest payed developer is: {}".format( obj["name"])) else: print("\t File is empty. You haven't engaged any developer")
def update_project_manager(): ''' It considered name to be the primary key, so user is promted to one to be able to change one of 3 other fields --- (update operation) ''' json_data = read_from(FILE_PATH) if json_data: name = input("\t Enter project manager's name: ") print("\t You can update one of three following options: ") print("\t ----------------------------------------") print(""" 1: years of experience 2: salary 3: project that's being supervised """) option = int( input( "\t Choose a number next to the action you want to perform: ")) for obj in json_data: if obj["name"] == name: if option == 1: years_of_experience = input( "\t Enter project manager's years of experience: ") if years_of_experience: delete_entity(name, FILE_PATH) obj["years_of_experience"] = years_of_experience write_to(obj, FILE_PATH) elif option == 2: salary = input("\t Enter a salary for product manager: ") if salary: delete_entity(name, FILE_PATH) obj["salary"] = salary write_to(obj, FILE_PATH) elif option == 3: supervises_project = input( "\t Enter a project that is " "being supervised by project manager: ") if supervises_project: delete_entity(name, FILE_PATH) obj["supervises_project"] = supervises_project write_to(obj, FILE_PATH) elif option < 1 or option > 3: print("\t That's not an option") break
def get_project_manager(): ''' select a project manager with certain name -- read operation ''' manager_name = input("\t Enter project manager's name: ") json_data = read_from(FILE_PATH) if json_data: #if is not empty for obj in json_data: if obj["name"] == manager_name: print( "\t {} is a project manager, with {} years of experience and he/she" " is engaged on a {} for a salary {}".format( obj["name"], obj["years_of_experience"], obj["supervises_poject"], obj["salary"])) return print("\t We do not have a project manager with that name!") else: print("\t We do not have a project manager with that name!")
def get_developer(): ''' It considered name to be the primary key, so you can get developer by searching through database using his name. --- (read operation) ''' developer = input("\t Enter developer's name: ") json_data = read_from(FILE_PATH) if json_data: #if is not empty for obj in json_data: if obj["name"] == developer: developer_projects = "" for project in obj["list_of_projects"]: developer_projects += project + "," print( "\t {} is a developer, with {} years of experience and he/she " "is engaged on several projects: {} for a salary {}". format(obj["name"], obj["years_of_experience"], developer_projects[:-1], obj["salary"])) return print("\t We do not have a developer with that name!") else: print("\t We do not have a developer with that name!")
def global_cache_read(cache_id, default='.'): cache_fname = join(GLOBAL_CACHE_DIR, 'cached_dir_%s.txt' % cache_id) return helpers.read_from(cache_fname) if exists(cache_fname) else default
def get_oxsty_mAP_score_from_res(hs, res, SV, oxsty_qres_dpath, compute_ap_exe, oxford_gt_dir): # find oxford ground truth directory cwd = os.getcwd() # build groundtruth query qcx = res.qcx qnx = hs.tables.cx2_nx[qcx] cx2_oxnum = hs.tables.prop_dict['oxnum'] qoxnum = cx2_oxnum[qcx] qname = hs.tables.nx2_name[qnx] # build ranked list cx2_score = res.cx2_score_V if SV else res.cx2_score top_cx = cx2_score.argsort()[::-1] top_gx = hs.tables.cx2_gx[top_cx] top_gname = hs.tables.gx2_gname[top_gx] # build mAP args if qoxnum == '': print("HACK: Adding a dummy qoxynum") qoxnum = '1' ground_truth_query = qname+'_'+qoxnum # build ranked list of gnames (remove duplicates) seen = set([]) ranked_list = [] for gname in iter(top_gname): gname_ = gname.replace('.jpg','') if not gname_ in seen: seen.add(gname_) ranked_list.append(gname_) ranked_list2 = [gname.replace('.jpg','') for gname in top_gname] # Write the ranked list of images names cx_aug = 'qcx_'+str(qcx) ranked_list_fname = 'ranked_list_' + cx_aug + ground_truth_query + '.txt' ranked_list_fpath = join(oxsty_qres_dpath, ranked_list_fname) helpers.write_to(ranked_list_fpath, '\n'.join(ranked_list)) # execute external mAP code: # ./compute_ap [GROUND_TRUTH] [RANKED_LIST] os.chdir(oxford_gt_dir) def filename(path): return os.path.split(path)[1] if OXSTY_VERBOSE: printable_cmd = ' '.join((filename(compute_ap_exe), ground_truth_query, filename(ranked_list_fpath))) print('Executing: %r' % printable_cmd) else: helpers.print_('.') args = (compute_ap_exe, ground_truth_query, ranked_list_fpath) cmdstr = ' '.join(args) try: proc_out = run_process(args) out = proc_out.out except OSError as ex: out = -1 if OXSTY_VERBOSE: print(repr(ex)) if repr(ex) == "OSError(12, 'Cannot allocate memory')": args_hash = helpers.hashstr(args) proc_err_fname = 'proc_err'+args_hash proc_err_cmd = proc_err_fname+'.cmd' proc_err_out = proc_err_fname+'.out' helpers.write_to(proc_err_cmd, repr(args)) if helpers.checkpath(proc_err_out): out = helpers.read_from(proc_err_out) mAP = float(out.strip()) os.chdir(cwd) return mAP