Skip to content

Commit

Permalink
chore(dependencies): update various libraries; deprecate NiceGUI (#888)
Browse files Browse the repository at this point in the history
* deprecate nicegui; move app/tray.py dependencies to app/__init__.py

* remove bind; update README

* Fix: wrap raw SQL queries in `text()` to prevent ArgumentError

* black

* noqa
  • Loading branch information
abrichr authored Nov 7, 2024
1 parent 90ed3c7 commit 50e4a3e
Show file tree
Hide file tree
Showing 35 changed files with 1,373 additions and 969 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,6 @@ This will start a web server locally, and then open a tab in your browser that l

![image](https://github.com/OpenAdaptAI/OpenAdapt/assets/774615/48d27459-4be8-4b96-beb0-1973953b8a09)

For a desktop app-based visualization, run:

```
python -m openadapt.app.visualize
```

This will open a scrollable window that looks something like this:

<img width="1512" alt="image" src="https://github.com/OpenAdaptAI/OpenAdapt/assets/774615/451dd467-20ae-4ce7-a3b4-f888635afe8c">

<img width="1511" alt="image" src="https://github.com/OpenAdaptAI/OpenAdapt/assets/774615/13264cf6-46c0-4413-a29d-59bdd040a32e">

### Playback

You can play back the recording using the following command:
Expand Down
21 changes: 15 additions & 6 deletions openadapt/alembic/versions/f9586c10a561_migrate_data_to_new_fks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text

# revision identifiers, used by Alembic.
revision = "f9586c10a561"
Expand All @@ -27,19 +28,27 @@ def upgrade() -> None:
"performance_stat",
]:
session.execute(
f"UPDATE {table} SET recording_id = (SELECT id FROM recording WHERE"
f" recording.timestamp = {table}.recording_timestamp)"
text(
f"UPDATE {table} SET recording_id = (SELECT id FROM recording WHERE"
f" recording.timestamp = {table}.recording_timestamp)"
)
)

session.execute(
"UPDATE action_event SET window_event_id = (SELECT id FROM window_event WHERE"
" window_event.timestamp = action_event.window_event_timestamp)"
text(
"UPDATE action_event SET window_event_id = (SELECT id FROM window_event WHERE"
" window_event.timestamp = action_event.window_event_timestamp)"
)
)
session.execute(
"UPDATE action_event SET screenshot_id = (SELECT id FROM screenshot WHERE"
" screenshot.timestamp = action_event.screenshot_timestamp)"
text(
"UPDATE action_event SET screenshot_id = (SELECT id FROM screenshot WHERE"
" screenshot.timestamp = action_event.screenshot_timestamp)"
)
)

session.commit()


def downgrade() -> None:
pass
114 changes: 112 additions & 2 deletions openadapt/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,114 @@
"""Package for the GUI.
"""openadapt.app module.
Module: __init__.py
This module provides core functionality for the OpenAdapt application.
"""

from datetime import datetime
import multiprocessing
import pathlib
import time

from openadapt.record import record
from openadapt.utils import WrapStdout

__all__ = [
"RecordProc",
"record_proc",
"stop_record",
"is_recording",
"quick_record",
"FPATH",
]

# Define FPATH
FPATH = pathlib.Path(__file__).parent


class RecordProc:
"""Class to manage the recording process."""

def __init__(self) -> None:
"""Initialize the RecordProc class."""
self.terminate_processing = multiprocessing.Event()
self.terminate_recording = multiprocessing.Event()
self.record_proc: multiprocessing.Process = None
self.has_initiated_stop = False

def set_terminate_processing(self) -> multiprocessing.Event:
"""Set the terminate event."""
return self.terminate_processing.set()

def terminate(self) -> None:
"""Terminate the recording process."""
self.record_proc.terminate()

def reset(self) -> None:
"""Reset the recording process."""
self.terminate_processing.clear()
self.terminate_recording.clear()
self.record_proc = None
self.has_initiated_stop = False

def wait(self) -> None:
"""Wait for the recording process to finish."""
while True:
if self.terminate_recording.is_set():
self.record_proc.terminate()
return
time.sleep(0.1)

def is_running(self) -> bool:
"""Check if the recording process is running."""
if self.record_proc is not None and not self.record_proc.is_alive():
self.reset()
return self.record_proc is not None

def start(self, func: callable, args: tuple, kwargs: dict) -> None:
"""Start the recording process."""
self.record_proc = multiprocessing.Process(
target=WrapStdout(func),
args=args,
kwargs=kwargs,
)
self.record_proc.start()


record_proc = RecordProc()


def stop_record() -> None:
"""Stop the current recording session."""
global record_proc
if record_proc.is_running() and not record_proc.has_initiated_stop:
record_proc.set_terminate_processing()

# wait for process to terminate
record_proc.wait()
record_proc.reset()


def is_recording() -> bool:
"""Check if a recording session is currently active."""
global record_proc
return record_proc.is_running()


def quick_record(
task_description: str | None = None,
status_pipe: multiprocessing.connection.Connection | None = None,
) -> None:
"""Run a recording session."""
global record_proc
task_description = task_description or datetime.now().strftime("%d/%m/%Y %H:%M:%S")
record_proc.start(
record,
(
task_description,
record_proc.terminate_processing,
record_proc.terminate_recording,
status_pipe,
),
{
"log_memory": False,
},
)
1 change: 0 additions & 1 deletion openadapt/app/dashboard/api/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""API endpoints for the dashboard."""


from pathlib import Path
import os

Expand Down
1 change: 0 additions & 1 deletion openadapt/app/dashboard/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This module contains the functions to run the dashboard web application."""


from threading import Thread
import os
import pathlib
Expand Down
3 changes: 1 addition & 2 deletions openadapt/app/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
QWidget,
)

from openadapt.app.cards import quick_record, stop_record
from openadapt.app import quick_record, stop_record, FPATH
from openadapt.app.dashboard.run import cleanup as cleanup_dashboard
from openadapt.app.dashboard.run import run as run_dashboard
from openadapt.app.main import FPATH # , start
from openadapt.build_utils import is_running_from_executable
from openadapt.custom_logger import logger
from openadapt.db import crud
Expand Down
1 change: 1 addition & 0 deletions openadapt/capture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module: capture.py
"""

import sys

if sys.platform == "darwin":
Expand Down
1 change: 1 addition & 0 deletions openadapt/capture/_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
usage: see bottom of file
"""

from datetime import datetime
from sys import platform
import os
Expand Down
1 change: 1 addition & 0 deletions openadapt/capture/_windows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Allows for capturing the screen and audio on Windows."""

from datetime import datetime
from sys import platform
import os
Expand Down
1 change: 0 additions & 1 deletion openadapt/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Configuration module for OpenAdapt."""


from enum import Enum
from typing import Any, ClassVar, Type, Union
import json
Expand Down
8 changes: 2 additions & 6 deletions openadapt/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,22 @@ def get_engine() -> sa.engine:
return engine


def get_base(engine: sa.engine) -> sa.engine:
def get_base() -> sa.engine:
"""Create and return the base model with the provided engine.
Args:
engine (sa.engine): The database engine to bind to the base model.
Returns:
sa.engine: The base model object.
"""
metadata = MetaData(naming_convention=NAMING_CONVENTION)
Base = declarative_base(
cls=BaseModel,
bind=engine,
metadata=metadata,
)
return Base


engine = get_engine()
Base = get_base(engine)
Base = get_base()
Session = sessionmaker(bind=engine)


Expand Down
1 change: 1 addition & 0 deletions openadapt/db/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Usage: python -m openadapt.db.remove [--all | --latest | --id <recording_id>]
"""

from sys import stdout

import click
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions openadapt/error_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ def show_alert() -> None:
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowIcon(QIcon(ICON_PATH))
msg.setText("""
msg.setText(
"""
An error has occurred. The development team has been notified.
Please join the discord server to get help or send an email to
help@openadapt.ai
""")
"""
)
discord_button = QPushButton("Join the discord server")
discord_button.clicked.connect(
lambda: webbrowser.open("https://discord.gg/yF527cQbDG")
Expand Down
1 change: 0 additions & 1 deletion openadapt/extensions/synchronized_queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Module for customizing multiprocessing.Queue to avoid NotImplementedError."""


from multiprocessing.queues import Queue
from typing import Any
import multiprocessing
Expand Down
18 changes: 12 additions & 6 deletions openadapt/productivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from openadapt.utils import configure_logging, image2utf8, row2dict, rows2dicts
from openadapt.visualize import IMG_WIDTH_PCT, MAX_EVENTS, dict2html

CSS = string.Template("""
CSS = string.Template(
"""
table {
outline: 1px solid black;
}
Expand All @@ -46,7 +47,8 @@
.screenshot:active img:nth-child(1) {
display: block;
}
""").substitute(
"""
).substitute(
IMG_WIDTH_PCT=IMG_WIDTH_PCT,
)

Expand Down Expand Up @@ -587,11 +589,13 @@ def calculate_productivity() -> None:
</table>
""",
),
Div(text=f"""
Div(
text=f"""
<table>
{dict2html(window_info)}
</table>
"""),
"""
),
),
]
)
Expand Down Expand Up @@ -638,11 +642,13 @@ def calculate_productivity() -> None:
</table>
""",
),
Div(text=f"""
Div(
text=f"""
<table>
{dict2html(window_info)}
</table>
"""),
"""
),
),
]
)
Expand Down
1 change: 0 additions & 1 deletion openadapt/scrub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Scrubbing module for OpenAdapt."""


from queue import Queue
from threading import Thread
import multiprocessing
Expand Down
1 change: 0 additions & 1 deletion openadapt/spacy_model_helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Init file for spacy_model_helpers package."""


from .download_model import download_spacy_model

__all__ = ["download_spacy_model"]
13 changes: 5 additions & 8 deletions openadapt/spacy_model_helpers/download_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Download the spacy model."""


import json
import os
import pathlib
Expand Down Expand Up @@ -67,13 +66,11 @@ def download_latest_model_version() -> str:
for filename in filenames:
if filename.endswith(".whl"):
continue
relative_path = (
f"{pathlib.Path(dirpath).relative_to(model_dir)}/{filename}"
.replace(
"\\", "/"
).replace(
"./", ""
)
# TODO: noqa below is a hack to force compatibility between flake8/black
relative_path = f"{pathlib.Path(dirpath).relative_to(model_dir)}/{filename}".replace( # noqa: E501
"\\", "/"
).replace(
"./", ""
)
url = (
"https://huggingface.co/spacy/en_core_web_trf/resolve/main/"
Expand Down
1 change: 0 additions & 1 deletion openadapt/spacy_model_helpers/spacy_model_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Spacy model init file."""


from pathlib import Path

from spacy.language import Language
Expand Down
1 change: 1 addition & 0 deletions openadapt/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Usage:
python3 -m openadapt.start
"""

import subprocess

from openadapt.app.main import run_app
Expand Down
Loading

0 comments on commit 50e4a3e

Please sign in to comment.