zmc
2023-09-05 c2f95b0b9090a2394b5b068582b932a5e57b86aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import dayjs from 'dayjs';
export default {
  /**
   * 计算日期相差几天
   * @param:
   * @createTime:开始时间,结束时间
   * @returns:
   */
  getDaysDifference(startDate, endDate) {
    return dayjs(endDate).diff(startDate, 'day') + 1;
  },
  /**
   * 从分析数据数组中计算最小和大值 ,平均值,    在线率,有效率,超标率(后三个值为0~100取值)
   * @param:分析表中的数据
   * @returns:
   */
  calBillData(arr, beginTime, endTime) {
    let min = 65536;
    let max = -1;
    let avg = 0;
    let online = 0;
    let valid = 0;
    let exceeding = 0;
 
    let sumAvg = 0;
    let sumOnline = 0;
    let sumValid = 0;
    let sumExceeding = 0;
 
    // 计算选择的时间的相差的天数
    let begin = dayjs(beginTime).format('YYYY-MM-DD');
    let end = dayjs(endTime).format('YYYY-MM-DD');
    let dayDiff = this.getDaysDifference(begin, end);
    console.log('日期间隔', dayDiff);
    let obj = {};
    // 计算最小和大值
    arr.forEach((item) => {
      if (item.min < min) {
        min = item.min;
      }
      if (item.max > max) {
        max = item.max;
      }
      // 计算平均值,在线率,有效率,超标率
      sumAvg = sumAvg + item.dayAvg;
      sumOnline = sumOnline + Number(item.dayOnline.slice(0, -1));
      sumValid = sumValid + Number(item.dayValid.slice(0, -1));
      sumExceeding = sumExceeding + Number(item.dayExceeding.slice(0, -1));
    });
    // 计算均值
    avg = sumAvg / dayDiff;
    // console.log('sumavg:',sumAvg,dayDiff);
    online = sumOnline / dayDiff;
    valid = sumValid / dayDiff;
    exceeding = sumExceeding / dayDiff;
    obj['min'] = min.toFixed(3);
    obj['max'] = max.toFixed(3);
 
    obj['avg'] = avg.toFixed(2);
    obj['online'] = online.toFixed(2);
    obj['valid'] = valid.toFixed(2);
    obj['exceeding'] = exceeding.toFixed(2);
 
    return obj;
  },
 
  /**
   * 计算异常类型聚集度 异常复现率
   * @param: 异常数据数组
   * @returns:
   */
  calRecur(exceptionArr) {
    // 典型异常复现率
    let exceptionTyprRecurRate = 0;
    // 量级突变
    let mutationCount = 0;
    // 超标临近
    let exceedingNearCount = 0;
    // 超标次数临界
    let exceedindCriticalDegree = 0;
 
    // 保存出现的不同异常类型
    let exception = [];
    // 异常类型聚集度
    let exceptionTypeAggregation = 0;
 
    exceptionArr.forEach((item) => {
      // 异常复现率
      if (item.exceptionType == 4) {
        mutationCount++;
      } else if (item.exceptionType == 5) {
        exceedingNearCount++;
      } else if (item.exceptionType == 6) {
        exceedindCriticalDegree++;
      }
 
      // 异常类型聚集度
      if (exception.length == 0) {
        exception.push(item.exceptionType);
      }
      // 保存新的异常类型
      else if (exception.indexOf(item.exceptionType) == -1) {
        exception.push(item.exceptionType);
      }
    });
 
    let sum = 0;
    // 次数减1,该异常出现2次,算复现1次。出现3次,算复现2次...
    if (mutationCount > 1) {
      sum = sum + mutationCount - 1;
    }
    if (exceedingNearCount > 1) {
      sum = sum + exceedindCriticalDegree - 1;
    }
    if (exceedindCriticalDegree > 1) {
      sum = sum + exceedindCriticalDegree - 1;
    }
    // console.log('sum:', sum);
    // console.log('exception:', exception);
    // console.log(
    //   '其他',
    //   mutationCount,
    //   exceedindCriticalDegree,
    //   exceedindCriticalDegree
    // );
    switch (sum) {
      case 0:
        exceptionTyprRecurRate = sum / 3;
        break;
      case 1:
        exceptionTyprRecurRate = sum / 3;
        break;
      case 2:
      case sum >= 3:
        exceptionTyprRecurRate = 1;
        break;
      default:
        return 'error';
    }
 
    exceptionTypeAggregation = exception.length / 8;
 
    let obj = {};
    obj['exceptionRecurrence'] = exceptionTyprRecurRate;
    obj['exceptionTypeAggregation'] = exceptionTypeAggregation;
 
    return obj;
  }
};