def test_get_all_candidates(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() sp1 = dbc.Specialization() sp1.capacity = 92 sp1.name = "specialization 1" sp1.identifier = 1 sp2 = dbc.Specialization() sp2.capacity = 92 sp2.name = "specialization 2" sp2.identifier = 2 dbc.save_specialization(sp1) dbc.save_specialization(sp2) to_save1 = dbc.Candidate() to_save1.cnp = 123456789 to_save1.first_name = "student1 in town" to_save1.surname = " name1 " to_save1.email = "*****@*****.**" to_save1.info_grade = 6.7 to_save1.math_grade = 8.9 to_save1.high_school_avg_grade = 9.5 to_save1.admission_grade = 7.8 to_save1.first_option = 2 to_save1.second_option = 1 to_save2 = dbc.Candidate() to_save2.cnp = 987654321 to_save2.first_name = " student2 in town" to_save2.surname = " name2" to_save2.email = "*****@*****.**" to_save2.info_grade = 6.7 to_save2.math_grade = 8.9 to_save2.high_school_avg_grade = 9.5 to_save2.admission_grade = 7.8 to_save2.first_option = 2 to_save2.second_option = 1 dbc.save_candidate(to_save1) dbc.save_candidate(to_save2) found = dbc.get_all_candidates() self.assertEqual(2, len(found)) found = dbc.get_all_candidates(1) self.assertEqual(2, len(found))
def candidates(): actions = menu_actions.menu candidates = DbC.get_all_candidates(1) return render_template('candidates_list.html', title='Candidates List', actions=actions, candidates=candidates)
def calculate_results(): specializations = DbC.get_all_specializations() candidates = DbC.get_all_candidates() repartition = [] specs = {} opt_arr = {} for item in specializations: specs[item.identifier] = {} specs[item.identifier]["name"] = item.name specs[item.identifier]["capacity"] = item.capacity specs[item.identifier]["free_spots"] = item.capacity for item in candidates: r = DbC.AdmissionResult() r.candidate_cnp = item.cnp r.final_score = max( item.info_grade, item.math_grade ) * 0.3 + item.high_school_avg_grade * 0.2 + 0.5 * item.admission_grade r.specialization_id = item.first_option r.allocation = DbC.AdmissionStatus.UNPROCESSED repartition.append(r) opt_arr[str(item.cnp)] = {} opt_arr[str(item.cnp)]["first_option"] = item.first_option opt_arr[str(item.cnp)]["second_option"] = item.second_option repartition = sorted(repartition, key=lambda x: ( x.specialization_id, (-1) * x.final_score, )) for item in repartition: if item.final_score < 5: item.allocation = DbC.AdmissionStatus.REJECTED continue if specs[item.specialization_id]["free_spots"] > 2: item.allocation = DbC.AdmissionStatus.FREE specs[item.specialization_id]["free_spots"] -= 1 elif specs[item.specialization_id]["free_spots"] > 0: item.allocation = DbC.AdmissionStatus.FEE specs[item.specialization_id]["free_spots"] -= 1 else: item.specialization_id = opt_arr[str( item.candidate_cnp)]["second_option"] if specs[item.specialization_id]["free_spots"] > 2: item.allocation = DbC.AdmissionStatus.FREE specs[item.specialization_id]["free_spots"] -= 1 elif specs[item.specialization_id]["free_spots"] > 0: item.allocation = DbC.AdmissionStatus.FEE specs[item.specialization_id]["free_spots"] -= 1 else: item.allocation = DbC.AdmissionStatus.REJECTED # print("Candidate CNP: ", item.candidate_cnp) # print("Admission Grade: ", item.final_score) # print("AdmissionResult: ", item.allocation) # print("Specialization: ", specs[item.specialization_id]["name"]) # print("Specialization ID: ", item.specialization_id) return repartition
def test_save_duplicate_candidate(self): with open(dbc.DB_FILE_PATH, "r+") as f: f.truncate() to_save = dbc.Candidate() to_save.cnp = 987654321 to_save.first_name = "new student in town" to_save.surname = " mhm " to_save.email = "*****@*****.**" to_save.info_grade = 6.7 to_save.math_grade = 8.9 to_save.high_school_avg_grade = 9.5 to_save.admission_grade = 7.8 to_save.first_option = 2 to_save.second_option = 1 dbc.save_candidate(to_save) result = dbc.save_candidate(to_save) saved = dbc.get_all_candidates() self.assertEqual(1, len(saved)) self.assertEqual('ALREADY_EXISTING', result)