Exemple #1
0
def tower():
    email = get_email_from_request()
    project_name = get_current_project()
    if not DBProxy.user_has_signed_consent(email, project_name):
        return consent_form(admin=True)

    proxy_id = DBProxy.get_proxy_id(project_name=project_name)
    project_proxy = DBProxy.get_proxy(proxy_id, database_model=False)

    project_model = DBProxy.get_project(project_name=project_name)

    def time_left(expiration_time):
        time_seconds = expiration_time - time.time()
        seconds = int(time_seconds % 60)
        minutes = floor(time_seconds / 60)
        return f'{minutes} minute{("" if minutes == 1 else "s")}, ' \
               f'{seconds} second{("" if seconds == 1 else "s")}'

    roundList = DBProxy.get_round_list(project_name)
    checked_out = [
        x for x in roundList
        if (x.checked_out and x.expiration_time > time.time())
    ]
    active_judges = {x.user_checked_out_by for x in checked_out}

    return render_template('tower.html',
                           project_proxy=project_proxy,
                           time_left=time_left,
                           project_model=project_model,
                           roundList=roundList,
                           checked_out=checked_out,
                           active_judges=active_judges)
Exemple #2
0
def sign_consent():
    email = get_email_from_request()
    project_name = request.form.get('project_name')
    admin = request.form.get('admin')
    DBProxy.sign_consent_form(email, project_name)
    if admin == 'True':
        return redirect(url_for('tower'))
    return redirect(url_for('sorter'))
Exemple #3
0
def sorted():
    project_name = get_current_project()
    proxy_id = DBProxy.get_proxy_id(project_name)
    project_proxy = DBProxy.get_proxy(proxy_id, database_model=False)
    return render_template(
        'sorted.html',
        project_proxy=project_proxy,
        project_model=DBProxy.get_project(project_name=project_name))
Exemple #4
0
def update_project_info(name, description, selection_prompt, preferred_prompt,
                        unpreferred_prompt, consent_form, landing_page):
    project = DBProxy.get_project(project_name=name)
    if project is None:
        return False
    DBProxy.delete_all_consents_from_project(project_name=name)
    return DBProxy.update_project(name, description, selection_prompt,
                                  preferred_prompt, unpreferred_prompt,
                                  consent_form, landing_page)
Exemple #5
0
def remove_self():
    email = get_email_from_request()
    project_name = request.form.get('project_name')
    print(f'remove {email} from {project_name}')
    DBProxy.remove_user_from_project(email, project_name=project_name)
    current_project = get_current_project()
    res = redirect(url_for('dashboard'))
    if project_name == current_project:
        res.set_cookie('current_project', '', max_age=0)
    return res
Exemple #6
0
def join_code():
    project_name = request.form.get('project_name')
    join_code = request.form.get('join_code')
    if not DBProxy.verify_join_code(project_name, join_code):
        flash('invalid project name or join code', 'warning')
        return redirect(url_for('dashboard'))
    email = get_email_from_request()
    DBProxy.add_user_to_project(email, project_name=project_name)
    flash(f'added project {project_name}', 'success')
    return redirect(url_for('dashboard'))
Exemple #7
0
def is_in_admin_file(email):
    with open(ADMIN_PATH, mode='r') as f:
        admins = f.read().split('\n')
    adminBool = False
    for admin in admins:
        if admin == email:
            adminBool = True
            break
    if adminBool:
        for project in DBProxy.get_all_projects():
            DBProxy.add_user_to_project(email, project.id)
    return adminBool
Exemple #8
0
def postLoadUser(email, cid):
    # Set user admin if needed
    if is_in_admin_file(email):
        DBProxy.set_user_as_admin(email, True)
    else:
        DBProxy.set_user_as_admin(email, False)

    cookies = {'email': email, 'cid': cid}
    encrypted_cookies = cookie_crypter.encrypt(cookies)
    res = make_response(redirect(url_for('dashboard')))
    res.set_cookie('email', encrypted_cookies['email'])
    res.set_cookie('cid', encrypted_cookies['cid'])
    return res
Exemple #9
0
def hard_easy():
    email = get_email_from_request()
    project = get_current_project()
    doc1_id = request.form.get('file_one_id')
    doc2_id = request.form.get('file_two_id')
    pair_id = request.form.get('pair_id')
    DBProxy.add_doc_pair_reject(judge_id=DBProxy.get_judge_id(email),
                                email=email,
                                project_name=project,
                                doc1_id=doc1_id,
                                doc2_id=doc2_id,
                                doc_pair_id=pair_id)
    DBProxy.return_pair(pair_id, too_hard=True)
    return redirect(url_for('sorter'))
 def wrapper(*args, **kwargs):
     email = request.cookies.get('email', None)
     project = request.cookies.get('current_project', None)
     if not DBProxy.verify_user_in_project(email, project_name=project):
         return redirect(url_for('dashboard'))
     else:
         # print("you're ok")
         return fn(*args, **kwargs)
Exemple #11
0
def returninguser(email):
    # admins = []
    # db_user_id = DBProxy.get_user(email)
    # email = DBProxy.get_email(db_user_id)
    # isInAdminFile(email)
    # isInPMFile(email)
    cid = DBProxy.get_user_cid(email)
    return postLoadUser(email, cid)
Exemple #12
0
def load_user(email):
    print(f'In load_user with {email}')
    # username = user.username
    if DBProxy.is_user_exists(email):
        # User already in database
        return returninguser(email)
    # New user
    return newuser(email)
Exemple #13
0
def process_doc_pairs(proxy, proxy_id):
    logging.info('in process_doc_pairs')
    project_id = DBProxy.get_project_id(proxy.project_name)
    all_pairs = DBProxy.get_completed_doc_pairs(project_id)
    if len(all_pairs) < len(proxy.get_round_list()):
        return 'not all pairs have been judged yet'
    # Submit all comparisons to proxy
    for pair in all_pairs:
        print(f'sending comparison for {pair}')
        if pair.doc1_id == pair.preferred_id:
            proxy.make_comparison(pair.doc1_id, pair.doc2_id)
        elif pair.doc2_id == pair.preferred_id:
            proxy.make_comparison(pair.doc1_id, pair.doc2_id)
        else:
            raise KeyError('docpair marked complete without indicating preferred_id')
    # DBProxy.update_proxy(proxy_id, proxy=proxy)
    DBProxy.delete_doc_pairs(project_id)
Exemple #14
0
def submit_answer():
    pair_id = request.form.get('pair_id')
    preferred_doc_id = request.form.get('preferred')
    pair_submitted = DBProxy.submit_doc_pair(pair_id=pair_id,
                                             preferred_doc_id=preferred_doc_id)
    email = get_email_from_request()
    judge_id = DBProxy.get_judge_id(email)
    unpreferred_doc_id = request.form.get('unpreferred')
    time_started = int(request.form.get('time_started'))
    proxy_id = DBProxy.get_sorting_proxy_id(get_current_project())
    preferred_doc_name = DBProxy.get_doc_name(preferred_doc_id)
    unpreferred_doc_name = DBProxy.get_doc_name(unpreferred_doc_id)
    DBProxy.make_comparison(judge_id=judge_id,
                            preferred_doc_name=preferred_doc_name,
                            unpreferred_doc_name=unpreferred_doc_name,
                            duration=floor(time.time()) - time_started,
                            sorting_proxy_id=proxy_id,
                            used_in_sorting=pair_submitted,
                            project_name=get_current_project())
    if request.form.get('admin') == 'True':
        return redirect(url_for('tower'))
    if isinstance(request.form.get('another_pair_checkbox'), type(None)):
        # flash('Judgment submitted', 'success')
        return redirect(url_for('instructions'))
    else:
        return redirect(url_for('sorter'))
 def wrapper(*args, **kwargs):
     # print("checking login ..............................................................")
     email = request.cookies.get('email', None)
     cid = request.cookies.get('cid', None)
     if not DBProxy.verify_login(email, cid):
         return redirect(url_for('home'))
     else:
         # print("you're ok")
         return fn(*args, **kwargs)
Exemple #16
0
def edit_project():
    project_name = request.form.get('project_name_edit', None)
    if project_name is None:
        flash('project not found', 'warning')
        return redirect(url_for('dashboard'))
    project = DBProxy.get_project(project_name=project_name)
    if project is None:
        flash('project not found', 'warning')
        return redirect(url_for('dashboard'))
    return render_template('editproject.html', project=project)
Exemple #17
0
def select_project():
    project_name = request.form.get('project_name')
    email = get_email_from_request()
    if not DBProxy.verify_user_in_project(email, project_name=project_name):
        flash(f'unable to select project {project_name}', 'warning')
        return redirect(url_for('dashboard'))
    return_page = request.form.get('return_page', False)
    if return_page:
        res = redirect(return_page)
    else:
        res = redirect(url_for('instructions'))
    res.set_cookie('current_project', project_name)
    return res
Exemple #18
0
def create_project(name, sorting_algorithm_name, public, join_code,
                   description, files):

    # Identify selected sorting algorithm
    target_algorithm = None
    for algorithm in pairselector_options:
        if sorting_algorithm_name == algorithm.get_algorithm_name():
            target_algorithm = algorithm
            break
    if target_algorithm is None:
        return f'sorting algorithm \'{sorting_algorithm_name}\' not found', 'warning'

    # Create project entry in database
    project_id = DBProxy.add_project(name=name,
                                     sorting_algorithm=sorting_algorithm_name,
                                     number_of_docs=0,
                                     public=public,
                                     join_code=join_code,
                                     description=description)

    if not project_id:
        return 'project name already used', 'warning'

    # Insert files into database
    file_ids = DBProxy.insert_files(files, project_id)

    # Create algorithm proxy for project
    project_proxy = target_algorithm(name)
    project_proxy.initialize_selector(file_ids)

    # Fill docpairs table in database
    PairSelector.turn_over_round(project_proxy)
    print(f'populating docpairs with: {project_proxy.roundList}')
    PairSelector.populate_doc_pairs(project_proxy)

    # Insert proxy into database
    proxy_id = DBProxy.add_proxy(project_proxy, name)
    print(f'new proxy roundList: {project_proxy.roundList}')

    # Update project in database with new info
    DBProxy.add_num_docs_to_project(project_id, len(file_ids))
    DBProxy.add_sorting_algorithm_id_to_project(project_id, proxy_id)

    f'added project {name} with {len(file_ids)} docs'

    test_proxy = DBProxy.get_proxy(proxy_id, database_model=False)
    print(f'new proxy from db: {test_proxy.roundList}')

    return f'created project {name}', 'success'
Exemple #19
0
def add_project():
    # Get data from form
    project_name = request.form.get('project_name')
    if ' ' in project_name:
        flash('project name may not contain spaces', 'warning')
        return redirect(url_for('dashboard'))
    sorting_algorithm_name = request.form.get('selector_algorithm')
    public = (True if request.form.get('public') == 'on' else False)
    join_code = request.form.get('join_code')
    description = request.form.get('description')
    message, status = ProjectHandler.create_project(
        name=project_name,
        sorting_algorithm_name=sorting_algorithm_name,
        public=public,
        join_code=join_code,
        description=description,
        files=request.files.getlist("file"),
    )
    if status == 'success':
        DBProxy.add_user_to_project(email=get_email_from_request(),
                                    project_name=project_name)
    flash(message, status)
    return redirect(url_for('dashboard'))
Exemple #20
0
def sorter(admin=False, pair_id=None):
    email = get_email_from_request()
    project_name = get_current_project()
    if not DBProxy.user_has_signed_consent(email, project_name):
        return redirect(url_for('consent_form'))
    project = DBProxy.get_project(project_name=project_name)
    if not admin:
        pair, success_code = PairSelector.get_pair(project_name, email)
    else:
        pair, success_code = DBProxy.check_out_pair_by_id(pair_id, email)
    if success_code == 1:
        flash('no pair currently available', 'warning')
        return render_template('instructions.html')
    if success_code == 2:
        ProjectHandler.start_new_round(project_name)
        return redirect(url_for('sorter'))
    if success_code == 3:
        flash('project not found', 'warning')
        return redirect(url_for('dashboard'))
    if success_code == 4:
        flash('user not found', 'warning')
        return redirect(url_for('home'))
    if success_code == 5:
        flash('pair not found', 'warning')
        return redirect(url_for('tower'))
    file_one_contents = DBProxy.get_doc_contents(pair.doc1_id)
    file_two_contents = DBProxy.get_doc_contents(pair.doc2_id)
    return render_template('sorter.html',
                           pair_id=pair.id,
                           file_one_id=pair.doc1_id,
                           file_two_id=pair.doc2_id,
                           project=project,
                           time_started=floor(time.time()),
                           timeout=120 * 1000,
                           file_one=file_one_contents,
                           file_two=file_two_contents,
                           admin=admin)
Exemple #21
0
def start_new_round(project_name):
    proxy_id = DBProxy.get_sorting_proxy_id(project_name)
    proxy = DBProxy.get_proxy(proxy_id)
    print(f'old round: {proxy.roundList}')
    PairSelector.process_doc_pairs(proxy, proxy_id)
    PairSelector.turn_over_round(proxy)
    DBProxy.clear_doc_pair_rejects(project_name)
    PairSelector.populate_doc_pairs(proxy)
    DBProxy.update_proxy(proxy_id, proxy=proxy)
    print(f'new round: {proxy.roundList}')
Exemple #22
0
def createnewuser():
    email = request.form.get('email', None)
    if email is None:
        return redirect(url_for('home'))
    # Validate first/last names
    first_name = request.form.get('firstName')
    if ' ' in first_name:
        flash('names may not contain any spaces', 'danger')
        return newuser(email)
    last_name = request.form.get('lastName')
    if ' ' in last_name:
        flash('names may not contain any spaces', 'danger')
        return newuser(email)
    cid = DBProxy.create_user(request.form.get('firstName'),
                              request.form.get('lastName'), email)
    return postLoadUser(email, cid)
Exemple #23
0
def delete_project(project_name):
    # Get the project id
    project_id = DBProxy.get_project_id(project_name)
    if project_id is None:
        return 'project not found', 'warning'

    # Delete sorting proxy and logs
    DBProxy.delete_sorting_proxy(project_name=project_name)

    # Delete doc pairs
    DBProxy.delete_doc_pairs(project_id)

    # Delete project itself
    DBProxy.delete_project(project_id)

    return f'project {project_name} deleted', 'success'
Exemple #24
0
def dashboard():
    # Renders admin or user dashboards, depending on admin privileges of user
    if DBProxy.check_admin(get_email_from_request()):
        all_users = DBProxy.get_all_judges()  # All judges in the system
        all_group_projects = DBProxy.get_all_group_projects(
        )  # All non-public projects
        public_projects = DBProxy.get_all_public_projects(
        )  # All public projects
        return render_template(
            'admindashboard.html',
            all_users=all_users,
            all_group_projects=all_group_projects,
            public_projects=public_projects,
            selector_algorithms=pairselector_options,
        )
    # Not admin, render user dashboard
    judge = DBProxy.get_judge(request.cookies.get('email'))
    all_public_projects = DBProxy.get_all_public_projects()
    filtered_public_projects = [
        p for p in all_public_projects if judge not in p.judges
    ]
    return render_template('userdashboard.html',
                           filtered_public_projects=filtered_public_projects)
Exemple #25
0
def instructions():
    project_name = request.cookies.get('current_project')
    project = DBProxy.get_project(project_name=project_name)
    return render_template('instructions.html',
                           landing_page=project.landing_page)
Exemple #26
0
def force_return():
    pair_id = request.form.get('pair_id')
    DBProxy.return_pair(pair_id)
    return redirect(url_for('tower'))
Exemple #27
0
def consent_form(admin=False):
    project_name = request.cookies.get('current_project')
    project = DBProxy.get_project(project_name=project_name)
    return render_template('consentform.html',
                           consent_form_text=project.consent_form,
                           admin=admin)
Exemple #28
0
def safe_exit():
    pair_id = request.form.get('pair_id')
    DBProxy.return_pair(pair_id)
    return redirect(url_for('instructions'))
Exemple #29
0
def get_judge():
    judge = DBProxy.get_judge(get_email_from_request())
    if judge is None:
        return dummy_judge
    return judge
Exemple #30
0
def add_public_project():
    project_name = request.form.get('project_name')
    email = get_email_from_request()
    DBProxy.add_user_to_project(email, project_name=project_name)
    return redirect(url_for('dashboard'))