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