示例#1
0
文件: tasks.py 项目: Macro-Bin/moocng
def update_kq_mark(db, kq, user, threshold, new_mark_kq=None, new_mark_normalized_kq=None):
    from moocng.courses.marks import calculate_kq_mark
    if not new_mark_kq or not new_mark_normalized_kq:
        from moocng.courses.marks_old import calculate_kq_mark_old
        calculate_kq_mark_old(kq, user)
        new_mark_kq, new_mark_normalized_kq, use_in_total = calculate_kq_mark(kq, user)
        if not use_in_total:
            return (False, False)
    data_kq = {}
    data_kq['user_id'] = user.pk
    data_kq['course_id'] = kq.unit.course.pk
    data_kq['unit_id'] = kq.unit.pk
    data_kq['kq_id'] = kq.pk

    marks_kq = db.get_collection('marks_kq')
    mark_kq_item = marks_kq.find_one(data_kq)
    if mark_kq_item:
        updated_kq_mark = (new_mark_kq != mark_kq_item['mark'] or
                           new_mark_normalized_kq != mark_kq_item['relative_mark'])
        if updated_kq_mark:
            marks_kq.update(
                data_kq,
                {'$set': {'mark': new_mark_kq,
                          'relative_mark': new_mark_normalized_kq}},
                safe=True
            )
    else:
        updated_kq_mark = True
        data_kq['mark'] = new_mark_kq
        data_kq['relative_mark'] = new_mark_normalized_kq
        marks_kq.insert(data_kq)
    return updated_kq_mark, has_passed_now(new_mark_kq, mark_kq_item, threshold)
示例#2
0
文件: tasks.py 项目: fid-jose/moocng
def update_mark(submitted):
    from moocng.courses.marks import calculate_kq_mark, calculate_unit_mark, calculate_course_mark
    updated_kq_mark = updated_unit_mark = updated_course_mark = False
    passed_kq = passed_unit = passed_course = False
    kq = KnowledgeQuantum.objects.get(pk=submitted['kq_id'])
    unit = kq.unit
    course = kq.unit.course
    user = User.objects.get(pk=submitted['user_id'])
    mark_kq, mark_normalized_kq = calculate_kq_mark(kq, user)

    db = get_db()

    # KQ
    updated_kq_mark, passed_kq = update_kq_mark(db, kq, user, course.threshold,
                                                new_mark_kq=mark_kq,
                                                new_mark_normalized_kq=mark_normalized_kq)

    # UNIT
    if not updated_kq_mark:
        return (updated_kq_mark, updated_unit_mark, updated_course_mark,
                passed_kq, passed_unit, passed_course)

    mark_unit, mark_normalized_unit = calculate_unit_mark(kq.unit, user)
    updated_unit_mark, passed_unit = update_unit_mark(db, unit, user, course.threshold,
                                                      new_mark_unit=mark_unit,
                                                      new_mark_normalized_unit=mark_normalized_unit)

    # COURSE
    if not updated_unit_mark:
        return (updated_kq_mark, updated_unit_mark, updated_course_mark,
                passed_kq, passed_unit, passed_course)
    mark_course, units_info = calculate_course_mark(unit.course, user)
    updated_course_mark, passed_course = update_course_mark(db, course, user, mark_course)
    return (updated_kq_mark, updated_unit_mark, updated_course_mark,
            passed_kq, passed_unit, passed_course)
示例#3
0
文件: tasks.py 项目: fid-jose/moocng
def update_kq_mark(db, kq, user, threshold, new_mark_kq=None, new_mark_normalized_kq=None):
    from moocng.courses.marks import calculate_kq_mark
    if not new_mark_kq or not new_mark_normalized_kq:
        new_mark_kq, new_mark_normalized_kq = calculate_kq_mark(kq, user)
    data_kq = {}
    data_kq['user_id'] = user.pk
    data_kq['course_id'] = kq.unit.course.pk
    data_kq['unit_id'] = kq.unit.pk
    data_kq['kq_id'] = kq.pk
    marks_kq = db.get_collection('marks_kq')
    mark_kq_item = marks_kq.find_one(data_kq)
    if mark_kq_item:
        updated_kq_mark = (new_mark_kq != mark_kq_item['mark'] or
                           new_mark_normalized_kq != mark_kq_item['relative_mark'])
        if updated_kq_mark:
            marks_kq.update(
                data_kq,
                {'$set': {'mark': new_mark_kq,
                          'relative_mark': new_mark_normalized_kq}},
                safe=True
            )
    else:
        updated_kq_mark = True
        data_kq['mark'] = new_mark_kq
        data_kq['relative_mark'] = new_mark_normalized_kq
        marks_kq.insert(data_kq)
    if kq.kq_type() == 'PeerReviewAssignment' and threshold is not None:
        threshold = decimal.Decimal('5.0')  # P2P is a special case
    return updated_kq_mark, has_passed_now(new_mark_kq, mark_kq_item, threshold)
示例#4
0
文件: tasks.py 项目: ntwuxc/moocng
def update_mark(submitted):
    from moocng.courses.marks import calculate_kq_mark, calculate_unit_mark, calculate_course_mark
    updated_kq_mark = updated_unit_mark = updated_course_mark = False
    passed_kq = passed_unit = passed_course = False
    kq = KnowledgeQuantum.objects.get(pk=submitted['kq_id'])
    unit = kq.unit
    course = kq.unit.course
    user = User.objects.get(pk=submitted['user_id'])
    mark_kq, mark_normalized_kq = calculate_kq_mark(kq, user)

    db = get_db()

    # KQ
    updated_kq_mark, passed_kq = update_kq_mark(
        db,
        kq,
        user,
        course.threshold,
        new_mark_kq=mark_kq,
        new_mark_normalized_kq=mark_normalized_kq)

    # UNIT
    if not updated_kq_mark:
        return (updated_kq_mark, updated_unit_mark, updated_course_mark,
                passed_kq, passed_unit, passed_course)

    mark_unit, mark_normalized_unit = calculate_unit_mark(kq.unit, user)
    updated_unit_mark, passed_unit = update_unit_mark(
        db,
        unit,
        user,
        course.threshold,
        new_mark_unit=mark_unit,
        new_mark_normalized_unit=mark_normalized_unit)

    # COURSE
    if not updated_unit_mark:
        return (updated_kq_mark, updated_unit_mark, updated_course_mark,
                passed_kq, passed_unit, passed_course)
    mark_course, units_info = calculate_course_mark(unit.course, user)
    updated_course_mark, passed_course = update_course_mark(
        db, course, user, mark_course)
    return (updated_kq_mark, updated_unit_mark, updated_course_mark, passed_kq,
            passed_unit, passed_course)
示例#5
0
文件: tasks.py 项目: ntwuxc/moocng
def update_kq_mark(db,
                   kq,
                   user,
                   threshold,
                   new_mark_kq=None,
                   new_mark_normalized_kq=None):
    from moocng.courses.marks import calculate_kq_mark
    if not new_mark_kq or not new_mark_normalized_kq:
        new_mark_kq, new_mark_normalized_kq = calculate_kq_mark(kq, user)
    data_kq = {}
    data_kq['user_id'] = user.pk
    data_kq['course_id'] = kq.unit.course.pk
    data_kq['unit_id'] = kq.unit.pk
    data_kq['kq_id'] = kq.pk
    marks_kq = db.get_collection('marks_kq')
    mark_kq_item = marks_kq.find_one(data_kq)
    if mark_kq_item:
        updated_kq_mark = (
            new_mark_kq != mark_kq_item['mark']
            or new_mark_normalized_kq != mark_kq_item['relative_mark'])
        if updated_kq_mark:
            marks_kq.update(data_kq, {
                '$set': {
                    'mark': new_mark_kq,
                    'relative_mark': new_mark_normalized_kq
                }
            },
                            safe=True)
    else:
        updated_kq_mark = True
        data_kq['mark'] = new_mark_kq
        data_kq['relative_mark'] = new_mark_normalized_kq
        marks_kq.insert(data_kq)
    if kq.kq_type() == 'PeerReviewAssignment' and threshold is not None:
        threshold = decimal.Decimal('5.0')  # P2P is a special case
    return updated_kq_mark, has_passed_now(new_mark_kq, mark_kq_item,
                                           threshold)
示例#6
0
def update_kq_mark(db, kq, user, threshold, new_mark_kq=None, new_mark_normalized_kq=None):
    from moocng.courses.marks import calculate_kq_mark

    if not new_mark_kq or not new_mark_normalized_kq:
        new_mark_kq, new_mark_normalized_kq = calculate_kq_mark(kq, user)
    data_kq = {}
    data_kq['user_id'] = user.pk
    data_kq['course_id'] = kq.unit.course.pk
    data_kq['unit_id'] = kq.unit.pk
    data_kq['kq_id'] = kq.pk
    marks_kq = db.get_collection('marks_kq')
    mark_kq_item = marks_kq.find_one(data_kq)
    if mark_kq_item:
        updated_kq_mark = (new_mark_kq != mark_kq_item['mark'] or
                           new_mark_normalized_kq != mark_kq_item['relative_mark'])
        if updated_kq_mark:
            marks_kq.update(
                data_kq,
                {'$set': {'mark': new_mark_kq,
                          'relative_mark': new_mark_normalized_kq}},
                safe=True
            )
    else:
        updated_kq_mark = True
        data_kq['mark'] = new_mark_kq
        data_kq['relative_mark'] = new_mark_normalized_kq
        marks_kq.insert(data_kq)
    if kq.kq_type() == 'PeerReviewAssignment' and threshold is not None:
        threshold = decimal.Decimal('5.0')  # P2P is a special case


    today = date.today()

    # badges
    badges = BadgeByCourse.objects.filter(course_id=kq.unit.course.pk, criteria_type=1)
    for badge in badges:
        win = False
        gotBadge = get_db().get_collection('badge').find_one({'id_badge': badge.id, "id_user": user.pk})
        if(not gotBadge):
            win = True
            criterias = badge.criteria.split(",")
            for criteria in criterias:
                mark = get_db().get_collection('marks_kq').find_one({'user_id': user.pk, "kq_id": int(criteria)})
                if(not mark or mark["mark"] < badge.note):
                    win = False

        if(win):
            get_db().get_collection('badge').insert({"id_badge":badge.id, "id_user":user.pk, "title":badge.title, "description":badge.description, "color":badge.color, "date": today.isoformat() })

    # badge unit checkpoint
    badges = BadgeByCourse.objects.filter(course_id=kq.unit.course_id, criteria_type=0)
    course_mark, units_info = get_course_mark(kq.unit.course, user)
    for badge in badges:
        win = False
        if(badge.note <= course_mark):
            gotBadge = get_db().get_collection('badge').find_one({'id_badge': badge.id, "id_user": user.pk})
            if(not gotBadge):
                try:
                    evaluateUnit = Unit.objects.get(id=badge.criteria)
                    units = Unit.objects.filter(course_id=evaluateUnit.course_id, order__lte = evaluateUnit.order)
                    win = True
                    for aux in units:
                        unit_kqs = aux.knowledgequantum_set.all()
                        for kq in unit_kqs:
                            if not kq.is_completed(user):
                                win = False
                except:
                    pass

        if(win):
            get_db().get_collection('badge').insert({"id_badge":badge.id, "id_user":user.pk, "title":badge.title, "description":badge.description, "color":badge.color, "date": today.isoformat()})

    return updated_kq_mark, has_passed_now(new_mark_kq, mark_kq_item, threshold)