Ejemplo n.º 1
0
def main():
    result_filename = sys.argv[1]
    project_id = sys.argv[2]
    round_id = sys.argv[3]

    admission_project = AdmissionProject.objects.get(pk=project_id)
    admission_round = AdmissionRound.objects.get(pk=round_id)

    all_applications = {}

    for application in (ProjectApplication.objects.filter(admission_project=admission_project,
                                                          admission_round=admission_round)
                        .select_related('applicant')
                        .select_related('major_selection')
                        .all()):
        all_applications[application.applicant.national_id] = application

    counter = 0
    with open(result_filename) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for items in reader:
            nat_id = items[0]
            if nat_id not in all_applications:
                print('ERROR', nat_id)
                continue
            
            application = all_applications[nat_id]
            major_selection = application.major_selection
            
            majors = major_selection.get_majors()
            result_nums = items[1:]
            if len(majors) != len(result_nums):
                print('ERROR')

            for i in range(len(result_nums)):
                result = AdmissionResult(applicant=application.applicant,
                                         application=application,
                                         admission_project=admission_project,
                                         admission_round=admission_round,
                                         major_rank=i+1,
                                         major=majors[i])
                if result_nums[i] == '-1':
                    result.is_accepted_for_interview = False
                else:
                    result.is_accepted_for_interview = True
                    if majors[i].number != int(result_nums[i]):
                        print('ERROR - number')
                    
                result.updated_accepted_for_interview_at = datetime.now()
                result.save()
                counter += 1
            print(application.applicant)

    print('Imported',counter,'results')
Ejemplo n.º 2
0
def common_print(request):
    applicant = request.applicant
    admission_round = AdmissionRound.objects.get(pk=1)
    
    personal_profile = applicant.get_personal_profile()
    educational_profile = applicant.get_educational_profile()

    active_application = applicant.get_active_application(admission_round)
    if not active_application:
        return HttpResponseForbidden()

    admission_project = active_application.admission_project
    #if admission_project.id not in [28,36]:
    #    return HttpResponseForbidden()

    project_round = admission_project.get_project_round_for(admission_round)
    if not project_round.accepted_for_interview_result_shown:
        return HttpResponseForbidden()
    
    major_selection = active_application.get_major_selection()
    majors = major_selection.get_majors()

    admission_results = AdmissionResult.find_by_application(active_application)
    is_accepted_for_interview = False
    for res in admission_results:
        if res.is_accepted_for_interview:
            is_accepted_for_interview = True

    if not is_accepted_for_interview:
        return HttpResponseForbidden()

    mresults = dict([(res.major_id, res) for res in admission_results])
    for major in majors:
        if major.id not in mresults:
            major.is_accepted_for_interview = False
        else:
            major.is_accepted_for_interview = mresults[major.id].is_accepted_for_interview
    
    return render(request,
                  'appl/print/common_print.html',
                  { 'applicant': applicant,
                    'application_number': active_application.get_number(),
                    'admission_project': admission_project,
                    'personal_profile': personal_profile,
                    'educational_profile': educational_profile,
                    'majors': majors })
Ejemplo n.º 3
0
def main():
    result_filename = sys.argv[1]
    project_id = sys.argv[2]
    round_id = sys.argv[3]

    admission_project = AdmissionProject.objects.get(pk=project_id)
    admission_round = AdmissionRound.objects.get(pk=round_id)

    all_applications = {}

    for application in (ProjectApplication.objects.filter(
            admission_project=admission_project,
            admission_round=admission_round).select_related(
                'applicant').select_related('major_selection').all()):
        all_applications[application.applicant.national_id] = application

    counter = 0
    with open(result_filename) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for items in reader:
            if (len(items) < 2) or (items[1].strip() == ''):
                continue
            nat_id = items[1]
            rank = int(items[0])

            if nat_id not in all_applications:
                print('ERROR', nat_id)
                continue

            application = all_applications[nat_id]

            results = AdmissionResult.find_by_application(application)
            for r in results:
                if r.is_accepted_for_interview:
                    r.interview_rank = rank
                    r.save()

            counter += 1

            print(application.applicant)

    print('Imported', counter, 'results')
Ejemplo n.º 4
0
def main():
    result_filename = sys.argv[1]
    project_id = 11
    round_id = 2

    admission_project = AdmissionProject.objects.get(pk=project_id)
    admission_round = AdmissionRound.objects.get(pk=round_id)

    all_applications = {}

    for application in (ProjectApplication.objects.filter(admission_project=admission_project,
                                                          admission_round=admission_round,
                                                          is_canceled=False)
                        .select_related('applicant')
                        .select_related('major_selection')
                        .all()):
        all_applications[application.applicant.national_id] = application

    counter = 0
    with open(result_filename) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for items in reader:
            if len(items) < 4:
                continue
            
            nat_id = items[3]
            if nat_id not in all_applications:
                print('ERROR', nat_id)
                continue
            
            application = all_applications[nat_id]
            major_selection = application.major_selection
            
            majors = major_selection.get_majors()
            interview_major_num  = int(items[0])

            found = False
            for i in range(len(majors)):
                old_results = AdmissionResult.objects.filter(application=application,
                                                             admission_project=admission_project,
                                                             admission_round=admission_round,
                                                             major=majors[i])

                if len(old_results) > 0:
                    result = old_results[0]
                else:
                    result = AdmissionResult(applicant=application.applicant,
                                             application=application,
                                             admission_project=admission_project,
                                             admission_round=admission_round,
                                             major_rank=i+1,
                                             major=majors[i])
                if majors[i].number != interview_major_num:
                    result.is_accepted_for_interview = False
                else:
                    found = True
                    result.is_accepted_for_interview = True
                    
                result.updated_accepted_for_interview_at = datetime.now()
                result.save()
                counter += 1
            if not found:
                print('ERROR, major not found', interview_major_num)
            print(application.applicant)

    print('Imported',counter,'results')
Ejemplo n.º 5
0
def main():
    result_filename = sys.argv[1]
    project_id = sys.argv[2]
    round_id = sys.argv[3]

    admission_project = AdmissionProject.objects.get(pk=project_id)
    admission_round = AdmissionRound.objects.get(pk=round_id)

    all_applications = {}

    for application in (ProjectApplication.objects.filter(admission_project=admission_project,
                                                          admission_round=admission_round,
                                                          is_canceled=False)
                        .select_related('applicant')
                        .select_related('major_selection')
                        .all()):
        all_applications[application.applicant.national_id] = application

    counter = 0
    with open(result_filename) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for items in reader:
            nat_id = items[1]
            if nat_id not in all_applications:
                print('ERROR', nat_id)
                continue
            
            application = all_applications[nat_id]
            results = application.admissionresult_set.all()
            if len(results) > 1:
                print('ERROR too many results', nat_id)
                continue

            if len(results) == 1:
                result = results[0]
                if result.major.number != int(items[0]):
                    print('ERROR wrong old majors',nat_id, items[0])
                    continue
            else:
                try:
                    majors = application.major_selection.get_majors()
                except:
                    print('ERROR not major selection')
                    continue
                
                if len(majors)!=1:
                    print('ERROR too many majors', nat_id)
                    continue
                if majors[0].number != int(items[0]):
                    print('ERROR wrong majors',nat_id, items[0])
                    continue
                result = AdmissionResult(applicant=application.applicant,
                                         application=application,
                                         admission_project=admission_project,
                                         admission_round=admission_round,
                                         major_rank=1,
                                         major=majors[0])

            result.calculated_score = float(items[2])
            result.save()
            
            print(application.applicant)
            counter += 1

    print('Imported',counter,'results')
def main():
    result_filename = sys.argv[1]
    project_id = sys.argv[2]
    round_id = sys.argv[3]

    admission_project = AdmissionProject.objects.get(pk=project_id)
    admission_round = AdmissionRound.objects.get(pk=round_id)

    all_applications = {}

    for application in (ProjectApplication.objects.filter(
            admission_project=admission_project,
            admission_round=admission_round).select_related(
                'applicant').select_related('major_selection').all()):
        all_applications[application.applicant.national_id] = application

    counter = 0
    with open(result_filename) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for items in reader:
            nat_id = items[0].strip()

            if not re.match(r'\d+', nat_id) and nat_id != '':
                continue

            if nat_id == '':
                name = ' '.join(items[1].split())
                for nat in all_applications.keys():
                    app = all_applications[nat].applicant
                    if app.first_name + ' ' + app.last_name == name:
                        nat_id = nat

            if nat_id not in all_applications:
                print('ERROR', nat_id, name)
                continue

            major_num = int(items[2])

            application = all_applications[nat_id]
            major_selection = application.major_selection
            majors = major_selection.get_majors()

            if major_num == 0:
                accepted_major = None
                for m in majors:
                    results = AdmissionResult.objects.filter(
                        applicant=application.applicant,
                        application=application,
                        major=m,
                        is_accepted_for_interview=True).all()
                    if len(results) != 0:
                        accepted_major = m
                        break
                if not accepted_major:
                    print('ERROR', nat_id, 'major not found', major_num)
                    continue
            else:
                accepted_major = None
                for m in majors:
                    if m.number == major_num:
                        accepted_major = m
                if not accepted_major:
                    print('ERROR', nat_id, 'major not found', major_num)
                    continue

            results = AdmissionResult.objects.filter(
                applicant=application.applicant,
                application=application,
                major=accepted_major).all()
            if len(results) == 0:
                result = AdmissionResult(applicant=application.applicant,
                                         application=application,
                                         admission_project=admission_project,
                                         admission_round=admission_round,
                                         major_rank=0,
                                         major=accepted_major)
            else:
                result = results[0]

            result.is_accepted_for_interview = True
            result.is_accepted = True
            result.updated_accepted_at = datetime.now()
            result.clearing_house_code = items[3]
            result.clearing_house_code_number = int(items[4])
            result.save()

            print(application.applicant, result.major)

            counter += 1

    print('Imported', counter, 'results')
Ejemplo n.º 7
0
def main():
    result_filename = sys.argv[1]
    project_id = sys.argv[2]
    round_id = sys.argv[3]

    admission_project = AdmissionProject.objects.get(pk=project_id)
    admission_round = AdmissionRound.objects.get(pk=round_id)

    all_applications = {}

    for application in (ProjectApplication.objects.filter(
            admission_project=admission_project,
            admission_round=admission_round,
            is_canceled=False).select_related('applicant').select_related(
                'major_selection').all()):
        all_applications[application.applicant.national_id] = application

    counter = 0
    with open(result_filename) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for items in reader:
            major_number = int(items[0])
            nat_id = 'x' + items[1]
            score = float(items[2])
            if nat_id not in all_applications:
                #print('ERROR', nat_id)
                continue

            application = all_applications[nat_id]

            majors = [
                m for m in application.major_selection.get_majors()
                if m.number == major_number
            ]

            if len(majors) == 0:
                #print('ERROR major not found', nat_id)
                continue

            print(nat_id, major_number)

            major = majors[0]

            old_results = AdmissionResult.objects.filter(
                application=application, major=major).all()

            if old_results:
                result = old_results[0]
            else:
                result = AdmissionResult()

            result.applicant = application.applicant
            result.application = application
            result.admission_project = admission_project
            result.admission_round = admission_round
            result.major_rank = 1
            result.major = major
            result.calculated_score = score
            result.is_accepted_for_interview = True
            result.save()

            major_results = ApplicantMajorResult.objects.filter(
                major=major,
                admission_project=admission_project,
                applicant=application.applicant).all()

            if len(major_results) != 0:
                major_result = major_results[0]
                major_result.admission_result = result
                major_result.save()
                print('saved', major.number)

            counter += 1
            if counter % 1000 == 0:
                print(counter, application.applicant)

    print('Imported', counter, 'results')
Ejemplo n.º 8
0
def main():
    result_filename = sys.argv[1]
    project_id = sys.argv[2]
    round_id = sys.argv[3]

    admission_project = AdmissionProject.objects.get(pk=project_id)
    admission_round = AdmissionRound.objects.get(pk=round_id)

    all_applications = {}

    for application in (ProjectApplication.objects.filter(admission_project=admission_project,
                                                          admission_round=admission_round,
                                                          is_canceled=False)
                        .select_related('applicant')
                        .select_related('major_selection')
                        .all()):
        all_applications[application.applicant.national_id] = application

    accepted_applications = set()
    
    counter = 0
    with open(result_filename) as csvfile:
        reader = csv.reader(csvfile, delimiter=',')
        for items in reader:
            nat_id = items[1]
            if nat_id not in all_applications:
                print('ERROR', nat_id)
                continue
            
            application = all_applications[nat_id]
            major_selection = application.major_selection
            
            majors = major_selection.get_majors()
            called_major = items[4].strip()
            called_faculty = items[3].strip()

            found = False
            for m in majors:
                if m.title == called_major and m.faculty.title == 'คณะ' + called_faculty:
                    found = True

            if not found:
                print('ERROR', nat_id, called_major, majors)
                continue

            for i in range(len(majors)):
                old_results = AdmissionResult.objects.filter(application=application,
                                                             admission_project=admission_project,
                                                             admission_round=admission_round,
                                                             major=majors[i]).all()
                if len(old_results) > 0:
                    result = old_results[0]
                else:
                    result = AdmissionResult(applicant=application.applicant,
                                             application=application,
                                             admission_project=admission_project,
                                             admission_round=admission_round,
                                             major_rank=i+1,
                                             major=majors[i])

                m=majors[i]
                if m.title == called_major and m.faculty.title == 'คณะ' + called_faculty:
                    result.is_accepted_for_interview = True
                else:
                    result.is_accepted_for_interview = False
                    
                result.updated_accepted_for_interview_at = datetime.now()
                result.save()
                counter += 1
            print(application.applicant)

            accepted_applications.add(application.id)

    print('Imported',counter,'results')

    for app in all_applications.values():
        if app.id not in accepted_applications:
            old_results = AdmissionResult.objects.filter(application=app,
                                                         admission_project=admission_project).all()
            for res in old_results:
                if res.is_accepted_for_interview:
                    res.is_accepted_for_interview = False
                    res.save()
                    print('cleared', res.id, app.applicant.national_id)