/* * 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. */ import { BaseElement, element } from '../../../../../base-ui/BaseElement.js'; import { SpHiSysEventChart } from '../../../chart/SpHiSysEventChart.js'; import { LitTable } from '../../../../../base-ui/table/lit-table.js'; import { queryAnomalyDetailedData } from '../../../../database/SqlLite.js'; import { SelectionParam } from '../../../../bean/BoxSelection.js'; import { EnergyAnomalyStruct } from '../../../../database/ui-worker/ProcedureWorkerEnergyAnomaly.js'; import { resizeObserver } from '../SheetUtils.js'; @element('tabpane-anomaly-details') export class TabPaneEnergyAnomaly extends BaseElement { private tblAnomaly: LitTable | null | undefined; private static KEY_INDEX: number = 2; private static VALUE_INDEX: number = 3; set data(selectionAnomaly: SelectionParam) { let div: HTMLElement | null | undefined = this?.shadowRoot?.querySelector('#anomaly-details'); let htmlText = ''; if (selectionAnomaly) { this.queryAnomalyTableData(selectionAnomaly.leftNs, selectionAnomaly.rightNs).then((bean) => { let filterAppMap = new Map(); for (let index = 0; index < bean.length; index++) { let findAppNameIndex = -1; // @ts-ignore let values = Object.values(bean[index]); if (values[TabPaneEnergyAnomaly.VALUE_INDEX]) { let apps = values[TabPaneEnergyAnomaly.VALUE_INDEX].split(','); for (let appIndex = 0; appIndex < apps.length; appIndex++) { if (apps.indexOf(SpHiSysEventChart.app_name) != -1) { findAppNameIndex = apps.indexOf(SpHiSysEventChart.app_name); filterAppMap.set(values[0] + values[1], findAppNameIndex); break; } } if (values[TabPaneEnergyAnomaly.KEY_INDEX] == 'APPNAME') { //ts+eventName : appNameIndex filterAppMap.set(values[0] + values[1], findAppNameIndex); } } } let set = new Set(); for (let index = 0; index < bean.length; index++) { // @ts-ignore let values = Object.values(bean[index]); let findAppNameIndex = -1; if (filterAppMap.get(values[0] + values[1]) == -1) { continue; } else { findAppNameIndex = filterAppMap.get(values[0] + values[1]); } if (!set.has(values[0])) { set.add(values[0]); htmlText += '
' + values[1] + ' | ||||
" + values[TabPaneEnergyAnomaly.KEY_INDEX] + " | " + (findAppNameIndex >= 0 ? appValues.length > 1 ? appValues[findAppNameIndex] : values[TabPaneEnergyAnomaly.VALUE_INDEX] : values[TabPaneEnergyAnomaly.VALUE_INDEX]) + TabPaneEnergyAnomaly.getUnit(values[TabPaneEnergyAnomaly.KEY_INDEX]) + " | "; } if (index + 1 < bean.length) { // @ts-ignore let nextValues = Object.values(bean[index + 1]); let appValues = nextValues[TabPaneEnergyAnomaly.VALUE_INDEX].split(','); if (set.has(nextValues[0])) { htmlText += " | " + nextValues[TabPaneEnergyAnomaly.KEY_INDEX] + " | " + (findAppNameIndex >= 0 ? appValues.length > 1 ? appValues[findAppNameIndex] : nextValues[TabPaneEnergyAnomaly.VALUE_INDEX] : nextValues[TabPaneEnergyAnomaly.VALUE_INDEX]) + TabPaneEnergyAnomaly.getUnit(nextValues[TabPaneEnergyAnomaly.KEY_INDEX]) + ' |