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;
|
}
|
};
|