|
42 | 42 | from graph_notebook.neptune.client import ClientBuilder, Client, VALID_FORMATS, PARALLELISM_OPTIONS, PARALLELISM_HIGH, \ |
43 | 43 | LOAD_JOB_MODES, MODE_AUTO, FINAL_LOAD_STATUSES, SPARQL_ACTION, FORMAT_CSV, FORMAT_OPENCYPHER, FORMAT_NTRIPLE, \ |
44 | 44 | FORMAT_NQUADS, FORMAT_RDFXML, FORMAT_TURTLE, STREAM_RDF, STREAM_PG, STREAM_ENDPOINTS, \ |
45 | | - NEPTUNE_CONFIG_HOST_IDENTIFIERS, is_allowed_neptune_host, STATISTICS_LANGUAGE_INPUTS, STATISTICS_MODES |
| 45 | + NEPTUNE_CONFIG_HOST_IDENTIFIERS, is_allowed_neptune_host, \ |
| 46 | + STATISTICS_LANGUAGE_INPUTS, STATISTICS_MODES, SUMMARY_MODES |
46 | 47 | from graph_notebook.network import SPARQLNetwork |
47 | 48 | from graph_notebook.network.gremlin.GremlinNetwork import parse_pattern_list_str, GremlinNetwork |
48 | 49 | from graph_notebook.visualization.rows_and_columns import sparql_get_rows_and_columns, opencypher_get_rows_and_columns |
@@ -403,26 +404,61 @@ def statistics(self, line, local_ns: dict = None): |
403 | 404 | help=f'The language endpoint to use. Valid inputs: {STATISTICS_LANGUAGE_INPUTS}. ' |
404 | 405 | f'Default: propertygraph.', |
405 | 406 | choices=STATISTICS_LANGUAGE_INPUTS) |
406 | | - parser.add_argument('-m', '--mode', type=str, default='status', |
| 407 | + parser.add_argument('-m', '--mode', type=str, default='', |
407 | 408 | help=f'The action to perform on the statistics endpoint. Valid inputs: {STATISTICS_MODES}. ' |
408 | | - f'Default: status') |
| 409 | + f'Default: `basic` if `--summary` is specified, otherwise `status`.') |
| 410 | + parser.add_argument('--summary', action='store_true', default=False, help="Retrieves the graph summary.") |
409 | 411 | parser.add_argument('--silent', action='store_true', default=False, help="Display no output.") |
410 | 412 | parser.add_argument('--store-to', type=str, default='') |
411 | 413 |
|
412 | 414 | args = parser.parse_args(line.split()) |
413 | | - |
414 | | - if args.mode not in STATISTICS_MODES: |
415 | | - print(f'Invalid mode. Please specify one of: {STATISTICS_MODES}, or leave blank to retrieve status.') |
| 415 | + mode = args.mode |
| 416 | + |
| 417 | + if not mode: |
| 418 | + mode = 'basic' if args.summary else 'status' |
| 419 | + elif (args.summary and mode not in SUMMARY_MODES) or (not args.summary and mode not in STATISTICS_MODES): |
| 420 | + err_endpoint_type, err_mode_list, err_default_mode = ("summary", SUMMARY_MODES[1:], "basic summary view") \ |
| 421 | + if args.summary else ("statistics", STATISTICS_MODES[1:], "status") |
| 422 | + print(f'Invalid {err_endpoint_type} mode. Please specify one of: {err_mode_list}, ' |
| 423 | + f'or leave blank to retrieve {err_default_mode}.') |
416 | 424 | return |
417 | 425 |
|
418 | | - statistics_res = self.client.statistics(args.language, args.mode) |
| 426 | + statistics_res = self.client.statistics(args.language, args.summary, mode) |
419 | 427 | statistics_res.raise_for_status() |
420 | | - res = statistics_res.json() |
| 428 | + statistics_res_json = statistics_res.json() |
421 | 429 | if not args.silent: |
422 | | - print(json.dumps(res, indent=2)) |
| 430 | + print(json.dumps(statistics_res_json, indent=2)) |
423 | 431 |
|
424 | 432 | if args.store_to != '' and local_ns is not None: |
425 | | - local_ns[args.store_to] = res |
| 433 | + local_ns[args.store_to] = statistics_res_json |
| 434 | + |
| 435 | + @line_magic |
| 436 | + def summary(self, line, local_ns: dict = None): |
| 437 | + parser = argparse.ArgumentParser() |
| 438 | + parser.add_argument('language', nargs='?', type=str.lower, default="propertygraph", |
| 439 | + help=f'The language endpoint to use. Valid inputs: {STATISTICS_LANGUAGE_INPUTS}. ' |
| 440 | + f'Default: propertygraph.', |
| 441 | + choices=STATISTICS_LANGUAGE_INPUTS) |
| 442 | + parser.add_argument('--detailed', action='store_true', default=False, |
| 443 | + help="Toggles the display of structures fields on or off in the output. If not supplied, " |
| 444 | + "we will default to the basic summary display mode.") |
| 445 | + parser.add_argument('--silent', action='store_true', default=False, help="Display no output.") |
| 446 | + parser.add_argument('--store-to', type=str, default='') |
| 447 | + |
| 448 | + args = parser.parse_args(line.split()) |
| 449 | + if args.detailed: |
| 450 | + mode = "detailed" |
| 451 | + else: |
| 452 | + mode = "basic" |
| 453 | + |
| 454 | + summary_res = self.client.statistics(args.language, True, mode) |
| 455 | + summary_res.raise_for_status() |
| 456 | + summary_res_json = summary_res.json() |
| 457 | + if not args.silent: |
| 458 | + print(json.dumps(summary_res_json, indent=2)) |
| 459 | + |
| 460 | + if args.store_to != '' and local_ns is not None: |
| 461 | + local_ns[args.store_to] = summary_res_json |
426 | 462 |
|
427 | 463 | @line_magic |
428 | 464 | def graph_notebook_host(self, line): |
|
0 commit comments