| 168 | self.eval_android_control = eval_android_control |
| 169 | |
| 170 | def action_map(self, action_api: dict): |
| 171 | action = action_api.get('ACTION', None) |
| 172 | args = action_api.get('ARGS', None) |
| 173 | status = action_api.get('STATUS', None) |
| 174 | duration = args.get('duration', default_duration) if args else None |
| 175 | |
| 176 | if action is None and args is None and status is None: |
| 177 | print('Schema error.') |
| 178 | return None, {} |
| 179 | elif status in self._stop_status: |
| 180 | return "stop", {} |
| 181 | elif "TYPE" in action: |
| 182 | return "type", action['TYPE'] |
| 183 | elif "POINT" in action and "to" not in args and duration == default_duration: # click |
| 184 | return "click", action['POINT'] |
| 185 | elif "POINT" in action and "to" in args and duration == default_duration: # swipte |
| 186 | return "scroll", {"start": action['POINT'], "end": args['to']} |
| 187 | elif "POINT" in action and "duration" in args and duration > default_duration: # long press |
| 188 | return "long_point", {"coordinate": action['POINT'], "duration": args['duration']} |
| 189 | elif "PRESS" in action: |
| 190 | return "press", action['PRESS'] |
| 191 | elif "duration" in args: # pause and wait |
| 192 | return "stop", args['duration'] |
| 193 | else: |
| 194 | raise ValueError("Unknown action type.") |
| 195 | |
| 196 | def _parse_action_(self, pred, image_width=None, image_height=None): |
| 197 | pd_action_type, pd_action_yx, pd_action_idx, pd_action_direction, pd_action_text, pd_action_button, pd_duration = (None, ) * 7 |