8
8
9
9
from copy import deepcopy
10
10
from pprint import pformat
11
- #import datetime
11
+
12
+ # import datetime
12
13
13
14
from loguru import logger
14
15
import deepdiff
@@ -25,7 +26,6 @@ class StatefulReplayStrategy(
25
26
OpenAIReplayStrategyMixin ,
26
27
strategies .base .BaseReplayStrategy ,
27
28
):
28
-
29
29
def __init__ (
30
30
self ,
31
31
recording : models .Recording ,
@@ -39,8 +39,7 @@ def __init__(
39
39
for action_event in self .recording .processed_action_events
40
40
][:- 1 ]
41
41
self .recording_action_diff_tups = zip (
42
- self .recording_window_state_diffs ,
43
- self .recording_action_strs
42
+ self .recording_window_state_diffs , self .recording_action_strs
44
43
)
45
44
self .recording_action_idx = 0
46
45
@@ -52,53 +51,63 @@ def get_next_action_event(
52
51
logger .debug (f"{ self .recording_action_idx = } " )
53
52
if self .recording_action_idx == len (self .recording .processed_action_events ):
54
53
raise StopIteration ()
55
- reference_action = (
56
- self .recording . processed_action_events [ self . recording_action_idx ]
57
- )
54
+ reference_action = self . recording . processed_action_events [
55
+ self .recording_action_idx
56
+ ]
58
57
reference_window = reference_action .window_event
59
58
60
- reference_window_dict = deepcopy ({
61
- key : val
62
- for key , val in utils .row2dict (reference_window , follow = False ).items ()
63
- if val is not None
64
- and not key .endswith ("timestamp" )
65
- and not key .endswith ("id" )
66
- #and not isinstance(getattr(models.WindowEvent, key), property)
67
- })
59
+ reference_window_dict = deepcopy (
60
+ {
61
+ key : val
62
+ for key , val in utils .row2dict (reference_window , follow = False ).items ()
63
+ if val is not None
64
+ and not key .endswith ("timestamp" )
65
+ and not key .endswith ("id" )
66
+ # and not isinstance(getattr(models.WindowEvent, key), property)
67
+ }
68
+ )
68
69
if reference_action .children :
69
70
reference_action_dicts = [
70
- deepcopy ({
71
- key : val
72
- for key , val in utils .row2dict (child , follow = False ).items ()
73
- if val is not None
74
- and not key .endswith ("timestamp" )
75
- and not key .endswith ("id" )
76
- and not isinstance (getattr (models .ActionEvent , key ), property )
77
- })
71
+ deepcopy (
72
+ {
73
+ key : val
74
+ for key , val in utils .row2dict (child , follow = False ).items ()
75
+ if val is not None
76
+ and not key .endswith ("timestamp" )
77
+ and not key .endswith ("id" )
78
+ and not isinstance (getattr (models .ActionEvent , key ), property )
79
+ }
80
+ )
78
81
for child in reference_action .children
79
82
]
80
83
else :
81
84
reference_action_dicts = [
82
- deepcopy ({
83
- key : val
84
- for key , val in utils .row2dict (reference_action , follow = False ).items ()
85
- if val is not None
86
- and not key .endswith ("timestamp" )
87
- and not key .endswith ("id" )
88
- #and not isinstance(getattr(models.ActionEvent, key), property)
89
- })
85
+ deepcopy (
86
+ {
87
+ key : val
88
+ for key , val in utils .row2dict (
89
+ reference_action , follow = False
90
+ ).items ()
91
+ if val is not None
92
+ and not key .endswith ("timestamp" )
93
+ and not key .endswith ("id" )
94
+ # and not isinstance(getattr(models.ActionEvent, key), property)
95
+ }
96
+ )
90
97
]
91
- active_window_dict = deepcopy ({
92
- key : val
93
- for key , val in utils .row2dict (active_window , follow = False ).items ()
94
- if val is not None
95
- and not key .endswith ("timestamp" )
96
- and not key .endswith ("id" )
97
- #and not isinstance(getattr(models.WindowEvent, key), property)
98
- })
98
+ active_window_dict = deepcopy (
99
+ {
100
+ key : val
101
+ for key , val in utils .row2dict (active_window , follow = False ).items ()
102
+ if val is not None
103
+ and not key .endswith ("timestamp" )
104
+ and not key .endswith ("id" )
105
+ # and not isinstance(getattr(models.WindowEvent, key), property)
106
+ }
107
+ )
99
108
if reference_window_dict and "state" in reference_window_dict :
100
109
reference_window_dict ["state" ].pop ("data" )
101
- if active_window_dict and "state" in active_window_dict :
110
+ if active_window_dict and "state" in active_window_dict :
102
111
active_window_dict ["state" ].pop ("data" )
103
112
104
113
prompt = (
@@ -145,16 +154,16 @@ def get_window_state_diffs(
145
154
ignore_window_ids = set ()
146
155
if ignore_boundary_windows :
147
156
first_window_event = action_events [0 ].window_event
148
- if first_window_event .state :
157
+ if first_window_event .state :
149
158
first_window_id = first_window_event .state ["window_id" ]
150
- else :
159
+ else :
151
160
first_window_id = None
152
161
first_window_title = first_window_event .title
153
162
last_window_event = action_events [- 1 ].window_event
154
- if last_window_event .state :
163
+ if last_window_event .state :
155
164
last_window_id = last_window_event .state ["window_id" ]
156
165
last_window_title = last_window_event .title
157
- else :
166
+ else :
158
167
last_window_id = None
159
168
last_window_title = last_window_event .title
160
169
if first_window_id != last_window_id :
@@ -164,7 +173,8 @@ def get_window_state_diffs(
164
173
logger .info (f"ignoring { first_window_title = } { last_window_title = } " )
165
174
window_event_states = [
166
175
action_event .window_event .state
167
- if action_event .window_event .state is not None and action_event .window_event .state ["window_id" ] not in ignore_window_ids
176
+ if action_event .window_event .state is not None
177
+ and action_event .window_event .state ["window_id" ] not in ignore_window_ids
168
178
else {}
169
179
for action_event in action_events
170
180
]
@@ -174,4 +184,4 @@ def get_window_state_diffs(
174
184
window_event_states , window_event_states [1 :]
175
185
)
176
186
]
177
- return diffs
187
+ return diffs
0 commit comments