1 /* 2 * Copyright (C) 2024 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 #ifndef OHOS_MEDIA_BACKUP_STATISTIC_PROCESSOR_H 16 #define OHOS_MEDIA_BACKUP_STATISTIC_PROCESSOR_H 17 18 #include <string> 19 #include <vector> 20 21 #include "rdb_store.h" 22 #include "result_set_utils.h" 23 #include "media_backup_report_data_type.h" 24 25 namespace OHOS::Media { 26 class StatisticProcessor { 27 public: ParseTotalCount(std::unordered_map<std::string,AlbumMediaStatisticInfo> & albumInfoMap,const std::vector<AlbumStatisticInfo> & countInfoList)28 StatisticProcessor &ParseTotalCount(std::unordered_map<std::string, AlbumMediaStatisticInfo> &albumInfoMap, 29 const std::vector<AlbumStatisticInfo> &countInfoList) 30 { 31 for (const auto &info : countInfoList) { 32 if (albumInfoMap.find(info.lPath) == albumInfoMap.end()) { 33 albumInfoMap[info.lPath] = AlbumMediaStatisticInfo(); 34 } 35 albumInfoMap[info.lPath].lPath = info.lPath; 36 albumInfoMap[info.lPath].albumName = info.albumName; 37 albumInfoMap[info.lPath].totalCount = info.count; 38 } 39 return *this; 40 } 41 ParseImageCount(std::unordered_map<std::string,AlbumMediaStatisticInfo> & albumInfoMap,const std::vector<AlbumStatisticInfo> & countInfoList)42 StatisticProcessor &ParseImageCount(std::unordered_map<std::string, AlbumMediaStatisticInfo> &albumInfoMap, 43 const std::vector<AlbumStatisticInfo> &countInfoList) 44 { 45 for (const auto &info : countInfoList) { 46 if (albumInfoMap.find(info.lPath) == albumInfoMap.end()) { 47 albumInfoMap[info.lPath] = AlbumMediaStatisticInfo(); 48 } 49 albumInfoMap[info.lPath].lPath = info.lPath; 50 albumInfoMap[info.lPath].albumName = info.albumName; 51 albumInfoMap[info.lPath].imageCount = info.count; 52 } 53 return *this; 54 } 55 ParseVideoCount(std::unordered_map<std::string,AlbumMediaStatisticInfo> & albumInfoMap,const std::vector<AlbumStatisticInfo> & countInfoList)56 StatisticProcessor &ParseVideoCount(std::unordered_map<std::string, AlbumMediaStatisticInfo> &albumInfoMap, 57 const std::vector<AlbumStatisticInfo> &countInfoList) 58 { 59 for (const auto &info : countInfoList) { 60 if (albumInfoMap.find(info.lPath) == albumInfoMap.end()) { 61 albumInfoMap[info.lPath] = AlbumMediaStatisticInfo(); 62 } 63 albumInfoMap[info.lPath].lPath = info.lPath; 64 albumInfoMap[info.lPath].albumName = info.albumName; 65 albumInfoMap[info.lPath].videoCount = info.count; 66 } 67 return *this; 68 } 69 ParseCloudCount(std::unordered_map<std::string,AlbumMediaStatisticInfo> & albumInfoMap,const std::vector<AlbumStatisticInfo> & countInfoList)70 StatisticProcessor &ParseCloudCount(std::unordered_map<std::string, AlbumMediaStatisticInfo> &albumInfoMap, 71 const std::vector<AlbumStatisticInfo> &countInfoList) 72 { 73 for (const auto &info : countInfoList) { 74 if (albumInfoMap.find(info.lPath) == albumInfoMap.end()) { 75 albumInfoMap[info.lPath] = AlbumMediaStatisticInfo(); 76 } 77 albumInfoMap[info.lPath].lPath = info.lPath; 78 albumInfoMap[info.lPath].albumName = info.albumName; 79 albumInfoMap[info.lPath].cloudCount = info.count; 80 } 81 return *this; 82 } 83 }; 84 } // namespace OHOS::Media 85 #endif // OHOS_MEDIA_BACKUP_STATISTIC_PROCESSOR_H