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

WIP: Add replay logging mechanism #802

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
20 changes: 20 additions & 0 deletions openadapt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,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]:
Copy link
Member

@abrichr abrichr Jul 15, 2024

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?

Copy link
Contributor Author

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

"""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."""
Expand Down
2 changes: 1 addition & 1 deletion openadapt/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def run(self) -> None:
replay_id=self._replay_id,
log_level="INFO",
key="action_event",
data=action_event,
data=action_event.to_log_dict(),
)
except StopIteration:
break
Expand Down
Loading