-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
WIP: Add replay logging mechanism #802
Draft
KIRA009
wants to merge
14
commits into
OpenAdaptAI:main
Choose a base branch
from
KIRA009:feature/replay-logs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
89e6aec
feat: Add replay logging mechanism
KIRA009 244e5ea
log dumping state
abrichr bba8a36
Merge branch 'main' into feature/replay-logs
KIRA009 7cd7076
lint: Fix linting errors
KIRA009 04121f1
feat: Reduce size of replay logs by commiting relevant data
KIRA009 97b4295
Merge branch 'main' into feature/replay-logs
KIRA009 5f1f1b9
temp
KIRA009 265bd0d
feat: Add segmentation logs to replay logs
KIRA009 ff324dd
Merge branch 'main' into feature/replay-logs
KIRA009 85027e9
fix: Fix visual replay strategy logs
KIRA009 f81dde6
lint: flake8 lint
KIRA009 db6d2c7
Merge branch 'main' into feature/replay-logs
KIRA009 b51a095
Merge branch 'main' into feature/replay-logs
KIRA009 fa137a7
feat: Add depth kwarg to replay log utility function
KIRA009 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
openadapt/alembic/versions/c84664aeb5ae_add_replay_models.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,62 @@ | ||
"""add_replay_models | ||
|
||
Revision ID: c84664aeb5ae | ||
Revises: bb25e889ad71 | ||
Create Date: 2024-06-25 15:05:09.110171 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
import openadapt | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "c84664aeb5ae" | ||
down_revision = "bb25e889ad71" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"replay", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column( | ||
"timestamp", | ||
openadapt.models.ForceFloat(precision=10, scale=2, asdecimal=False), | ||
nullable=True, | ||
), | ||
sa.Column("strategy_name", sa.String(), nullable=True), | ||
sa.Column("strategy_args", sa.JSON(), nullable=True), | ||
sa.Column("git_hash", sa.String(), nullable=True), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_replay")), | ||
) | ||
op.create_table( | ||
"replay_log", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("replay_id", sa.Integer(), nullable=True), | ||
sa.Column("lineno", sa.Integer(), nullable=True), | ||
sa.Column("filename", sa.String(), nullable=True), | ||
sa.Column("git_hash", sa.String(), nullable=True), | ||
sa.Column( | ||
"timestamp", | ||
openadapt.models.ForceFloat(precision=10, scale=2, asdecimal=False), | ||
nullable=True, | ||
), | ||
sa.Column("log_level", sa.String(), nullable=True), | ||
sa.Column("key", sa.String(), nullable=True), | ||
sa.Column("data", sa.LargeBinary(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["replay_id"], ["replay.id"], name=op.f("fk_replay_log_replay_id_replay") | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_replay_log")), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("replay_log") | ||
op.drop_table("replay") | ||
# ### 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
from openadapt.privacy.base import ScrubbingProvider, TextScrubbingMixin | ||
from openadapt.privacy.providers import ScrubProvider | ||
|
||
|
||
EMPTY_VALS = [None, "", [], (), {}] | ||
|
||
|
||
|
@@ -182,6 +181,26 @@ def __init__(self, **kwargs: dict) -> None: | |
for key, value in properties.items(): | ||
setattr(self, key, value) | ||
|
||
def to_log_dict(self) -> dict[str, Any]: | ||
"""Convert the action event to a log dictionary.""" | ||
return { | ||
"name": self.name, | ||
"timestamp": self.timestamp, | ||
"mouse_x": self.mouse_x, | ||
"mouse_y": self.mouse_y, | ||
"mouse_dx": self.mouse_dx, | ||
"mouse_dy": self.mouse_dy, | ||
"mouse_button_name": self.mouse_button_name, | ||
"mouse_pressed": self.mouse_pressed, | ||
"key_name": self.key_name, | ||
"key_char": self.key_char, | ||
"key_vk": self.key_vk, | ||
"canonical_key_name": self.canonical_key_name, | ||
"canonical_key_char": self.canonical_key_char, | ||
"canonical_key_vk": self.canonical_key_vk, | ||
"element_state": self.element_state, | ||
} | ||
|
||
@property | ||
def available_segment_descriptions(self) -> list[str]: | ||
"""Gets the available segment descriptions.""" | ||
|
@@ -930,6 +949,24 @@ class Replay(db.Base): | |
strategy_name = sa.Column(sa.String) | ||
strategy_args = sa.Column(sa.JSON) | ||
git_hash = sa.Column(sa.String) | ||
logs = sa.orm.relationship("ReplayLog", back_populates="replay") | ||
|
||
|
||
class ReplayLog(db.Base): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about renaming "Replay" to "Execution" and "ReplayLog" to "ExecutionLog"? |
||
"""Class representing a replay log in the database.""" | ||
|
||
__tablename__ = "replay_log" | ||
|
||
id = sa.Column(sa.Integer, primary_key=True) | ||
replay_id = sa.Column(sa.ForeignKey("replay.id")) | ||
replay = sa.orm.relationship("Replay", back_populates="logs") | ||
lineno = sa.Column(sa.Integer) | ||
filename = sa.Column(sa.String) | ||
git_hash = sa.Column(sa.String) | ||
timestamp = sa.Column(ForceFloat) | ||
log_level = sa.Column(sa.String) | ||
key = sa.Column(sa.String) | ||
data = sa.Column(sa.LargeBinary) | ||
|
||
|
||
def copy_sa_instance(sa_instance: db.Base, **kwargs: dict) -> db.Base: | ||
|
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use
asdict()
?Edit: if the goal is to remove unnecessary properties, what do you think about overriding asdict, calling the super method, then removing the unnecessary keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that makes more sense