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 event_procedure_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_str
23
24
25# procedure: HandleTouchDown, state: READY, disposal: NONE, timestamp: 2017-08-25 15:00:20.177
26class ProcedureStep(BaseBean):
27    procedure = ''
28    state = ''
29    disposal = ''
30    timestamp = ''
31
32    original_str = ''
33
34    def __init__(self, input_str):
35        super().__init__()
36        self.original_str = input_str
37        self.procedure = get_value_as_str(input_str, get_sample_key(event_procedure_keyword, 'procedure'),
38                                          get_sample_separator_count(event_procedure_keyword, 'procedure'))
39        self.state = get_value_as_str(input_str, get_sample_key(event_procedure_keyword, 'state'),
40                                      get_sample_separator_count(event_procedure_keyword, 'state'))
41        self.disposal = get_value_as_str(input_str, get_sample_key(event_procedure_keyword, 'disposal'),
42                                         get_sample_separator_count(event_procedure_keyword, 'disposal'))
43        self.timestamp = get_value_as_str(input_str, get_sample_key(event_procedure_keyword, 'timestamp'),
44                                          get_sample_separator_count(event_procedure_keyword, 'timestamp'), True)
45        self.check_parse_result()
46
47    def check_parse_result(self):
48        if self.procedure is None or self.timestamp is None:
49            self.parse_failed()
50        else:
51            self.parse_succeed()
52
53    def get_detailed_summary_string(self):
54        result_str = self.procedure
55        if self.state is not None:
56            result_str += ', state(' + self.state + ')'
57        if self.disposal is not None:
58            result_str += ', disposal(' + self.disposal + ')'
59        return result_str
60
61    def to_string(self):
62        result_str = '  procedure: ' + self.procedure
63        if self.state is not None:
64            result_str += ', state: ' + self.state
65        if self.disposal is not None:
66            result_str += ', disposal: ' + self.disposal
67        result_str += ', timestamp: ' + self.timestamp
68        return result_str
69
70    def dump(self):
71        log_info(self.to_string())
72