• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TEST_WUKONG_STATISTICS_EVENT_H
17 #define TEST_WUKONG_STATISTICS_EVENT_H
18 
19 #include <iomanip>
20 #include <string>
21 
22 #include "data_set.h"
23 #include "statistics.h"
24 #include "wukong_define.h"
25 
26 namespace OHOS {
27 namespace WuKong {
28 class EventStatisticsRecord {
29 public:
30     std::string eventType_ = "";
31     uint32_t execTimes_ = 0;
32 };
33 
34 class EventStatisticsMsg {
35 public:
36     /*
37      * @brief find eventType position in eventTypes_
38      * @param eventType
39      * @return index
40      */
ElementTypesIndex(const std::string & eventType)41     uint32_t ElementTypesIndex(const std::string &eventType)
42     {
43         uint32_t index = eventTypes_.size();
44         TRACK_LOG_STR("eventTypes_.size{%d}", index);
45         std::vector<std::string>::iterator eventTypesIter;
46         eventTypesIter = find(eventTypes_.begin(), eventTypes_.end(), eventType);
47         if (eventTypesIter != eventTypes_.end()) {
48             index = (uint32_t)(eventTypesIter - eventTypes_.begin());
49             DEBUG_LOG_STR("find index{%d}", index);
50         }
51         TRACK_LOG_STR("find index{%d}", index);
52         return index;
53     }
54     std::vector<std::string> eventTypes_;
55     std::vector<std::shared_ptr<EventStatisticsRecord>> eventTypeRecord_;
56     uint32_t eventTypeTotal_ = 0;
57 };
58 
59 class StatisticsEvent : public Statistics {
60 public:
61     StatisticsEvent() = default;
62     ~StatisticsEvent() = default;
63     void StatisticsDetail(std::vector<std::map<std::string, std::string>> srcDatas,
64                           std::map<std::string, std::shared_ptr<Table>> &destTables);
65 
66 private:
67     /*
68      * @brief statistics msg update to line
69      * @param EventStatisticsRecordPtr store statistics msg
70      * @param eventTypeTotal Proportion to calculate the total
71      * @param line output
72      * @return void
73      */
74     void UpdateLine(std::shared_ptr<EventStatisticsRecord> eventStatisticsRecordPtr, uint32_t eventTypeTotal,
75                     std::vector<std::string> &line);
76     /*
77      * @brief Realize secondary classification and update statistics of source data through bundleName and event
78      * methods
79      * @param srcDatas filtered data
80      * @return void
81      */
82     void SrcDatasPretreatment(std::vector<std::map<std::string, std::string>> srcDatas);
83     /*
84      * @brief Global Statistics for ElementTypesmethods
85      * @return void
86      */
87     void GlobalElementTypesStatistics();
88 
89     // bundle map EventStatisticsMsgPtr
90     std::map<std::string, std::shared_ptr<EventStatisticsMsg>> eventStatisticsMsg_;
91     // all eventTypes record for global statistics used
92     std::vector<std::string> globalElementTypes_;
93 
94     std::vector<std::string> headers_ = {"type", "execTimes", "proportion"};
95     std::vector<std::vector<std::string>> record_;
96     int execCount_ = 0;
97 };
98 }  // namespace WuKong
99 }  // namespace OHOS
100 #endif
101