Exemplo n.º 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)
Exemplo n.º 2
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))
Exemplo n.º 3
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}')
Exemplo n.º 4
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'