Esempio n. 1
0
def addPost(request, instance=None):
    company = getCurrentCompany(request)
    if company.profileCompleted == False:
        return redirect('company:editprofile')
    if instance is None:
        formInitialData = {'company': company}
        form = addPostForm(initial=formInitialData)
    else:
        formInitialData = {'company': company}
        form = addPostForm(initial=formInitialData, instance=instance)

    if request.method == 'POST':
        form = addPostForm(request.POST, instance=instance)
        if form.is_valid():
            newPost = form.save()

            collection = connectDatabase()

            if instance is None:
                result = collection.update(
                    {'id': int(newPost.id)},
                    {'$set': {
                        'appliedStudents': [],
                        'selectedStudents': []
                    }})

            return redirect('company:home')
    elif not (instance is None):
        return render(request, 'company/editpost.html', {'form': form})
    return render(request, 'company/addpost.html', {'form': form})
Esempio n. 2
0
def getAppliedStudents(postid):
    collection = connectDatabase()
    result = list(
        collection.find({'id': int(postid)}, {
            'appliedStudents': 1,
            '_id': 0
        }))[0]['appliedStudents']

    applied_students = []

    if len(result) > 0:
        for id in result:
            try:
                current_student = Student.objects.filter(id=int(id))[0]
                applied_students.append(current_student)
            except IndexError:
                print("Student with " + str(id) + " is deleted")

    post_technology = Post.objects.filter(id=int(postid))[0].postTechnology

    applied_students_marks = []

    for student in applied_students:
        current_students_marks_total = 0
        for field in Student._meta.get_fields():
            # normalizing the marks out of 100 and multiplying with weights. if current marks are posted technologythen weight = 0.7 else 0.2
            if 'Marks' in field.name:
                current_field = field.name.replace("Marks", "")
                if current_field == post_technology:
                    current_students_marks_total += (
                        getattr(student, field.name) * 100 / 70) * 0.7
                else:
                    current_students_marks_total += (
                        getattr(student, field.name) * 100 / 70) * 0.2
            elif field.name == 'cpi':
                current_students_marks_total += (getattr(student, field.name) *
                                                 100 / 10) * 0.2
            elif field.name == 'aptitude':
                current_students_marks_total += getattr(student,
                                                        field.name) * 0.2
        # applying multiple linear regression formula : y = b1x1 + b2x2 + ... where x are marks, b are weights
        applied_students_marks.append(current_students_marks_total)

    # associatingstudents with their ML score
    appliedStudents = list(zip(applied_students, applied_students_marks))

    # sorting the applied students in descending order
    sorted_applied_students = [
        student[0]
        for student in sorted(appliedStudents,
                              key=lambda appliedStudents: appliedStudents[1],
                              reverse=True)
    ]

    return sorted_applied_students
Esempio n. 3
0
def getAppliedPosts(studentId):
    collection = connectDatabase()

    cursor = [
        id['id'] for id in list(
            collection.find({'appliedStudents': int(studentId)}, {
                "id": 1,
                '_id': 0
            }))
    ]
    return cursor
Esempio n. 4
0
def getSelectedStudents(postid):
    collection = connectDatabase()
    result = list(
        collection.find({'id': int(postid)}, {
            'selectedStudents': 1,
            '_id': 0
        }))[0]['selectedStudents']
    selected_students = []
    if len(result) > 0:
        selected_students = [
            Student.objects.filter(id=int(id))[0] for id in result
        ]
    return selected_students
Esempio n. 5
0
def selectStudent(postid, studentid):
    collection = connectDatabase()
    cursor = list(
        collection.find({"id": int(postid)}, {
            "selectedStudents": 1,
            '_id': 0
        }))[0]['selectedStudents']

    if int(studentid) not in cursor:
        cursor.append(int(studentid))

    result = collection.update({'id': int(postid)},
                               {'$set': {
                                   'selectedStudents': cursor
                               }})
Esempio n. 6
0
def showResult(request, postid, studentid):
    collection = connectDatabase()

    cursor = list(
        collection.find({'id': int(postid)}, {
            "selectedStudents": 1,
            '_id': 0
        }))[0]['selectedStudents']
    message, error_message = '', ''
    if int(studentid) in cursor:
        message = 'Congratulations you are selected :)'
    else:
        error_message = 'Sorry you are not selected :('
    return render(request, 'student/showresult.html', {
        'message': message,
        'errormessage': error_message
    })