How to use the ramp-database.ramp_database.tools._query.select_submission_by_id 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_submission_similarity(session, submission_id):
    """Delete the submission similarity associated with a submission.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    submission_id: int
        The id of the submission to use.
    """
    submission = select_submission_by_id(session, submission_id)
    similarities = []
    similarities += select_similarities_by_target(session, submission)
    similarities += select_similarities_by_source(session, submission)
    for similarity in similarities:
        session.delete(similarity)
    session.commit()
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / contributivity.py View on Github external
os.path.join(ramp_submission_dir, 'training_output', bsfb_f_name))
    row = (bsfb_df['step'] == 'valid') & (bsfb_df['n_bag'] == n_folds - 1)
    event.combined_foldwise_valid_score =\
        bsfb_df[row][score_type.name].values[0]
    row = (bsfb_df['step'] == 'test') & (bsfb_df['n_bag'] == n_folds - 1)
    event.combined_foldwise_test_score =\
        bsfb_df[row][score_type.name].values[0]

    c_f_name = 'contributivities.csv'
    contributivities_df = pd.read_csv(
        os.path.join(ramp_submission_dir, 'training_output', c_f_name))

    logger.info(contributivities_df)
    for index, row in contributivities_df.iterrows():
        sub_id = int(row['submission'][-9:])
        submission = select_submission_by_id(session, sub_id)
        submission.contributivity = 0.0
        for fold_i in range(n_folds):
            c_i = row['fold_{}'.format(fold_i)]
            submission.contributivity += c_i

    session.commit()
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / submission.py View on Github external
def set_submission_error_msg(session, submission_id, error_msg):
    """Set the error message after that a submission failed to be processed.

    Parameters
    ----------
    config : dict
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    submission_id : int
        The id of the submission.
    error_msg : str
        The error message.
    """
    submission = select_submission_by_id(session, submission_id)
    submission.error_msg = error_msg
    session.commit()
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / submission.py View on Github external
def set_submission_max_ram(session, submission_id, max_ram_mb):
    """Set the max amount RAM used by a submission during processing.

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    submission_id : int
        The id of the submission.
    max_ram_mb : float
        The max amount of RAM in MB.
    """
    submission = select_submission_by_id(session, submission_id)
    submission.max_ram = max_ram_mb
    session.commit()
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / submission.py View on Github external
-----
    The possible states for a submission are:

    * 'new': submitted by user to the web interface;
    * 'sent_to_training': submission was send for training but not launch
        yet.
    * 'trained': training finished normally;
    * 'training_error': training finished abnormally;
    * 'validated': validation finished normally;
    * 'validating_error': validation finished abnormally;
    * 'tested': testing finished normally;
    * 'testing_error': testing finished abnormally;
    * 'training': training is running normally;
    * 'scored': submission scored.
    """
    submission = select_submission_by_id(session, submission_id)
    return submission.state
github paris-saclay-cds / ramp-board / ramp-database / ramp_database / tools / submission.py View on Github external
"""Score a submission and change its state to 'scored'

    Parameters
    ----------
    session : :class:`sqlalchemy.orm.Session`
        The session to directly perform the operation on the database.
    submission_id : int
        submission id

    Raises
    ------
    ValueError :
        when the state of the submission is not 'tested'
        (only a submission with state 'tested' can be scored)
    """
    submission = select_submission_by_id(session, submission_id)
    if submission.state != 'tested':
        raise ValueError('Submission state must be "tested"'
                         ' to score, not "{}"'.format(submission.state))

    # We are conservative:
    # only score if all stages (train, test, validation)
    # were completed. submission_on_cv_fold compute scores can be called
    # manually if needed for submission in various error states.
    all_cv_folds = (session.query(SubmissionOnCVFold)
                           .filter_by(submission_id=submission_id)
                           .options(defer("full_train_y_pred"),
                                    defer("test_y_pred"))
                           .all())
    all_cv_folds = sorted(all_cv_folds, key=lambda x: x.id)
    for submission_on_cv_fold in all_cv_folds:
        submission_on_cv_fold.session = session