Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EHN: add more command lines to interact with database #251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions ramp-database/ramp_database/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import defaultdict
from collections.abc import Iterable

import click
import pandas as pd
Expand Down Expand Up @@ -108,6 +109,29 @@ def add_event(config, problem, event, title, sandbox, submissions_dir,
submissions_dir, is_public, force)


@main.command()
@click.option("--config", default='config.yml', show_default=True,
help='Configuration file YAML format containing the database '
'information')
@click.option("--event", default=None, show_default=True,
help='Name of the event')
def get_event(config, event):
"""Get an event from the database."""
config = read_config(config)
with session_scope(config['sqlalchemy']) as session:
event = event_module.get_event(session, event)
if not isinstance(event, Iterable):
event = [event]
data = defaultdict(list)
for e in event:
data['ID'] = e.id
data['Problem ID'] = e.problem_id
data['Problem name'] = e.problem_name
data['# submissions'] = e.n_submissions
data['Public event'] = e.is_public
click.echo(pd.DataFrame(data).set_index('ID'))


@main.command()
@click.option("--config", default='config.yml', show_default=True,
help='Configuration file YAML format containing the database '
Expand Down