How to use the ramp-database.ramp_database.tools._query.select_event_by_name function in ramp-database

To help you get started, we’ve selected a few ramp-database examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / event.py View on Github external
def delete_event(session, event_name):
    """Delete an event from the database.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The name of the event to delete.
    """
    event = select_event_by_name(session, event_name)
    submissions = select_submissions_by_state(session, event_name, state=None)
    for sub in submissions:
        delete_submission_similarity(session, sub.id)
    session.delete(event)
    session.commit()
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / team.py View on Github external
The session to directly perform the operation on the database.
    event_name : str
        The RAMP event name.
    team_name : str
        The name of the team.

    Returns
    -------
    event : :class:`ramp_database.model.Event`
        The queried Event.
    team : :class:`ramp_database.model.Team`
        The queried team.
    event_team : :class:`ramp_database.model.EventTeam`
        The relationship event-team table.
    """
    event = select_event_by_name(session, event_name)
    team = select_team_by_name(session, team_name)
    event_team = select_event_team_by_name(session, event_name, team_name)
    if event_team is None:
        event_team = EventTeam(event=event, team=team)
        session.add(event_team)
        session.commit()
    return event, team, event_team
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / frontend.py View on Github external
def is_admin(session, event_name, user_name):
    """Whether or not a user is administrator or administrate an event.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The event name.
    user_name : str
        The user name.
    """
    event = select_event_by_name(session, event_name)
    user = select_user_by_name(session, user_name)
    if user.access_level == 'admin':
        return True
    event_admin = select_event_admin_by_instance(session, event, user)
    if event_admin is None:
        return False
    return True
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / event.py View on Github external
ramp_submissions_path : str
        Path to the deployment RAMP submissions directory. It will corresponds
        to the key `ramp_submissions_dir` of the dictionary created with
        :func:`ramp_utils.generate_ramp_config`.
    is_public : bool, default is False
        Whether the event is made public or not.
    force : bool, default is False
        Whether to overwrite an existing event. If ``false=False``, an error
        will be raised.

    Returns
    -------
    event : Event
        The event which has been registered in the database.
    """
    event = select_event_by_name(session, event_name)
    if event is not None:
        if not force:
            raise ValueError("Attempting to overwrite existing event. "
                             "Use force=True to overwrite.")
        delete_event(session, event_name)

    event = Event(name=event_name, problem_name=problem_name,
                  event_title=event_title,
                  ramp_sandbox_name=ramp_sandbox_name,
                  path_ramp_submissions=ramp_submissions_path,
                  session=session)
    event.is_public = is_public
    event.is_send_submitted_mails = False
    event.is_send_trained_mails = False
    logger.info('Adding {}'.format(event))
    session.add(event)
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / submission.py View on Github external
def get_event_nb_folds(session, event_name):
    """Get the number of fold for a given event.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The event name.

    Returns
    -------
    nb_folds : int
        The number of folds for a specific event.
    """
    event = select_event_by_name(session, event_name)
    return len(event.cv_folds)
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / submission.py View on Github external
all these kits at once for a specific user.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The name of the event.
    team_name : str
        The name of the team.
    path_submission : str
        The path of the files associated to the current submission. It will
        corresponds to the key `ramp_kit_submissions_dir` of the dictionary
        created with :func:`ramp_utils.generate_ramp_config`.
    """
    event = select_event_by_name(session, event_name=event_name)
    submission_names = os.listdir(path_submission)
    # we temporary bypass the limit time between two submissions
    min_duration_between_submissions = event.min_duration_between_submissions
    event.min_duration_between_submissions = 0
    for submission_name in submission_names:
        from_submission_path = os.path.join(path_submission, submission_name)
        # one of the starting kit is usually used a sandbox and we need to
        # change the name to not have any duplicate
        submission_name = (submission_name
                           if submission_name != event.ramp_sandbox_name
                           else submission_name + '_test')
        submission = add_submission(session, event_name, team_name,
                                    submission_name, from_submission_path)
        logger.info('Copying the submission files into the deployment folder')
        logger.info('Adding {}'.format(submission))
    # revert the minimum duration between two submissions
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / frontend.py View on Github external
Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The event name.
    user_name : str
        The user name.

    Returns
    -------
    is_accessible : bool
        True if leaderboard can be displayed.
    """
    event = select_event_by_name(session, event_name)
    user = select_user_by_name(session, user_name)
    if not user.is_authenticated or not user.is_active:
        return False
    if is_admin(session, event_name, user_name):
        return True
    if not is_user_signed_up(session, event_name, user_name):
        return False
    if event.is_public_open:
        return True
    return False
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / event.py View on Github external
Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    event_name : str
        The event name.
    user_name : str
        The user name.

    Returns
    -------
    event_admin : :class:`ramp_database.model.EventAdmin` or None
        The event/admin instance queried.
    """
    event = select_event_by_name(session, event_name)
    user = select_user_by_name(session, user_name)
    return select_event_admin_by_instance(session, event, user)