Exemplo n.º 1
0
    def update_database_results(self, session):
        """Update the database with the results of ramp_test_submission."""
        make_update_leaderboard = False
        while not self._processed_submission_queue.empty():
            make_update_leaderboard = True
            submission_id, submission_name = \
                self._processed_submission_queue.get_nowait()
            if 'error' in get_submission_state(session, submission_id):
                continue
            logger.info('Write info in database for submission {}'.format(
                submission_name))
            path_predictions = os.path.join(
                self._worker_config['predictions_dir'], submission_name)
            # NOTE: In the past we were adding the predictions into the
            # database. Since they require too much space, we stop to store
            # them in the database and instead, keep it onto the disk.
            # set_predictions(session, submission_id, path_predictions)
            set_time(session, submission_id, path_predictions)
            set_scores(session, submission_id, path_predictions)
            set_bagged_scores(session, submission_id, path_predictions)
            set_submission_state(session, submission_id, 'scored')

        if make_update_leaderboard:
            logger.info('Update all leaderboards')
            update_leaderboards(session, self._ramp_config['event_name'])
            update_all_user_leaderboards(session,
                                         self._ramp_config['event_name'])
Exemplo n.º 2
0
 def update_database_results(self, session):
     """Update the database with the results of ramp_test_submission."""
     while not self._processed_submission_queue.empty():
         submission_id, submission_name = \
             self._processed_submission_queue.get_nowait()
         if 'error' in get_submission_state(session, submission_id):
             update_leaderboards(session, self._ramp_config['event_name'])
             update_all_user_leaderboards(session,
                                          self._ramp_config['event_name'])
             logger.info('Skip update for {} due to failure during the '
                         'processing'.format(submission_name))
             continue
         logger.info('Update the results obtained on each fold for '
                     '{}'.format(submission_name))
         path_predictions = os.path.join(
             self._worker_config['predictions_dir'], submission_name
         )
         set_predictions(session, submission_id, path_predictions)
         set_time(session, submission_id, path_predictions)
         set_scores(session, submission_id, path_predictions)
         set_bagged_scores(session, submission_id, path_predictions)
         set_submission_state(session, submission_id, 'scored')
         update_leaderboards(session, self._ramp_config['event_name'])
         update_all_user_leaderboards(session,
                                      self._ramp_config['event_name'])
Exemplo n.º 3
0
def toggle_competition(submission_hash):
    """Pulling out or putting a submission back into competition.

    Parameters
    ----------
    submission_hash : str
        The submission hash of the current submission.
    """
    submission = (Submission.query.filter_by(
        hash_=submission_hash).one_or_none())
    if submission is None:
        error_str = 'Missing submission: {}'.format(submission_hash)
        return redirect_to_user(error_str)

    access_code = is_accessible_code(db.session,
                                     submission.event_team.event.name,
                                     flask_login.current_user.name,
                                     submission.id)
    if not access_code:
        error_str = 'Missing submission: {}'.format(submission_hash)
        return redirect_to_user(error_str)

    submission.is_in_competition = not submission.is_in_competition
    db.session.commit()
    update_leaderboards(db.session, submission.event_team.event.name)
    return redirect('/{}/{}'.format(submission_hash,
                                    submission.files[0].f_name))
Exemplo n.º 4
0
    def update_database_results(self, session):
        """Update the database with the results of ramp_test_submission."""
        make_update_leaderboard = False
        while not self._processed_submission_queue.empty():
            make_update_leaderboard = True
            submission_id, submission_name = \
                self._processed_submission_queue.get_nowait()
            if 'error' in get_submission_state(session, submission_id):
                continue
            logger.info('Write info in data base for submission {}'.format(
                submission_name))
            path_predictions = os.path.join(
                self._worker_config['predictions_dir'], submission_name)
            set_predictions(session, submission_id, path_predictions)
            set_time(session, submission_id, path_predictions)
            set_scores(session, submission_id, path_predictions)
            set_bagged_scores(session, submission_id, path_predictions)
            set_submission_state(session, submission_id, 'scored')

        if make_update_leaderboard:
            logger.info('Update all leaderboards')
            update_leaderboards(session, self._ramp_config['event_name'])
            update_all_user_leaderboards(session,
                                         self._ramp_config['event_name'])
Exemplo n.º 5
0
def test_update_leaderboard_functions(session_toy_function):
    event_name = 'iris_test'
    user_name = 'test_user'
    for leaderboard_type in ['public', 'private', 'failed',
                             'public competition', 'private competition']:
        leaderboard = get_leaderboard(session_toy_function, leaderboard_type,
                                      event_name)
        assert leaderboard is None
    leaderboard = get_leaderboard(session_toy_function, 'new', event_name)
    assert leaderboard

    event = get_event(session_toy_function, event_name)
    assert event.private_leaderboard_html is None
    assert event.public_leaderboard_html_with_links is None
    assert event.public_leaderboard_html_no_links is None
    assert event.failed_leaderboard_html is None
    assert event.public_competition_leaderboard_html is None
    assert event.private_competition_leaderboard_html is None
    assert event.new_leaderboard_html

    event_team = get_event_team_by_name(session_toy_function, event_name,
                                        user_name)
    assert event_team.leaderboard_html is None
    assert event_team.failed_leaderboard_html is None
    assert event_team.new_leaderboard_html

    event_teams = (session_toy_function.query(EventTeam)
                                       .filter_by(event=event)
                                       .all())
    for et in event_teams:
        assert et.leaderboard_html is None
        assert et.failed_leaderboard_html is None
        assert et.new_leaderboard_html

    # run the dispatcher to process the different submissions
    config = read_config(database_config_template())
    event_config = read_config(ramp_config_template())
    dispatcher = Dispatcher(
        config, event_config, n_workers=-1, hunger_policy='exit'
    )
    dispatcher.launch()
    session_toy_function.commit()

    update_leaderboards(session_toy_function, event_name)
    event = get_event(session_toy_function, event_name)
    assert event.private_leaderboard_html
    assert event.public_leaderboard_html_with_links
    assert event.public_leaderboard_html_no_links
    assert event.failed_leaderboard_html
    assert event.public_competition_leaderboard_html
    assert event.private_competition_leaderboard_html
    assert event.new_leaderboard_html is None

    update_user_leaderboards(session_toy_function, event_name, user_name)
    event_team = get_event_team_by_name(session_toy_function, event_name,
                                        user_name)
    assert event_team.leaderboard_html
    assert event_team.failed_leaderboard_html
    assert event_team.new_leaderboard_html is None

    update_all_user_leaderboards(session_toy_function, event_name)
    event_teams = (session_toy_function.query(EventTeam)
                                       .filter_by(event=event)
                                       .all())
    for et in event_teams:
        assert et.leaderboard_html
        assert et.failed_leaderboard_html
        assert et.new_leaderboard_html is None