From c2f95b0b9090a2394b5b068582b932a5e57b86aa Mon Sep 17 00:00:00 2001
From: zmc <zmc_li@foxmail.com>
Date: 星期二, 05 九月 2023 18:19:37 +0800
Subject: [PATCH] 雷达图 新增综合风险排名 数据接入配置

---
 src/utils/risk_estimate_common_function/index.js |  149 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 149 insertions(+), 0 deletions(-)

diff --git a/src/utils/risk_estimate_common_function/index.js b/src/utils/risk_estimate_common_function/index.js
new file mode 100644
index 0000000..50cae19
--- /dev/null
+++ b/src/utils/risk_estimate_common_function/index.js
@@ -0,0 +1,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;
+  }
+};

--
Gitblit v1.9.3