From 467414ccd115fade93176f6bccc45065dd2b3b93 Mon Sep 17 00:00:00 2001 From: Kelvin Lawrence Date: Tue, 21 Jun 2022 15:07:16 -0500 Subject: [PATCH] Issue 233 (#311) * Initial work to add the commit timestamp to the stream viewer * Add UTC human readable timestamp * Put the human readable date in parens #233 * Initial support for isLastOp in stream viewer #233 * Center the operation column text #233 * Improve hover help text #233 * Update changelog - still need to add PR info later. #233 * Add link to pR in the changelog Co-authored-by: Michael Chin --- ChangeLog.md | 3 ++ src/graph_notebook/magics/streams.py | 42 ++++++++++++++++++++-------- src/graph_notebook/neptune/client.py | 2 ++ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 26823d30..9e54a90f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,8 +3,11 @@ Starting with v1.31.6, this file will contain a record of major features and updates made in each release of graph-notebook. ## Upcoming +- Improved the `%stream_viewer` magic to show the commit timestamp and `isLastOp` information, + if available. Also added additional hover (help) text to the stream viewer. ([Link to PR](https://github.com/aws/graph-notebook/pull/311)) - Added `--max-content-length` option to `%%gremlin` ([Link to PR](https://github.com/aws/graph-notebook/pull/305)) + ## Release 3.4.1 (June 7, 2022) - Identity Graph - ETL notebook ([Link to PR](https://github.com/aws/graph-notebook/pull/288)) - Path: 03-Identity-Graphs>03-Jumpstart-Identity-Graphs-Using-Canonical-Model-and-ETL diff --git a/src/graph_notebook/magics/streams.py b/src/graph_notebook/magics/streams.py index 2fc395c5..67739c86 100644 --- a/src/graph_notebook/magics/streams.py +++ b/src/graph_notebook/magics/streams.py @@ -2,9 +2,11 @@ import json import ipywidgets as widgets import queue +from datetime import datetime from IPython.display import display, HTML from graph_notebook.neptune.client import STREAM_AT, STREAM_AFTER, STREAM_TRIM, STREAM_EXCEPTION_NOT_FOUND,\ - STREAM_EXCEPTION_NOT_ENABLED, STREAM_PG, STREAM_RDF, STREAM_ENDPOINTS + STREAM_EXCEPTION_NOT_ENABLED, STREAM_PG, STREAM_RDF, STREAM_ENDPOINTS,\ + STREAM_COMMIT_TIMESTAMP, STREAM_IS_LASTOP class EventId: @@ -176,30 +178,48 @@ def show_records(self, records): html = '''''' html += ''' - - - + + + + ''' commit_num = None for record in records: current_commit_num = record['eventId']['commitNum'] - + timestamp = None + lastop = False + lastop_text = '' + if STREAM_COMMIT_TIMESTAMP in record: + timestamp = record[STREAM_COMMIT_TIMESTAMP] + utc_text = datetime.utcfromtimestamp(timestamp/1000) + data = json.dumps(record['data']).replace('&', '&').replace('<', '<') if commit_num is None or current_commit_num != commit_num: commit_num = current_commit_num - html += '' - html += ''.format(commit_num) + html += '' + html += '' html += '' - html += '' - html += ''' - - '''.format( + if STREAM_IS_LASTOP in record: + lastop = record[STREAM_IS_LASTOP] + if lastop: + lastop_text = 'Y' + + html += '' + html += ''' + + + '''.format( record['eventId']['opNum'], record['op'], + lastop_text, data) html += '
Tx/Op#OperationDataTx/Op#OperationLastOpData
{}
{}'.format(commit_num) + if timestamp != None: + html += '   Timestamp = {}'.format(timestamp) + html += '   ( {} UTC )'.format(utc_text) + html += '
{}{}{}
{}{}{}{}
' diff --git a/src/graph_notebook/neptune/client.py b/src/graph_notebook/neptune/client.py index b9c5ee8e..d68c1e6f 100644 --- a/src/graph_notebook/neptune/client.py +++ b/src/graph_notebook/neptune/client.py @@ -77,6 +77,8 @@ STREAM_AFTER = 'AFTER_SEQUENCE_NUMBER' STREAM_TRIM = 'TRIM_HORIZON' STREAM_LATEST = 'LATEST' +STREAM_COMMIT_TIMESTAMP = 'commitTimestamp' +STREAM_IS_LASTOP = 'isLastOp' STREAM_EXCEPTION_NOT_FOUND = 'StreamRecordsNotFoundException' STREAM_EXCEPTION_NOT_ENABLED = 'UnsupportedOperationException'