Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# we can automatically setup the database from the config file used for the
# tests.
ramp_config = generate_ramp_config(read_config(ramp_config))
# FIXME: we are recreating the deployment directory but it should be
# replaced by an temporary creation of folder.
deployment_dir = os.path.commonpath(
[ramp_config['ramp_kit_dir'], ramp_config['ramp_data_dir']]
)
shutil.rmtree(deployment_dir, ignore_errors=True)
os.makedirs(ramp_config['ramp_submissions_dir'])
db, _ = setup_db(database_config)
Model.metadata.drop_all(db)
Model.metadata.create_all(db)
with session_scope(database_config) as session:
setup_files_extension_type(session)
return deployment_dir
"""Create a toy dataset with couple of users, problems, events.
Parameters
----------
database_config : dict
The configuration file containing the database information.
ramp_config : str
The configuration file containing the information about a RAMP event.
Returns
-------
deployment_dir : str
The deployment directory for the RAMP components (kits, data, etc.).
"""
deployment_dir = create_test_db(database_config, ramp_config)
with session_scope(database_config['sqlalchemy']) as session:
setup_toy_db(session)
return deployment_dir
def update_all_users_leaderboards(config, event):
"""Update the leaderboards of all users for a given event."""
config = read_config(config)
with session_scope(config['sqlalchemy']) as session:
leaderboard_module.update_all_user_leaderboards(session, event)
def update_user_leaderboards(config, event, user):
"""Update the user leaderboards for a given event."""
config = read_config(config)
with session_scope(config['sqlalchemy']) as session:
leaderboard_module.update_user_leaderboards(session, event, user)
def update_leaderboards(config, event):
"""Update the leaderboards for a given event."""
config = read_config(config)
with session_scope(config['sqlalchemy']) as session:
leaderboard_module.update_leaderboards(session, event)
def sign_up_team(config, event, team):
"""Sign-up a user (or team) for a RAMP event."""
config = read_config(config)
with session_scope(config['sqlalchemy']) as session:
team_module.sign_up_team(session, event, team)
def make_user_admin(config, login):
"""Make a user a RAMP admin."""
config = read_config(config)
with session_scope(config['sqlalchemy']) as session:
user_module.make_user_admin(session, login)
def get_submissions_by_state(config, event, state):
"""Display the list of submission for an event in a particular state."""
config = read_config(config)
with session_scope(config['sqlalchemy']) as session:
submissions = submission_module.get_submissions(session, event, state)
if submissions:
data = defaultdict(list)
for sub_info in submissions:
sub = submission_module.get_submission_by_id(
session, sub_info[0]
)
data['ID'].append(sub.id)
data['name'].append(sub.name)
data['team'].append(sub.team)
data['path'].append(sub.path)
data['state'].append(sub.state)
click.echo(pd.DataFrame(data).set_index('ID'))
else:
click.echo('No submission for this event and this state')
def add_submission(config, event, team, submission, path):
"""Add a submission to the database."""
config = read_config(config)
with session_scope(config['sqlalchemy']) as session:
submission_module.add_submission(session, event, team, submission,
path)