diff --git a/gbd.py b/gbd.py index 105ad30..40104b3 100755 --- a/gbd.py +++ b/gbd.py @@ -84,6 +84,15 @@ def cli_get(api: GBD, args): for index, row in df.iterrows(): print(args.delimiter.join([ item or "[None]" for item in row.to_list() ])) +def cli_interactive(api: GBD, args): + data = api.query(args.query, args.hashes, args.resolve, args.collapse, args.group_by, args.join_type) + if args.group_by: + data.set_index(args.group_by, inplace=True) + else: + data.set_index('hash', inplace=True) + import IPython + IPython.embed(header ="GBD data is available as `data`", colors="neutral") + def cli_set(api: GBD, args): hashes = api.query(args.query, args.hashes)['hash'].tolist() if args.create: @@ -187,6 +196,17 @@ def main(): parser_get.add_argument('-H', '--header', action='store_true', help='Include header information in output') parser_get.set_defaults(func=cli_get) + # GBD INTERACTIVE $QUERY + parser_interactive = subparsers.add_parser('interactive', help='Get data by query (or hash-list via stdin) and open interactive Python prompt') + add_query_and_hashes_arguments(parser_interactive) + parser_interactive.add_argument('-r', '--resolve', help='List of feature names to resolve against', nargs='+', default=[]) + parser_interactive.add_argument('-c', '--collapse', default='group_concat', + choices=['group_concat', 'min', 'max', 'avg', 'count', 'sum', 'none'], + help='Specify a function for the handling of multiple feature values') + parser_interactive.add_argument('-g', '--group_by', default=None, help='Group by the specified feature as the key, rather than by the primary key') + parser_interactive.add_argument('--join-type', help='Join Type: treatment of missing values', choices=['INNER', 'OUTER', 'LEFT'], default="LEFT") + parser_interactive.set_defaults(func=cli_interactive) + # GBD SET parser_set = subparsers.add_parser('set', help='Set specified attribute-value for query result') parser_set.add_argument('assign', type=key_value_type, help='key=value') diff --git a/pyproject.toml b/pyproject.toml index 6726cb5..b3d61f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,20 +9,17 @@ description = "GBD Tools: Maintenance and Distribution of Benchmark Instances an readme = "README.md" license-files = ["LICENSE"] requires-python = ">=3.6" -authors = [ - { name = "Markus Iser", email = "markus.iser@kit.edu" } -] +authors = [{ name = "Markus Iser", email = "markus.iser@kit.edu" }] urls = { Homepage = "https://github.com/Udopia/gbd" } -classifiers = [ - "Programming Language :: Python :: 3" -] +classifiers = ["Programming Language :: Python :: 3"] dependencies = [ - "flask", - "tatsu", - "pandas", - "waitress", - "pebble", - "gbdc" + "flask", + "tatsu", + "pandas", + "waitress", + "pebble", + "gbdc", + "IPython", ] scripts = { gbd = "gbd:main" }