Пример #1
0
def open_big_cell():
    user = current_user
    pid = r.get(user.username + '_working_pid')
    assignment_id = pid + '-' + user.username

    pair_datafile = storage_model.get_pair_datafile(mongo=mongo,
                                                    user=user,
                                                    pid=pid)
    full_data = dl.load_data_from_csv(pair_datafile)
    working_data = dm.DataPairList(
        data_pairs=dl.load_data_from_csv(pair_datafile))
    assignment_status = storage_model.get_assignment_status(
        mongo=mongo, username=user.username, pid=pid)
    kapr_limit = float(assignment_status['kapr_limit'])

    id1 = request.args.get('id1')
    id2 = request.args.get('id2')
    id3 = request.args.get('id3')
    id4 = request.args.get('id4')
    mode = request.args.get('mode')

    pair_num1 = str(id1.split('-')[0])
    attr_num1 = str(id1.split('-')[2])
    ret1 = dm.open_cell(assignment_id, full_data, working_data, pair_num1,
                        attr_num1, mode, r, kapr_limit)
    pair_num2 = str(id3.split('-')[0])
    attr_num2 = str(id3.split('-')[2])
    ret2 = dm.open_cell(assignment_id, full_data, working_data, pair_num2,
                        attr_num2, mode, r, kapr_limit)

    if ret2['result'] == 'fail':
        return jsonify(ret2)

    ret = {
        'value1': ret1['value1'],
        'value2': ret1['value2'],
        'value3': ret2['value1'],
        'value4': ret2['value2'],
        'id': ret1['id'],
        'mode': ret2['mode'],
        'KAPR': ret2['KAPR'],
        'result': ret2['result'],
        'new_delta': ret2['new_delta']
    }

    log_data = {
        'username': user.username,
        'timestamp': time.time(),
        'url': '/get_big_cell',
        'pid': str(pid),
        'assignment_id': str(assignment_id),
        'log': json.dumps(ret)
    }
    storage_model.mlog(mongo=mongo, data=log_data)

    return jsonify(ret)
Пример #2
0
def open_cell():
    user = current_user
    pid = r.get(user.username + '_working_pid')
    assignment_id = pid + '-' + user.username
    is_rc = r.get(user.username + '_working_pid_rc')

    pair_datafile = storage_model.get_project_pair_datafile(mongo=mongo,
                                                            user=user,
                                                            pid=pid)
    working_data = dm.DataPairList(
        data_pairs=dl.load_data_from_csv(pair_datafile))
    project_pairfile = storage_model.get_project_pair_datafile(
        mongo=mongo, user=user.username, pid=pid)
    full_project_pairs = storage_model.get_total_pairs_from_pairfile(
        project_pairfile)
    working_data.set_kapr_size(full_project_pairs)
    full_data = dl.load_data_from_csv(project_pairfile)

    id1 = request.args.get('id1')
    id2 = request.args.get('id2')
    mode = request.args.get('mode')
    pair_num = str(id1.split('-')[0])
    attr_num = str(id1.split('-')[2])

    if is_rc != '1':
        assignment_status = storage_model.get_assignment_status(
            mongo=mongo, username=user.username, pid=pid)
        kapr_limit = float(assignment_status['kapr_limit'])
    # is resolve conflict
    if is_rc == '1':
        kapr_limit = 100

    ret = dm.open_cell(assignment_id, full_data, working_data, pair_num,
                       attr_num, mode, r, kapr_limit)

    log_data = {
        'username': user.username,
        'timestamp': time.time(),
        'url': '/get_cell',
        'pid': str(pid),
        'assignment_id': str(assignment_id),
        'log': json.dumps(ret)
    }
    storage_model.mlog(mongo=mongo, data=log_data)

    return jsonify(ret)
Пример #3
0
def record_linkage(pid):
    user = current_user

    # find if this project exist
    project = storage_model.get_assignment(mongo=mongo,
                                           username=user.username,
                                           pid=pid)
    if not project:
        return page_not_found('page_not_found')

    # username and project_id can identify an assignment
    assignment_id = pid + '-' + user.username

    # get assignment status
    assignment_status = storage_model.get_assignment_status(
        mongo=mongo, username=user.username, pid=pid)
    current_page = assignment_status['current_page']
    page_size = assignment_status['page_size']
    kapr_limit = assignment_status['kapr_limit']
    current_kapr = assignment_status['current_kapr']
    display_mode = assignment_status['display_mode']
    isfull = False
    if 'isfull' in assignment_status:
        isfull = assignment_status['isfull']
    if isfull == 'true':
        default_mode = 'B'
    else:
        default_mode = 'M'
    if current_page >= page_size:
        flask.flash('You have completed the project.', 'alert-success')
        return redirect(url_for('project'))

    # get working data and full data
    pair_datafile = storage_model.get_pair_datafile(mongo=mongo,
                                                    user=user,
                                                    pid=pid)
    indices, pair_idx = storage_model.get_current_block(mongo=mongo,
                                                        pid=pid,
                                                        assignee=user.username)
    working_data = dm.DataPairList(
        data_pairs=dl.load_data_from_csv(pair_datafile), indices=indices)
    project_pairfile = storage_model.get_project_pair_datafile(
        mongo=mongo, user=user.username, pid=pid)
    full_project_pairs = storage_model.get_total_pairs_from_pairfile(
        project_pairfile)
    working_data.set_kapr_size(full_project_pairs)
    full_data = dl.load_data_from_csv(project_pairfile)

    # prepare return data
    icons = working_data.get_icons()
    #print(icons)
    ids_list = working_data.get_ids()
    ids = list(zip(ids_list[0::2], ids_list[1::2]))
    data_mode = display_mode.lower()
    data_mode_list = storage_model.get_data_mode(assignment_id,
                                                 ids,
                                                 r=r,
                                                 data_mode=data_mode,
                                                 default_mode=default_mode)
    pairs_formatted = working_data.get_data_display(data_mode, data_mode_list)
    data = list(zip(pairs_formatted[0::2], pairs_formatted[1::2]))

    pair_ids = indices
    record_ids = storage_model.get_record_id_by_pair_id(mongo, pid, indices)

    # get the delta information
    delta = list()
    for i in range(working_data.size()):
        data_pair = working_data.get_data_pair_by_index(i)
        if data_pair is None:
            break
        delta += dm.KAPR_delta(full_data, data_pair, 11 * ['M'],
                               len(full_data))

    # prepare cache data for ajax query
    r.set(user.username + '_working_pid', pid)
    r.set(user.username + '_working_pid_rc', 0)
    KAPR_key = assignment_id + '_KAPR'
    r.set(KAPR_key, float(current_kapr))

    # get saved working answers
    answers = storage_model.get_working_answers(assignment_id, r)

    ret_data = {
        'data': data,
        'data_mode_list': data_mode_list,
        'icons': icons,
        'ids': ids,
        'record_ids': record_ids,
        'pair_ids': pair_ids,
        'title': project['project_name'],
        'kapr': round(100 * float(current_kapr), 1),
        'kapr_limit': float(kapr_limit),
        'page_number': current_page + 1,
        'page_size': page_size,
        'pair_num_base': pair_idx + 1,
        'delta': delta,
        'this_url': '/record_linkage/' + pid,
        'saved_answers': answers,
        'data_size': len(data),
        'isfull': isfull,
    }
    return render_template('record_linkage_ppirl.html', data=ret_data)