Ejemplo n.º 1
0
def get_completeness():
    COURSE = get_collection('course')
    COLLECTION = get_collection('collection')
    FOCUS = get_collection('focus')

    result = COLLECTION.find({'usr': g.usr['usr']})
    json_body = {}
    for i, course in enumerate(result):
        course_id = course['id']
        course_focus = FOCUS.find_one({'id': course_id, 'usr': g.usr['usr']})
        course_content = COURSE.find_one({'id': course_id})
        json_body[i] = course_content
        json_body[i]['complete'] = calcu_focus_completeness(course_focus)
        json_body[i].pop('_id')
    return jsonify(json_body)
Ejemplo n.º 2
0
def get_usr_info():
    MEMBER = get_collection('member')

    result = MEMBER.find_one({'usr': g.usr['usr']})
    result.pop('_id')
    result.pop('pic')
    return jsonify(result)
Ejemplo n.º 3
0
def get_usr_pic():
    MEMBER = get_collection('member')

    result = MEMBER.find_one({'usr': g.usr['usr']})
    response = make_response(result['pic'])
    response.headers.set('Content-Type', 'image/png')
    return response
Ejemplo n.º 4
0
def add_focus():
    FOCUS = get_collection('focus')

    result_filter = {
        'usr': g.usr['usr'],
        'id': request.args.get('course_id')  # course_id
    }
    c_time = str(math.floor(float(request.args.get('time'))))
    document = result_filter.copy()
    document['rate'] = 1.0
    document['emotion'] = {}
    document['emotion'][c_time] = {
        'anger': float(request.args.get('anger')),
        'disgust': float(request.args.get('disgust')),
        'fear': float(request.args.get('fear')),
        'happiness': float(request.args.get('happiness')),
        'neutral': float(request.args.get('neutral')),
        'sadness': float(request.args.get('sadness')),
        'surprise': float(request.args.get('surprise')),
        'vector_x': abs(float(request.args.get('vector_x'))),
        'vector_y': abs(float(request.args.get('vector_y'))),
        'vector_z': float(request.args.get('vector_z')),
        'position_x': float(request.args.get('position_x')),
        'position_y': float(request.args.get('position_y'))
    }
    result = FOCUS.find_one(result_filter)
    if result:  # 已经有了
        result['emotion'][c_time] = document['emotion'][c_time]
        FOCUS.replace_one(result_filter, result)
    else:
        FOCUS.insert_one(document)
    return 'Success!'
Ejemplo n.º 5
0
def get_avg_focus():
    """
        每个老师获取特定课程的平均专注度
    """
    FOCUS = get_collection('focus')

    result = FOCUS.find({'id': request.args.get('course_id')})
    if result:
        json_body = {}
        all_weight = 0.0
        for focus in result:
            weight = focus['rate']
            all_weight += weight
            for i in range(0, 600):
                if str(i) in focus['emotion']:
                    if str(i) in json_body:
                        json_body[str(i)] += calcu_focus(
                            focus['emotion'][str(i)]) * weight
                    else:
                        json_body[str(i)] = calcu_focus(
                            focus['emotion'][str(i)]) * weight

        for i in range(0, 600):
            if str(i) in json_body:
                json_body[str(i)] /= all_weight

        return jsonify(json_body)
    else:
        return 'None'
Ejemplo n.º 6
0
def get_comment():
    COMMENT = get_collection('comment')

    result = COMMENT.find({'id': request.args.get('id')})
    json_body = {}
    for i, comment in enumerate(result):
        json_body[i] = comment
        json_body[i].pop('_id')
    return jsonify(json_body)
Ejemplo n.º 7
0
def rate():
    FOCUS = get_collection('focus')

    result_filter = {'usr': g.usr['usr'], 'id': request.args.get('course_id')}
    result = FOCUS.find_one(result_filter)
    if result:
        result['rate'] = int(request.args.get('rate')) / 5
        FOCUS.replace_one(result_filter, result)

    return 'Success!'
Ejemplo n.º 8
0
def add_comment():
    COMMENT = get_collection('comment')

    document = {
        'id': request.args.get('id'),
        'startTime': request.args.get('startTime'),
        'endTime': request.args.get('endTime'),
        'content': request.args.get('content')
    }
    COMMENT.insert_one(document)
    return 'Success!'
Ejemplo n.º 9
0
def update_usr_pwd():
    MEMBER = get_collection('member')

    result = MEMBER.find_one({'usr': g.usr['usr']})
    pwd = request.args.get('pwd')
    if pwd != '':
        result['pwd'] = pwd

    MEMBER.replace_one({'usr': g.usr['usr']}, result)

    return 'Success!'
Ejemplo n.º 10
0
def load_logged_in_user():
    usr_id = session.get('usr')

    if usr_id is None:
        g.usr = None
    else:
        MEMBER = get_collection('member')

        result = MEMBER.find_one({'usr': usr_id})
        result.pop('pwd')
        g.usr = result
Ejemplo n.º 11
0
def sign_in():
    result_filter = {'usr': request.form['usr'], 'pwd': request.form['pwd']}
    MEMBER = get_collection('member')

    result = MEMBER.find_one(result_filter)
    if result:
        session.clear()  # What is a session? And how does cookie work in this?
        session['usr'] = result['usr']
        return jsonify(status=True, role=result['role'])
    else:
        return jsonify(status=False)
Ejemplo n.º 12
0
def update_usr_info():
    MEMBER = get_collection('member')

    result = MEMBER.find_one({'usr': g.usr['usr']})
    pwd = request.form['pwd']
    if pwd != '':
        result['pwd'] = pwd
    image = request.files['file']
    result['pic'] = base64.encodestring(image.read())
    MEMBER.replace_one({'usr': g.usr['usr']}, result)

    return 'Success!'
Ejemplo n.º 13
0
def get_focus():
    """
        每个学生获取自己的专注度
    """
    FOCUS = get_collection('focus')

    result_filter = {'usr': g.usr['usr'], 'id': request.args.get('course_id')}
    result = FOCUS.find_one(result_filter)
    if result:
        json_body = {}
        for i in range(0, 600):
            if str(i) in result['emotion']:
                json_body[str(i)] = calcu_focus(result['emotion'][str(i)])
        return jsonify(json_body)
    else:
        return 'None'
Ejemplo n.º 14
0
def sign_up():
    MEMBER = get_collection('member')

    result = MEMBER.find_one({'usr': request.form['usr']})
    if result:
        return 'Taken'
    else:
        image = request.files['file']
        document = {
            'usr': request.form['usr'],
            'pwd': request.form['pwd'],
            'role': request.form['role'],
            'date': str(datetime.date.today()),
            'pic': base64.encodestring(image.read())
        }
        MEMBER.insert_one(document)
        return 'Success!'