def engage_project_manager(): ''' hire an employee - create operation ''' name = input("\t Enter project manager's name: ") years_of_experience = input( "\t Enter project manager's years of experience: ") salary = input("\t Enter a salary for product manager: ") supervises_project = input( "\t Enter a project that project manager supervises: ") project_manager = ProjectManager(name, years_of_experience, salary, supervises_project) output_data = { "name": project_manager.name, "years_of_experience": project_manager.years_of_experience, "salary": project_manager.salary, "supervises_poject": project_manager.supervises_project } if check_if_unique(project_manager.name, FILE_PATH): write_to(output_data, FILE_PATH) print("\t Project manager hired!") else: print( "\t This entity already exists in database. Please, enter another one" )
def engage_developer(): ''' hire an developer --- (create operation) ''' name = input("\t Enter developer's name: ") years_of_experience = input("\t Enter developer's years of experience: ") salary = input("\t Enter a salary for developer: ") projects_str = input( "\t Enter all projects that developer is working on. \n" "\t So enter name of the project followed by , \n" "\t For instance: Ime Projekta 1, Ime Projekta 2 \n" "\t Now your turn:") list_of_projects = projects_str.split(",") developer = Developer(name, years_of_experience, salary, list_of_projects) output_data = { "name": developer.name, "years_of_experience": developer.years_of_experience, "salary": developer.salary, "list_of_projects": developer.list_of_projects } if check_if_unique(developer.name, FILE_PATH): write_to(output_data, FILE_PATH) print("\t Developer hired!") else: print( "\t This entity already exists in database. Please, enter another one" )
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 global_cache_write(cache_id, newdir): cache_fname = join(GLOBAL_CACHE_DIR, 'cached_dir_%s.txt' % cache_id) helpers.write_to(cache_fname, newdir)
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