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_COMPONMENT_H 17 #define TEST_WUKONG_STATISTICS_COMPONMENT_H 18 19 #include <string> 20 21 #include "statistics.h" 22 #include "wukong_define.h" 23 24 namespace OHOS { 25 namespace WuKong { 26 27 class ComponmentStatisticsRecord { 28 public: 29 std::string componmentType_ = ""; 30 uint32_t execTimes_ = 0; 31 uint32_t inputedTimes_ = 0; 32 uint32_t expectInputTimes_ = 0; 33 }; 34 35 class ComponmentStatisticsMsg { 36 public: 37 /* 38 * @brief find componmentType position in componmentTypes_ 39 * @param componmentType 40 * @return index 41 */ ComponmentTypesIndex(const std::string & componmentType)42 uint32_t ComponmentTypesIndex(const std::string &componmentType) 43 { 44 uint32_t index = componmentTypes_.size(); 45 TRACK_LOG_STR("componmentTypes_.size{%d}", index); 46 uint32_t findIndex = WuKongUtil::GetInstance()->FindElement(componmentTypes_, componmentType); 47 if (findIndex != INVALIDVALUE) { 48 DEBUG_LOG_STR("findIndex{%d}", findIndex); 49 index = findIndex; 50 } 51 TRACK_LOG_STR("current componmentType find index{%d}", index); 52 return index; 53 } 54 std::vector<std::string> componmentTypes_; 55 std::vector<std::shared_ptr<ComponmentStatisticsRecord>> componmentTypeRecord_; 56 uint32_t componmentTypeTotal_ = 0; 57 }; 58 class StatisticsComponment : public Statistics { 59 public: 60 StatisticsComponment() = default; 61 ~StatisticsComponment() = default; 62 void StatisticsDetail(std::vector<std::map<std::string, std::string>> srcDatas, 63 std::map<std::string, std::shared_ptr<Table>> &destTables); 64 65 private: 66 /* 67 * @brief statistics msg update to line 68 * @param ComponmentStatisticsRecordPtr store statistics msg 69 * @param componmentTypeTotal Proportion to calculate the total 70 * @param line output 71 * @return void 72 */ 73 void UpdateLine(std::shared_ptr<ComponmentStatisticsRecord> ComponmentStatisticsRecordPtr, uint32_t componmentTypeTotal, 74 std::vector<std::string> &line); 75 /* 76 * @brief Realize secondary classification and update statistics of source data through bundleName and componment 77 * methods 78 * @param srcDatas filtered data 79 * @return void 80 */ 81 void SrcDatasPretreatment(std::vector<std::map<std::string, std::string>> srcDatas); 82 /* 83 * @brief Global Statistics for ComponmentTypesmethods 84 * @return void 85 */ 86 void GlobalComponmentTypeStatistics(); 87 88 // bundle map ComponmentStatisticsMsgPtr 89 std::map<std::string, std::shared_ptr<ComponmentStatisticsMsg>> componmentStatisticsMsg_; 90 // all componmentType record for global statistics used 91 std::vector<std::string> globalComponmentTypes_; 92 std::vector<std::string> headers_ = {"type", "execTimes", "proportion", 93 "inputedTimes", "expectInputTimes", "coverage"}; 94 std::vector<std::vector<std::string>> record_; 95 uint32_t execCount_ = 0; 96 }; 97 } // namespace WuKong 98 } // namespace OHOS 99 #endif 100