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 16import { secToTime } from '../common/utils/TimeUtils'; 17import { TIndexInfo } from '../common/entity/DatabaseEntity'; 18import router from '@system.router'; 19import { Summary } from '../common/ui/detail/Summary'; 20import { PowerDubai } from '../common/ui/detail/PowerDubai'; 21import { Performance } from '../common/ui/detail/Performance'; 22import { Load } from '../common/ui/detail/Load'; 23import { Temperature } from '../common/ui/detail/Temperature'; 24import { StartTestTitleComponent } from '../common/ui/StartTestTitleComponent'; 25import { ReportItem } from '../common/entity/LocalConfigEntity'; 26import CheckEmptyUtils from'../common/utils/CheckEmptyUtils' 27 28import { TPowerSensorInfo, TPowerAppInfo } from '../common/entity/DatabaseEntity'; 29import database from '../common/database/DatabaseUtils'; 30import SPLogger from '../common/utils/SPLogger' 31 32@Entry 33@Component 34struct ReportDetail { 35 private controller: TabsController = new TabsController() 36 private gpData: Array<TIndexInfo> = new Array() 37 private reportItem: ReportItem = null 38 private tPowerSensorList: Array<TPowerSensorInfo> = new Array<TPowerSensorInfo>() 39 private tPowerAppList: Array<TPowerAppInfo> = new Array<TPowerAppInfo>() 40 aboutToAppear() { 41 42 let data:any = router.getParams()["gpData"] 43 let report:any = router.getParams()["reportItem"] 44 let timeStamp:any = router.getParams()["timeStamp"] 45 if (data != null) { 46 this.gpData = data 47 } 48 if (report != null) { 49 this.reportItem = report 50 } 51 globalThis.testDuration=this.reportItem.testDuration 52 53 database.query_powersensor_info(timeStamp).then(data => { 54 data.forEach(t=>{ 55 this.tPowerSensorList.push(t) 56 }) 57 }) 58 //归一化电流 59 database.queryData(timeStamp + ".db").then(data => { 60 let normalCurrentNow = data.reduce((pre,cur)=>{ 61 return pre + Number(cur.currentNow).valueOf() 62 },0) 63 return Math.abs(normalCurrentNow /data.length/ 1.1125) 64 }).then((normalCurrentNow)=>{ 65 database.query_powerapp_info(timeStamp).then(data => { 66 data.forEach(t=>{ 67 let current = (Number(t.percent)) * normalCurrentNow /100 68 t.setCurrent(current.toFixed(5)) 69 t.setPercent(Number(t.percent).toFixed(2) + "%") 70 this.tPowerAppList.push(t) 71 }) 72 }) 73 }) 74 75 } 76 77 build() { 78 79 Column() { 80 StartTestTitleComponent({ title: "报告详情" }) 81 82 Row() { 83 Flex({ justifyContent: FlexAlign.SpaceBetween }) { 84 Column() { 85 Image(globalThis.iconMap.get(this.reportItem.packageName)) 86 .width('60vp') 87 .height('60vp') 88 .margin({ top: '10vp', left: '20vp' }) 89 }.margin({ left: '4%' }) 90 91 92 Column() { 93 Text(`SP工具`).fontSize('15fp').margin({ top: '30vp' }) 94 Text(`应用版本:v1.0.2`).fontSize('15fp').margin({ top: '10vp' }) 95 }.margin({ right: '4%' }) 96 } 97 } 98 99 Row() { 100 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { 101 Text(`开始时间:${this.reportItem.startTime}`) 102 .fontSize('13fp') 103 .fontColor($r("app.color.color_666")) 104 .margin({ top: '5vp' }) 105 Text(`测试时长:${secToTime(Number(this.reportItem.testDuration))}`) 106 .fontSize('13fp') 107 .fontColor($r("app.color.color_666")) 108 .margin({ top: '5vp' }) 109 Text(`文件路径:${this.reportItem.dbPath}/t_index_info.csv`) 110 .fontSize('13fp') 111 .fontColor($r("app.color.color_666")) 112 .margin({ top: '5vp' }) 113 }.width('100%').margin({ left: '10vp' }).height('95') 114 }.margin({ left: '4%' }) 115 116 Row() { 117 Flex() { 118 Tabs({ barPosition: BarPosition.Start, index: 0, controller: this.controller }) { 119 TabContent() { 120 Summary({ gpData: this.gpData }) 121 }.tabBar('概览') 122 123 TabContent() { 124 Column() { 125 Performance({ gpData: this.gpData }) 126 }.width('100%').height('100%') 127 }.tabBar('性能') 128 129 TabContent() { 130 Column() { 131 Load({ gpData: this.gpData }) 132 }.width('100%').height('100%') 133 }.tabBar('负载') 134 135 if (!CheckEmptyUtils.checkStrIsEmpty(this.gpData[0].currentNow)) { 136 TabContent() { 137 Column() { 138 PowerDubai({tPowerSensorList:this.tPowerSensorList, TPowerAppInfoList:this.tPowerAppList}) 139 }.width('100%').height('100%') 140 }.tabBar('功耗') 141 } 142 143 TabContent() { 144 Column() { 145 Temperature({ gpData: this.gpData }) 146 }.width('100%').height('100%') 147 }.tabBar('热') 148 }.backgroundColor("#f5f5f5") 149 .barWidth(360) 150 .scrollable(true) 151 .barHeight(60) 152 .width('100%') 153 .height('100%') 154 } 155 } 156 } 157 } 158}