Esempio n. 1
0
    def test_delete_admission_by_id(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save1 = dbc.AdmissionResult()
        to_save1.candidate_cnp = 987654321
        to_save1.allocation = dbc.AdmissionStatus.FEE
        to_save1.specialization_id = 0
        to_save1.final_score = 8.6

        to_save2 = dbc.AdmissionResult()
        to_save2.candidate_cnp = 1234567
        to_save2.allocation = dbc.AdmissionStatus.FREE
        to_save2.specialization_id = 0
        to_save2.final_score = 9.0

        dbc.save_admission_result_for_candidate(to_save1)
        dbc.save_admission_result_for_candidate(to_save2)

        dbc.delete_admission_result_for_candidate(987654321)

        found1 = dbc.get_admission_result_for_candidate(987654321)
        found2 = dbc.get_admission_result_for_candidate(1234567)

        self.assertEqual(to_save2.to_xml(), found2.to_xml())
        self.assertEqual(None, found1)
Esempio n. 2
0
    def test_get_all_results(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save = dbc.Specialization()
        to_save.capacity = 92
        to_save.name = "new specialization"
        to_save.identifier = 0

        result = dbc.save_specialization(to_save)

        to_save1 = dbc.AdmissionResult()
        to_save1.candidate_cnp = 987654321
        to_save1.allocation = dbc.AdmissionStatus.FEE
        to_save1.specialization_id = 0
        to_save1.final_score = 8.6

        to_save2 = dbc.AdmissionResult()
        to_save2.candidate_cnp = 1234567
        to_save2.allocation = dbc.AdmissionStatus.FREE
        to_save2.specialization_id = 0
        to_save2.final_score = 9.0

        dbc.save_admission_result_for_candidate(to_save1)
        dbc.save_admission_result_for_candidate(to_save2)

        found = dbc.get_admission_results()

        self.assertEqual(2, len(found))

        found = dbc.get_admission_results(1)

        self.assertEqual(2, len(found))
Esempio n. 3
0
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
Esempio n. 4
0
    def test_save_admission_no_data(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save = dbc.AdmissionResult()

        result = dbc.save_admission_result_for_candidate(to_save)
        found = dbc.get_admission_result_for_candidate(0)

        self.assertEqual('OK', result)
        self.assertEqual(to_save.to_xml(), found.to_xml())
        found.print()
Esempio n. 5
0
    def test_update_specialization_not_found(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        original = dbc.AdmissionResult()
        original.candidate_cnp = 987654321
        original.allocation = dbc.AdmissionStatus.FEE
        original.specialization_id = 0
        original.final_score = 8.6

        dbc.save_admission_result_for_candidate(original)

        updated = dbc.AdmissionResult()
        updated.candidate_cnp = 12345
        updated.allocation = dbc.AdmissionStatus.UNPROCESSED
        updated.specialization_id = 0
        updated.final_score = 0.0

        result = dbc.update_admission_result_for_candidate(updated)

        found = dbc.get_admission_result_for_candidate(987654321)

        self.assertEqual(original.to_xml(), found.to_xml())
        self.assertEqual('Entry not found', result)
Esempio n. 6
0
    def test_save_duplicate_admission(self):
        with open(dbc.DB_FILE_PATH, "r+") as f:
            f.truncate()

        to_save = dbc.AdmissionResult()
        to_save.candidate_cnp = 987654321
        to_save.allocation = dbc.AdmissionStatus.FEE
        to_save.specialization_id = 0
        to_save.final_score = 8.6

        dbc.save_admission_result_for_candidate(to_save)

        result = dbc.save_admission_result_for_candidate(to_save)
        saved = dbc.get_admission_results()

        self.assertEqual(1, len(saved))
        self.assertEqual('OK', result)