Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abrichr committed May 26, 2023
1 parent 15f7c31 commit cc1dfea
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 81 deletions.
4 changes: 2 additions & 2 deletions puterbot/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def make_parent_event(child, extra=None):


# Set by_diff_distance=True to compute distance from mouse to screenshot diff
# (computationally expensive but more keeps useful events)
# (computationally expensive but keeps more useful events)
def merge_consecutive_mouse_move_events(events, by_diff_distance=False):
"""Merge consecutive mouse move events into a single move event"""

Expand Down Expand Up @@ -297,7 +297,7 @@ def get_timestamp_mappings(to_merge):
dx = abs(event.mouse_x - prev_pressed_event.mouse_x)
dy = abs(event.mouse_y - prev_pressed_event.mouse_y)
if (
dt <= timedelta(seconds=double_click_interval) and
dt.seconds <= double_click_interval and
dx <= double_click_distance and
dy <= double_click_distance
):
Expand Down
37 changes: 0 additions & 37 deletions puterbot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,45 +194,8 @@ def __str__(self):
_text_name_prefix = "<"
_text_name_suffix = ">"

@classmethod
def recreate_children(cls, data):
# XXX not useful since doesn't include press and release actions

# {'canonical_text': '<cmd>-<49>', 'name': 'type', 'text': '<cmd>-<space>'}


def get_key_names(text):
# TODO XXX: handle text == None
text_parts = text.split(cls._text_sep)
key_names = [
part.strip(cls._text_name_prefix).strip(cls._text_name_suffix)
for part in text_parts
]
return key_names


key_names = get_key_names(data.pop("text", None))
canonical_key_names = get_key_names(data.pop("canonical_text", None))
children = []
for key_name, canonical_key_name in zip(key_names, canonical_key_names):
child_data = dict(data)
# TODO: assign to key_char/key_vk?
child_data["key_name"] = key_name
child_data["canonical_key_name"] = canonical_key_name
child = ActionEvent(**child_data)
children.append(child)
data["children"] = children
parent = ActionEvent(**data)
return parent


@classmethod
def from_children(cls, children_dicts):
#[{'canonical_key_name': 'cmd', 'key_name': 'cmd', 'name': 'press'},
# {'canonical_key_vk': '49', 'key_name': 'space', 'name': 'press'},
# {'canonical_key_name': 'cmd', 'key_name': 'cmd', 'name': 'release'},
# {'canonical_key_vk': '49', 'key_name': 'space', 'name': 'release'}]

children = [
ActionEvent(**child_dict)
for child_dict in children_dicts
Expand Down
4 changes: 2 additions & 2 deletions puterbot/strategies/naive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@


DISPLAY_EVENTS = False
PROCESS_EVENTS = True
PROCESS_EVENTS = False
REPLAY_EVENTS = True
SLEEP = True
SLEEP = False


class NaiveReplayStrategy(strategies.base.BaseReplayStrategy):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
alembic==1.8.1
ascii_magic==2.3.0
git+https://github.com/abrichr/atomacos.git
git+https://github.com/abrichr/atomacos.git; sys_platform == 'darwin'
bokeh==2.4.3
clipboard==0.0.4
deepdiff[optimize]==6.3.0
Expand Down
46 changes: 7 additions & 39 deletions tests/puterbot/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,48 +324,16 @@ def test_merge_consecutive_mouse_scroll_events():

def test_remove_redundant_mouse_move_events():
# certain failure modes only appear in longer event chains
raw_events = list(itertools.chain(*[
[
make_move_event(1),
make_click_event(True, 1),
make_move_event(1),
make_click_event(False, 1),
make_move_event(2),
make_click_event(True, 2),
make_move_event(3),
make_click_event(False, 3),
make_move_event(3),
]
for _ in range(2)
]))
raw_events = [
make_move_event(1),
make_move_event(2),
make_move_event(3),
make_move_event(4),
]
logger.info(f"raw_events=\n{pformat(rows2dicts(raw_events))}")
reset_timestamp()
expected_events = rows2dicts([
make_click_event(True, 1, get_pre_children=lambda: [
make_move_event(1),
]),
make_click_event(False, 1, get_post_children=lambda: [
make_move_event(1),
]),
make_click_event(True, 2, get_post_children=lambda: [
make_move_event(2),
]),
make_click_event(False, 3, get_post_children=lambda: [
make_move_event(3),
]),
make_click_event(True, 1, get_post_children=lambda: [
make_move_event(3),
make_move_event(1),
]),
make_click_event(False, 1, get_post_children=lambda: [
make_move_event(1),
]),
make_click_event(True, 2, get_post_children=lambda: [
make_move_event(2),
]),
make_click_event(False, 3, get_post_children=lambda: [
make_move_event(3),
]),
make_move_event(4),
])
logger.info(f"expected_events=\n{pformat(expected_events)}")
actual_events = rows2dicts(
Expand Down

0 comments on commit cc1dfea

Please sign in to comment.