Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
List of submissions information. Each item is a tuple containing:
* an integer containing the id of the submission;
* a string with the name of the submission in the database;
* a list of string representing the file associated with the
submission.
See also
--------
ramp_database.tools.get_submission_by_id : Get a submission using an id.
ramp_database.tools.get_submission_by_name : Get a submission using names.
"""
if state is not None and state not in STATES:
raise UnknownStateError("Unrecognized state : '{}'".format(state))
submissions = select_submissions_by_state(session, event_name, state)
if not submissions:
return []
submission_id = [sub.id for sub in submissions]
submission_files = [sub.files for sub in submissions]
submission_basename = [sub.basename for sub in submissions]
filenames = [[f.path for f in files] for files in submission_files]
return list(zip(submission_id, submission_basename, filenames))
def compute_historical_contributivity(session, event_name):
"""Compute historical contributivities of an event using
contributivities from blending and credits.
Parameters
----------
session : :class:`sqlalchemy.orm.Session`
The session to directly perform the operation on the database.
event_name : str
The event associated to the submission.
"""
submissions = select_submissions_by_state(
session, event_name, state='scored')
submissions.sort(key=lambda x: x.submission_timestamp, reverse=True)
for s in submissions:
s.historical_contributivity = 0.0
for s in submissions:
s.historical_contributivity += s.contributivity
similarities = session.query(SubmissionSimilarity).filter_by(
type='target_credit', target_submission=s).all()
if similarities:
# if a target team enters several credits to a source submission
# we only take the latest
similarities.sort(key=lambda x: x.timestamp, reverse=True)
processed_submissions = []
historical_contributivity = s.historical_contributivity
for ss in similarities:
source_submission = ss.source_submission
The event associated to the submission.
ramp_kit_dir : str
The directory of the RAMP kit.
ramp_data_dir : str
The directory of the data.
min_improvement : float, default is 0.0
The minimum improvement under which greedy blender is stopped.
"""
logging.basicConfig(level=logging.INFO, format='%(message)s')
logger.info('Combining models')
event = select_event_by_name(session, event_name)
ramp_submission_dir = event.path_ramp_submissions
score_type = event.get_official_score_type(session)
submissions = select_submissions_by_state(
session, event_name, state='scored')
if len(submissions) == 0:
logger.info('No submissions to blend.')
return
blend_submissions(
submissions=[sub.basename for sub in submissions],
ramp_kit_dir=ramp_kit_dir,
ramp_data_dir=ramp_data_dir,
ramp_submission_dir=ramp_submission_dir,
save_output=True,
min_improvement=min_improvement,
)
bsc_f_name = 'bagged_scores_combined.csv'
bsc_df = pd.read_csv(