Exemplo n.º 1
0
def project_detail(pid):
    user = current_user
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)
    if not project:
        return page_not_found('page_not_found')
    if project['owner'] != user.username:
        return forbidden()

    assignee_stat = project['assignee_stat']
    pair_idx, total_pairs = 0, 0
    for assignee in assignee_stat:
        pair_idx += int(assignee['pair_idx'])
        total_pairs += int(assignee['total_pairs'])
        assignee_progress = int(assignee['pair_idx']) / int(
            assignee['total_pairs'])
        assignee_progress = round(100 * assignee_progress, 2)
        assignee['progress'] = assignee_progress
    progress = float(pair_idx) / total_pairs
    progress = round(100 * progress, 2)
    if progress > 100:
        progress = 100
    project['progress'] = progress

    indices = storage_model.detect_result_conflicts(mongo, pid)
    if len(indices) > 0:
        project['conflicts'] = 1
    else:
        project['conflicts'] = 0

    data = {'project': project}

    return render_template('project_detail.html', data=data)
Exemplo n.º 2
0
def new_blocking_save(pid):
    user = current_user
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)
    if not project:
        return page_not_found('page_not_found')
    if project['owner'] != user.username:
        return forbidden()

    form = BlockForm(formdata=request.form)

    if form.validate():
        data = form.data
        data['pid'] = pid
        data['owner'] = project['owner']
        data['project_name'] = project['project_name']
        result = storage_model.new_blocking(mongo=mongo, data=data)

        if not result:
            flask.flash('You have finished. No more blocking needed.',
                        'alert-success')
        else:
            flask.flash('New blocking has been processed.', 'alert-success')
    else:
        print(form.errors, "new blocking error")
    return redirect(url_for('project'))
Exemplo n.º 3
0
def update_project(pid):
    user = current_user

    #project_name = request.form['project_name']
    project_des = request.form['project_description']
    #assignee = request.form['assignto']
    #kapr_limit = request.form['privacy_budget']

    data = {
        'pid': pid,
        #'project_name': project_name,
        'project_des': project_des,
        #'assignee': assignee,
        #'kapr_limit': kapr_limit,
        'owner': user.username
    }

    # check if project name existed
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)
    #if project['project_name'] != data['project_name']:
    #    if storage_model.project_name_existed(mongo=mongo, data=data):
    #        flask.flash('project name existed.', 'alert-danger')
    #        return redirect(url_for('view_project', pid=pid))

    #if storage_model.is_invalid_kapr(mongo=mongo, data=data):
    #    current_kapr = storage_model.get_current_kapr(mongo=mongo, data=data)
    #    flask.flash('Kapr value is lower than the amount it has been used (%s%%).' % str(current_kapr), 'alert-danger')
    #    return redirect(url_for('view_project', pid=pid))

    storage_model.update_project_setting(mongo=mongo,
                                         user=user.username,
                                         data=data)

    flask.flash('Project update has been saved.', 'alert-success')
    return redirect(url_for('project'))
Exemplo n.º 4
0
def delete_project(pid):
    user = current_user
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)
    if not project:
        return page_not_found('page_not_found')
    if project['owner'] != user.username:
        return forbidden()

    storage_model.delete_project(mongo=mongo, pid=pid, username=user.username)

    flask.flash('Project has been deleted.', 'alert-success')

    return redirect(url_for('project_list'))
Exemplo n.º 5
0
def view_project(pid):
    user = current_user
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)
    if not project:
        return page_not_found('page_not_found')
    if project['owner'] != user.username:
        return forbidden()

    data = {'project': project}

    all_users = storage_model.get_all_users(mongo=mongo)
    user_list = [(u['username'], u['username']) for u in all_users]

    return render_template('viewProject.html', data=data)
Exemplo n.º 6
0
def get_file(pid):
    """Download a file."""
    user = current_user
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)
    if not project:
        return page_not_found('page_not_found')
    if project['owner'] != user.username:
        return forbidden()

    path = storage_model.get_result_path(mongo=mongo, pid=pid)
    return send_from_directory('',
                               path,
                               as_attachment=True,
                               attachment_filename='result.csv')
Exemplo n.º 7
0
def new_blocking(pid):
    user = current_user
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)
    if not project:
        return page_not_found('page_not_found')
    if project['owner'] != user.username:
        return forbidden()

    all_users = storage_model.get_all_users(mongo=mongo)
    user_list = [u['username'] for u in all_users]

    data = {'project': project, 'users': user_list}

    form = BlockForm()

    return render_template('newBlocking.html', data=data, form=form)
Exemplo n.º 8
0
def get_file(pid):
    """Download a file."""
    user = current_user
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)
    if not project:
        return page_not_found('page_not_found')
    if project['owner'] != user.username:
        return forbidden()

    path = storage_model.get_result_path(mongo=mongo, pid=pid)
    result_file_name = '%s_result.csv' % project['project_name']
    #filename = path.split('/')[-1]
    filename = os.path.split(path)[-1]
    return send_from_directory(os.path.join('data', 'internal'),
                               filename,
                               as_attachment=True,
                               attachment_filename=result_file_name)
Exemplo n.º 9
0
def create_resolve_conflict_project(pid):
    project = storage_model.get_project_by_pid(mongo, pid)
    owner = project['owner']

    assignment_id = pid + '-' + owner
    # get pair_num of conflicts
    conflict_indices = storage_model.detect_result_conflicts(mongo, pid)

    # get block information of the project
    project = storage_model.get_project_by_pid(mongo=mongo, pid=pid)

    # arrange conflict pairs by block
    block_id = project['block_id']

    # arrange pairs by block id
    conflicts = list()
    for block in block_id:
        cur_block = list()
        for idx in conflict_indices:
            if idx in block:
                cur_block.append(idx)
        if cur_block:
            conflicts.append(cur_block)

    # simulate open cells for those opened by assignees
    pair_datafile = storage_model.get_pair_datafile_by_owner(mongo=mongo,
                                                             owner=owner,
                                                             pid=pid)
    working_data = dm.DataPairList(
        data_pairs=dl.load_data_from_csv(pair_datafile),
        indices=conflict_indices)
    project_pairfile = storage_model.get_project_pair_datafile(mongo=mongo,
                                                               user=owner,
                                                               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)

    KAPR_key = assignment_id + '_KAPR'
    r.set(KAPR_key, 0.0)

    ids_list = working_data.get_ids()
    ids = list(zip(ids_list[0::2], ids_list[1::2]))
    data_mode_list = storage_model.get_conflict_data_mode(
        pid, ids, mongo, r, assignment_id)
    dm.batched_open_cell(assignment_id,
                         full_data,
                         working_data,
                         ids,
                         data_mode_list,
                         r,
                         kapr_limit=100)

    KAPR_key = assignment_id + '_KAPR'
    current_kapr = r.get(KAPR_key)

    result_path = os.path.join(
        config.DATA_DIR, 'internal', project['owner'] + '_' +
        project['project_name'] + '_conflict_result.csv')
    # create result file
    f = open(result_path, 'w+')
    f.close()

    isfull = storage_model.has_full_assignee(mongo, pid)

    conflict_project = {
        'pid': pid,
        'project_name': project['project_name'],
        'pair_num': conflicts,
        'current_page': 0,
        'page_size': len(conflicts),
        'kapr_limit': 100,
        'current_kapr': current_kapr,
        'pair_idx': 0,
        'total_pairs': len(conflict_indices),
        'result_path': result_path,
        'isfull': isfull,
    }

    storage_model.save_conflict_project(mongo, conflict_project)

    return 'block_id'