-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from MLDSAI/feat/window_state
Window state
- Loading branch information
Showing
28 changed files
with
1,150 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""add WindowEvent.state | ||
Revision ID: 57d78d23087a | ||
Revises: 20f9c2afb42c | ||
Create Date: 2023-05-14 18:32:57.473479 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '57d78d23087a' | ||
down_revision = '20f9c2afb42c' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('window_event', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('state', sa.JSON(), nullable=True)) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('window_event', schema=None) as batch_op: | ||
batch_op.drop_column('state') | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Window.window_id | ||
Revision ID: b2dc41850120 | ||
Revises: d63569e4fb90 | ||
Create Date: 2023-05-17 12:50:35.125610 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'b2dc41850120' | ||
down_revision = 'd63569e4fb90' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('window_event', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('window_id', sa.String(), nullable=True)) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('window_event', schema=None) as batch_op: | ||
batch_op.drop_column('window_id') | ||
|
||
# ### end Alembic commands ### |
32 changes: 32 additions & 0 deletions
32
alembic/versions/d63569e4fb90_actionevent_element_state.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""ActionEvent.element_state | ||
Revision ID: d63569e4fb90 | ||
Revises: ec337f277666 | ||
Create Date: 2023-05-16 21:43:00.120143 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'd63569e4fb90' | ||
down_revision = 'ec337f277666' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('action_event', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('element_state', sa.JSON(), nullable=True)) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('action_event', schema=None) as batch_op: | ||
batch_op.drop_column('element_state') | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""DateTime timestamp | ||
Revision ID: ec337f277666 | ||
Revises: 57d78d23087a | ||
Create Date: 2023-05-16 17:51:00.061604 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'ec337f277666' | ||
down_revision = '57d78d23087a' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('screenshot', schema=None) as batch_op: | ||
batch_op.create_foreign_key(batch_op.f('fk_screenshot_recording_timestamp_recording'), 'recording', ['recording_timestamp'], ['timestamp']) | ||
|
||
with op.batch_alter_table('window_event', schema=None) as batch_op: | ||
batch_op.create_foreign_key(batch_op.f('fk_window_event_recording_timestamp_recording'), 'recording', ['recording_timestamp'], ['timestamp']) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('window_event', schema=None) as batch_op: | ||
batch_op.drop_constraint(batch_op.f('fk_window_event_recording_timestamp_recording'), type_='foreignkey') | ||
|
||
with op.batch_alter_table('screenshot', schema=None) as batch_op: | ||
batch_op.drop_constraint(batch_op.f('fk_screenshot_recording_timestamp_recording'), type_='foreignkey') | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from functools import wraps | ||
import time | ||
|
||
from joblib import Memory | ||
from loguru import logger | ||
|
||
|
||
from openadapt import config | ||
|
||
|
||
def default(val, default): | ||
return val if val is not None else default | ||
|
||
|
||
def cache(dir_path=None, enabled=None, verbosity=None, **cache_kwargs): | ||
"""TODO""" | ||
|
||
cache_dir_path = default(dir_path, config.CACHE_DIR_PATH) | ||
cache_enabled = default(enabled, config.CACHE_ENABLED) | ||
cache_verbosity = default(verbosity, config.CACHE_VERBOSITY) | ||
def decorator(fn): | ||
@wraps(fn) | ||
def wrapper(*args, **kwargs): | ||
logger.debug(f"{cache_enabled=}") | ||
if cache_enabled: | ||
memory = Memory(cache_dir_path, verbose=cache_verbosity) | ||
nonlocal fn | ||
fn = memory.cache(fn, **cache_kwargs) | ||
cache_hit = fn.check_call_in_cache(*args, **kwargs) | ||
logger.debug(f"{fn=} {cache_hit=}") | ||
start_time = time.time() | ||
logger.debug(f"{fn=} {start_time=}") | ||
rval = fn(*args, **kwargs) | ||
duration = time.time() - start_time | ||
logger.debug(f"{fn=} {duration=}") | ||
return rval | ||
return wrapper | ||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
# processed | ||
"type", | ||
) | ||
ALL_EVENTS = tuple(list(MOUSE_EVENTS) + list(KEY_EVENTS)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
import multiprocessing | ||
import os | ||
import pathlib | ||
|
||
ROOT_DIRPATH = pathlib.Path(__file__).parent.parent.resolve() | ||
DB_FNAME = "openadapt.db" | ||
from dotenv import load_dotenv | ||
from loguru import logger | ||
|
||
|
||
_DEFAULTS = { | ||
"CACHE_DIR_PATH": ".cache", | ||
"CACHE_ENABLED": True, | ||
"CACHE_VERBOSITY": 0, | ||
"DB_ECHO": False, | ||
"DB_FNAME": "openadapt.db", | ||
"OPENAI_API_KEY": None, | ||
#"OPENAI_MODEL_NAME": "gpt-4", | ||
"OPENAI_MODEL_NAME": "gpt-3.5-turbo", | ||
# may incur significant performance penalty | ||
"RECORD_READ_ACTIVE_ELEMENT_STATE": False, | ||
# TODO: remove? | ||
"REPLAY_STRIP_ELEMENT_STATE": True, | ||
} | ||
|
||
|
||
def getenv_fallback(var_name): | ||
rval = os.getenv(var_name) or _DEFAULTS.get(var_name) | ||
if rval is None: | ||
raise ValueError(f"{var_name=} not defined") | ||
return rval | ||
|
||
|
||
load_dotenv() | ||
|
||
for key in _DEFAULTS: | ||
val = getenv_fallback(key) | ||
locals()[key] = val | ||
|
||
ROOT_DIRPATH = pathlib.Path(__file__).parent.parent.resolve() | ||
DB_FPATH = ROOT_DIRPATH / DB_FNAME | ||
DB_URL = f"sqlite:///{DB_FPATH}" | ||
DB_ECHO = False | ||
|
||
if multiprocessing.current_process().name == "MainProcess": | ||
for key, val in locals().items(): | ||
if not key.startswith("_") and key.isupper(): | ||
logger.info(f"{key}={val}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.