aaltay commented on a change in pull request #11020: [BEAM-7926] Update Data
Visualization
URL: https://github.com/apache/beam/pull/11020#discussion_r387359733
##########
File path:
sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py
##########
@@ -291,3 +402,81 @@ def _to_dataframe(self):
def _is_one_dimension_type(self, val):
return type(val) in _one_dimension_types
+
+
+def format_window_info_in_dataframe(data):
+ if 'event_time' in data.columns:
+ data['event_time'] = data['event_time'].apply(event_time_formatter)
+ if 'windows' in data.columns:
+ data['windows'] = data['windows'].apply(windows_formatter)
+ if 'pane_info' in data.columns:
+ data['pane_info'] = data['pane_info'].apply(pane_info_formatter)
+
+
+def event_time_formatter(event_time_us):
+ options = ie.current_env().options
+ to_tz = options.display_timezone
+ try:
+ return (
+ datetime.datetime.utcfromtimestamp(event_time_us / 1000000).replace(
+ tzinfo=tz.tzutc()).astimezone(to_tz).strftime(
+ options.display_timestamp_format))
+ except ValueError:
+ if event_time_us < 0:
+ return 'Min Timestamp'
+ return 'Max Timestamp'
+
+
+def windows_formatter(windows):
+ result = []
+ for w in windows:
+ if isinstance(w, GlobalWindow):
+ result.append(str(w))
+ elif isinstance(w, IntervalWindow):
+ # First get the duration in terms of hours, minutes, seconds, and
+ # micros.
+ duration = w.end.micros - w.start.micros
+ duration_secs = duration // 1000000
+ hours, remainder = divmod(duration_secs, 3600)
+ minutes, seconds = divmod(remainder, 60)
+ micros = (duration - duration_secs * 1000000) % 1000000
+
+ # Construct the duration string. Try and write the string in such a
Review comment:
Is there any other standard function that will do this?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services