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

feat(openadapt): add progress bar in record.py and visualize.py #318

Merged
merged 29 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
29ec8ec
run `poetry lock --no-update`
Jun 26, 2023
2f29934
add alive-progress via poetry and in code
Jun 26, 2023
1ff5e9d
add progress bar in visualization
Jun 26, 2023
790a17e
add a check for MAX_EVENT = None
Jun 26, 2023
37f22c0
update the title for the Progress bAr
Jun 26, 2023
afbaa2c
update the requirement.txt
Jun 26, 2023
7227c5c
ran ` black --line-length 80 <file>`
Jun 26, 2023
0c5f4e9
remove all progress bar from record
Jun 26, 2023
d2adac1
Merge branch 'MLDSAI:main' into feature/record_pb
KrishPatel13 Jun 26, 2023
9e8ee4d
add tqdm progress bar in recrod.py
Jun 27, 2023
3de913f
add tqdm for visualiztion
Jun 27, 2023
e5b1601
remove alive-progress
Jun 27, 2023
f7c42d1
consistent tqdm api
Jun 27, 2023
03dc223
Update requirements.txt
KrishPatel13 Jun 28, 2023
2c26a45
Address comemnt:
Jun 28, 2023
d41d088
remove incorrect indent
Jun 28, 2023
2234eb9
remove rows
Jun 28, 2023
8f6d02b
try to fix distorted table in html
Jun 28, 2023
b2df437
Merge branch 'MLDSAI:main' into feature/record_pb
KrishPatel13 Jun 28, 2023
9c063ef
add custom queue class
Jun 29, 2023
857382a
lint --line-length 80
Jun 29, 2023
c6fbf3a
fix `NotImplementedError` for MacOs
Jun 29, 2023
416ce80
rename custom -> thirdparty_customization
Jun 29, 2023
00fdcc3
rename to something useful
Jun 29, 2023
a612535
address comments
Jun 29, 2023
5204148
rename dir to customized_imports
Jun 29, 2023
e2419cc
rename to extensions
Jun 29, 2023
cb9a3d8
Merge branch 'OpenAdaptAI:main' into feature/record_pb
KrishPatel13 Jun 29, 2023
aa61233
Merge branch 'main' into feature/record_pb
KrishPatel13 Jul 3, 2023
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
21 changes: 13 additions & 8 deletions openadapt/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import threading
import time

from alive_progress import alive_bar
from loguru import logger
from pynput import keyboard, mouse
import fire
Expand Down Expand Up @@ -247,14 +248,18 @@ def write_events(
utils.set_start_time(recording_timestamp)
logger.info(f"{event_type=} starting")
signal.signal(signal.SIGINT, signal.SIG_IGN)
while not terminate_event.is_set() or not write_q.empty():
try:
event = write_q.get_nowait()
except queue.Empty:
continue
assert event.type == event_type, (event_type, event)
write_fn(recording_timestamp, event, perf_q)
logger.debug(f"{event_type=} written")

with alive_bar(total=write_q.qsize(), title=f"Writing {event_type} events") as progress:
KrishPatel13 marked this conversation as resolved.
Show resolved Hide resolved
while not terminate_event.is_set() or not write_q.empty():
try:
event = write_q.get_nowait()
except queue.Empty:
continue
assert event.type == event_type, (event_type, event)
write_fn(recording_timestamp, event, perf_q)
logger.debug(f"{event_type=} written")
progress()

logger.info(f"{event_type=} done")


Expand Down
133 changes: 70 additions & 63 deletions openadapt/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import string

from alive_progress import alive_bar
from bokeh.io import output_file, show
from bokeh.layouts import layout, row
from bokeh.models.widgets import Div
Expand Down Expand Up @@ -188,70 +189,76 @@ def main():
),
]
logger.info(f"{len(action_events)=}")
for idx, action_event in enumerate(action_events):
if idx == MAX_EVENTS:
break
image = display_event(action_event)
diff = display_event(action_event, diff=True)
mask = action_event.screenshot.diff_mask

if SCRUB:
image = scrub.scrub_image(image)
diff = scrub.scrub_image(diff)
mask = scrub.scrub_image(mask)

image_utf8 = image2utf8(image)
diff_utf8 = image2utf8(diff)
mask_utf8 = image2utf8(mask)
width, height = image.size

action_event_dict = row2dict(action_event)
window_event_dict = row2dict(action_event.window_event)

if SCRUB:
action_event_dict = scrub.scrub_dict(action_event_dict)
window_event_dict = scrub.scrub_dict(window_event_dict)

rows.append(
[
row(
Div(
text=f"""
<div class="screenshot">
<img
src="{image_utf8}"
style="
aspect-ratio: {width}/{height};
"
>
<img
src="{diff_utf8}"
style="
aspect-ratio: {width}/{height};
"
>
<img
src="{mask_utf8}"
style="
aspect-ratio: {width}/{height};
"
>
</div>
<table>
{dict2html(window_event_dict , None)}
</table>
""",
),
Div(
text=f"""
<table>
{dict2html(action_event_dict)}
</table>
"""

rows = []
num_events = min(MAX_EVENTS, len(action_events)) if MAX_EVENTS is not None else len(action_events)
with alive_bar(total=num_events, title="Processing HTML for visualization:") as progress:
for idx, action_event in enumerate(action_events):
if idx == MAX_EVENTS:
break
image = display_event(action_event)
diff = display_event(action_event, diff=True)
mask = action_event.screenshot.diff_mask

if SCRUB:
image = scrub.scrub_image(image)
diff = scrub.scrub_image(diff)
mask = scrub.scrub_image(mask)

image_utf8 = image2utf8(image)
diff_utf8 = image2utf8(diff)
mask_utf8 = image2utf8(mask)
width, height = image.size

action_event_dict = row2dict(action_event)
window_event_dict = row2dict(action_event.window_event)

if SCRUB:
action_event_dict = scrub.scrub_dict(action_event_dict)
window_event_dict = scrub.scrub_dict(window_event_dict)

rows.append(
[
row(
Div(
text=f"""
<div class="screenshot">
<img
src="{image_utf8}"
style="
aspect-ratio: {width}/{height};
"
>
<img
src="{diff_utf8}"
style="
aspect-ratio: {width}/{height};
"
>
<img
src="{mask_utf8}"
style="
aspect-ratio: {width}/{height};
"
>
</div>
<table>
{dict2html(window_event_dict , None)}
</table>
""",
),
Div(
text=f"""
<table>
{dict2html(action_event_dict)}
</table>
"""
),
),
),
]
)
]
)

progress()

title = f"recording-{recording.id}"
fname_out = f"recording-{recording.id}.html"
Expand Down
41 changes: 40 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ nltk = "3.8.1"
pywinauto = {version = "^0.6.8", markers = "sys_platform == 'win32'"}
moviepy = "1.0.3"
python-levenshtein = "^0.21.1"
alive-progress = "^3.1.4"

[tool.poetry.dependencies.en_core_web_trf]
url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_trf-3.5.0/en_core_web_trf-3.5.0.tar.gz"
Expand Down