• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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 {
17  AVERAGE_LINE_FOR_REPAIRE_RULE_COEFFICIENT,
18  NPAI_REPAIRE_WORKLOADA_COEFFICIEN,
19  TEST_DEBUG_WORKLOAD_COEFFICIENT
20} from '../../utils/consts/WorkloadRelatedConst';
21import type { FloderScanResultInfo } from './FloderScanResultInfo';
22import type { ProblemNumbersInfo } from './ProblemNumbersInfo';
23
24export class WorkLoadInfo {
25  scanFilePathList: string[] = [];
26  totalArkTSCodeLines = 0;
27  totalCAndCPPCodeLines = 0;
28  totalNapiCodeLines = 0;
29  totalJsCodeLines = 0;
30  totalTsCodeLines = 0;
31  totalJsonCodeLines = 0;
32  totalXmlCodeLines = 0;
33
34  addFloderResult(result: FloderScanResultInfo): void {
35    this.scanFilePathList.push(result.normalizedPath);
36    this.totalArkTSCodeLines += result.arkTSCodeLines;
37    this.totalCAndCPPCodeLines += result.cAndCPPCodeLines;
38    this.totalNapiCodeLines += result.napiCodeLines;
39    this.totalJsCodeLines += result.jsCodeLines;
40    this.totalTsCodeLines += result.tsCodeLines;
41    this.totalJsonCodeLines += result.jsonCodeLines;
42    this.totalXmlCodeLines += result.xmlCodeLines;
43  }
44
45  calculateFixRate(problemNumbers: ProblemNumbersInfo): string {
46    const totalLines = this.totalArkTSCodeLines + this.totalCAndCPPCodeLines;
47    if (totalLines <= 0) {
48      return '0.00%';
49    }
50
51    const problemCount = problemNumbers.needToManualFixproblemNumbers;
52    const ratio =
53      (problemCount * AVERAGE_LINE_FOR_REPAIRE_RULE_COEFFICIENT * TEST_DEBUG_WORKLOAD_COEFFICIENT +
54        this.totalNapiCodeLines * NPAI_REPAIRE_WORKLOADA_COEFFICIEN) /
55      totalLines;
56
57    return `${(ratio * 100).toFixed(2)}%`;
58  }
59}
60