Skip to content

Commit

Permalink
remove custom visualize function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mustaballer committed Dec 11, 2023
1 parent 0edcd88 commit 1367cb9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 60 deletions.
2 changes: 0 additions & 2 deletions openadapt/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""Package for interacting with the OpenAdapt database."""

from .db import export_recording
52 changes: 1 addition & 51 deletions openadapt/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Usage:
python -m openadapt.share send --recording_id=1
python -m openadapt.share receive <wormhole_code>
python -m openadapt.share visualize <db_name>
"""

from zipfile import ZIP_DEFLATED, ZipFile
Expand All @@ -12,11 +11,9 @@
import subprocess

from loguru import logger
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
import fire

from openadapt import config, db, utils, visualize
from openadapt import config, db, utils

LOG_LEVEL = "INFO"
utils.configure_logging(logger, LOG_LEVEL)
Expand Down Expand Up @@ -152,58 +149,11 @@ def receive_recording(wormhole_code: str) -> None:
logger.info(f"deleted {zip_path=}")


def visualize_recording(db_name: str) -> None:
"""Visualize a recording from a SQLite database.
This function loads the specified db file containing a recording and
visualizes the data using the 'visualize.main' function.
Args:
db_name (str): The name of the SQLite database containing the recording.
Raises:
Exception: If there is an error accessing the database.
"""
# Determine the recording path based on the database name
if db_name == "openadapt.db":
recording_path = os.path.join(config.ROOT_DIRPATH, db_name)
else:
recording_path = os.path.join(config.RECORDING_DIRECTORY_PATH, db_name)

recording_url = f"sqlite:///{recording_path}"

# Save the old value of DB_FNAME
old_val = os.getenv("DB_FNAME")

# Update the environment variable DB_FNAME and persist it
config.persist_env("DB_FNAME", db_name)
os.environ["DB_FNAME"] = db_name

# Set the database URL
config.set_db_url(db_name)

engine = create_engine(recording_url)

try:
with Session(engine) as session:
os.system("alembic upgrade head")
# Visualize the recording
visualize.main(None, False, session)
except Exception as exc:
# Handle any exceptions that may occur during visualization
logger.exception(exc)
finally:
# Restore the old value of DB_FNAME in case of exceptions or at the end
os.environ["DB_FNAME"] = old_val
config.persist_env("DB_FNAME", old_val)


# Create a command-line interface using python-fire and utils.get_functions
if __name__ == "__main__":
fire.Fire(
{
"send": send_recording,
"receive": receive_recording,
"visualize": visualize_recording,
}
)
9 changes: 2 additions & 7 deletions openadapt/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
from loguru import logger
from nicegui import events, ui
from notifypy import Notify
from sqlalchemy.orm import session
from tqdm import tqdm
import click

from openadapt import config
from openadapt.db.crud import db, get_latest_recording, get_recording
from openadapt.db.crud import get_latest_recording, get_recording
from openadapt.events import get_events
from openadapt.privacy.providers.presidio import PresidioScrubbingProvider
from openadapt.utils import (
EMPTY,
configure_logging,
Expand Down Expand Up @@ -134,11 +132,8 @@ def toggle_dark_mode(
type=str,
help="The timestamp of the recording to visualize.",
)
def main(timestamp: str, notify: bool = True, sesh: session.Session = None) -> None:
def main(timestamp: str, notify: bool = True) -> None:
"""Visualize a recording."""
if sesh:
db = sesh

configure_logging(logger, LOG_LEVEL)

ui_dark = ui.dark_mode(config.VISUALIZE_DARK_MODE)
Expand Down

0 comments on commit 1367cb9

Please sign in to comment.