/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef TEST_WUKONG_STATISTICS_EVENT_H #define TEST_WUKONG_STATISTICS_EVENT_H #include #include #include "data_set.h" #include "statistics.h" #include "wukong_define.h" namespace OHOS { namespace WuKong { class EventStatisticsRecord { public: std::string eventType_ = ""; uint32_t execTimes_ = 0; }; class EventStatisticsMsg { public: /* * @brief find eventType position in eventTypes_ * @param eventType * @return index */ uint32_t ElementTypesIndex(const std::string &eventType) { uint32_t index = eventTypes_.size(); TRACK_LOG_STR("eventTypes_.size{%d}", index); std::vector::iterator eventTypesIter; eventTypesIter = find(eventTypes_.begin(), eventTypes_.end(), eventType); if (eventTypesIter != eventTypes_.end()) { index = (uint32_t)(eventTypesIter - eventTypes_.begin()); DEBUG_LOG_STR("find index{%d}", index); } TRACK_LOG_STR("find index{%d}", index); return index; } std::vector eventTypes_; std::vector> eventTypeRecord_; uint32_t eventTypeTotal_ = 0; }; class StatisticsEvent : public Statistics { public: StatisticsEvent() = default; ~StatisticsEvent() = default; void StatisticsDetail(std::vector> srcDatas, std::map> &destTables); private: /* * @brief statistics msg update to line * @param EventStatisticsRecordPtr store statistics msg * @param eventTypeTotal Proportion to calculate the total * @param line output * @return void */ void UpdateLine(std::shared_ptr eventStatisticsRecordPtr, uint32_t eventTypeTotal, std::vector &line); /* * @brief Realize secondary classification and update statistics of source data through bundleName and event * methods * @param srcDatas filtered data * @return void */ void SrcDatasPretreatment(std::vector> srcDatas); /* * @brief Global Statistics for ElementTypesmethods * @return void */ void GlobalElementTypesStatistics(); // bundle map EventStatisticsMsgPtr std::map> eventStatisticsMsg_; // all eventTypes record for global statistics used std::vector globalElementTypes_; std::vector headers_ = {"type", "execTimes", "proportion"}; std::vector> record_; int execCount_ = 0; }; } // namespace WuKong } // namespace OHOS #endif