Esempio n. 1
0
def check_data(campus_id, student_id1, lectures1, student_id2, lectures2):
    if student_id1 == student_id2:
        return

    lectures1 = set([l.subject_code for l in lectures1])
    lectures2 = set([l.subject_code for l in lectures2])

    analogue = len(lectures1 & lectures2)/len(lectures1 | lectures2)
    if analogue >= 1.0:
        return

    try:
        analogue_obj = LectureAnalogue.objects(
            campus_id=campus_id,
            student_id=student_id1
        ).get()

        if analogue_obj.point >= analogue:
            return
    except:
        analogue_obj = LectureAnalogue(
            campus_id=campus_id,
            student_id=student_id1
        )

    analogue_obj.point = analogue
    analogue_obj.target = student_id2
    analogue_obj.save()

    print('%s-%s %s' % (student_id1, student_id2, analogue))
Esempio n. 2
0
def lecture_vtimetable():
    current_year = datetime.now().year
    recommend = []

    if session.get_account():
        try:
            analogue = LectureAnalogue.objects(
                campus_id=session.get_account().campus_id,
                student_id=session.get_account().student_id
            ).get()

            lectures1 = Lecture.objects(students__in=[session.get_account().student_id])
            lectures2 = Lecture.objects(students__in=[analogue.target])

            lectures1 = set([l.subject_code for l in lectures1])
            lectures2 = set([l.subject_code for l in lectures2])

            lectures = lectures2 - lectures1
            
            for lecture in lectures:
                try:
                    lecture = Lecture.objects(subject_code=lecture)[0]
                    recommend.append(lecture.subject_name)
                except:
                    pass
        except:
            pass

    return render_template('module/lecture/vtimetable.html', current_year=current_year, recommend=recommend)