1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# 5# Copyright (c) 2024 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19from src.beans.base_bean import BaseBean 20from src.keywords import touch_point_keyword, get_sample_key, get_sample_separator_count 21from src.utils.log_wrapper import log_info 22from src.utils.value_parser import get_value_as_int, get_value_as_str 23 24 25# id: 0, point: Offset (278.00, 551.00), screenPoint: Offset (278.00, 551.00), type: TouchUp, timestamp: 2017-08-25 26# 15:00:22.295, isInjected: 0 27class TouchPoint(BaseBean): 28 id = 0 29 point = '' 30 screenPoint = '' 31 type = '' 32 timestamp = '' 33 isInjected = 0 34 original_str = '' 35 36 def __init__(self, input_str): 37 super().__init__() 38 self.original_str = input_str 39 self.id = get_value_as_int(input_str, get_sample_key(touch_point_keyword, 'id'), 40 get_sample_separator_count(touch_point_keyword, 'id')) 41 self.point = get_value_as_str(input_str, get_sample_key(touch_point_keyword, 'point'), 42 get_sample_separator_count(touch_point_keyword, 'point')) 43 self.screenPoint = get_value_as_str(input_str, get_sample_key(touch_point_keyword, 'screenPoint'), 44 get_sample_separator_count(touch_point_keyword, 'screenPoint')) 45 self.type = get_value_as_str(input_str, get_sample_key(touch_point_keyword, 'type'), 46 get_sample_separator_count(touch_point_keyword, 'type')) 47 self.timestamp = get_value_as_str(input_str, get_sample_key(touch_point_keyword, 'timestamp'), 48 get_sample_separator_count(touch_point_keyword, 'timestamp')) 49 self.isInjected = get_value_as_int(input_str, get_sample_key(touch_point_keyword, 'isInjected'), 50 get_sample_separator_count(touch_point_keyword, 'isInjected'), True) 51 self.check_parse_result() 52 53 def check_parse_result(self): 54 if (self.id is None or self.point is None or self.screenPoint is None or self.type is None or self.timestamp 55 is None or self.isInjected is None): 56 self.parse_failed() 57 else: 58 self.parse_succeed() 59 60 def to_string(self): 61 return ('id: {}, point: {}, screenPoint: {}, type: {}, timestamp: {}, isInjected: {}' 62 .format(self.id, self.point, self.screenPoint, self.type, self.timestamp, self.isInjected)) 63 64 def to_summary_string(self): 65 return ('id: {}, {}, {}, {}, {}' 66 .format(str(self.id), self.point, self.screenPoint, self.type, self.timestamp)) 67 68 def dump(self): 69 log_info(self.to_string()) 70