From 0ee16e9f5dd31c6c98df1a5fdcf081c8eb7f80df Mon Sep 17 00:00:00 2001
From: zmc <zmc_li@foxmail.com>
Date: 星期二, 14 十一月 2023 13:15:55 +0800
Subject: [PATCH] 修改了获取风险值的请求接口

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

diff --git a/src/utils/risk_estimate_common_function/index.js b/src/utils/risk_estimate_common_function/index.js
index bfcfb96..a6430d5 100644
--- a/src/utils/risk_estimate_common_function/index.js
+++ b/src/utils/risk_estimate_common_function/index.js
@@ -1,4 +1,4 @@
-import dayjs from 'dayjs';
+import dayjs from 'dayjs'
 // import exceptionApi from '../../api/exceptionApi';
 export default {
   /**
@@ -8,7 +8,7 @@
    * @returns锛�
    */
   getDaysDifference(startDate, endDate) {
-    return dayjs(endDate).diff(startDate, 'day') + 1;
+    return dayjs(endDate).diff(startDate, 'day') + 1
   },
 
   /**
@@ -17,55 +17,52 @@
    * @returns锛�
    */
   calBillData(arr, beginTime, endTime) {
-    let min = 65536;
-    let max = -1;
-    let avg = 0;
-    let online = 0;
-    let valid = 0;
-    let exceeding = 0;
+    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 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);
-    let obj = {};
+    let begin = dayjs(beginTime).format('YYYY-MM-DD')
+    let end = dayjs(endTime).format('YYYY-MM-DD')
+    let dayDiff = this.getDaysDifference(begin, end)
+    let obj = {}
     // 璁$畻鏈�灏忓拰澶у��
     arr.forEach((item) => {
       if (item.min < min) {
-        min = item.min;
+        min = item.min
       }
       if (item.max > max) {
-        max = item.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));
-    });
+      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;
-    online = sumOnline / dayDiff;
-    valid = sumValid / dayDiff;
-    exceeding = sumExceeding / dayDiff;
-    obj['min'] = min.toFixed(3);
-    obj['max'] = max.toFixed(3);
+    avg = 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);
+    obj['avg'] = avg.toFixed(2)
+    obj['online'] = online.toFixed(2)
+    obj['valid'] = valid.toFixed(2)
+    obj['exceeding'] = exceeding.toFixed(2)
 
-    return obj;
+    return obj
   },
-
-
-
 
   /**
    * 璁$畻寮傚父绫诲瀷鑱氶泦搴︼細璇ユ椂娈靛嚭鐜扮殑寮傚父绫诲瀷鏁伴噺闄�8
@@ -74,159 +71,165 @@
    * @returns锛�
    */
   calRecur(exceptionArr) {
-    if(exceptionArr.length == 0){
-      let obj = {};
-      obj['exceptionRecurrence'] = 0;
-      obj['exceptionTypeAggregation'] = 0;
+    if (exceptionArr.length == 0) {
+      let obj = {}
+      obj['exceptionRecurrence'] = 0
+      obj['exceptionTypeAggregation'] = 0
 
-      return obj;
+      return obj
     }
-    // 鍏稿瀷寮傚父澶嶇幇鐜�
-    let exceptionTyprRecurRate = 0;
+
     // 閲忕骇绐佸彉
-    let mutationCount = 0;
+    let mutationCount = 0
     // 瓒呮爣涓磋繎
-    let exceedingNearCount = 0;
+    let exceedingNearCount = 0
     // 瓒呮爣娆℃暟涓寸晫
-    let exceedingCriticalDegree = 0;
+    let exceedingCriticalDegree = 0
 
     // 淇濆瓨鍑虹幇鐨勪笉鍚屽紓甯哥被鍨�
-    let exception = [];
+    let exception = []
     // 寮傚父绫诲瀷鑱氶泦搴�
-    let exceptionTypeAggregation = 0;
-
+    let exceptionTypeAggregation = 0
+    // 鍏稿瀷寮傚父澶嶇幇鐜�
+    let exceptionTyprRecurRate = 0
+    // 璁板綍鎸囧畾3绉嶅紓甯稿嚭鐜扮殑娆℃暟鍜屼笉鍚岀殑寮傚父绉嶇被
     exceptionArr.forEach((item) => {
-      // 寮傚父澶嶇幇鐜�
+      // 閲忕骇绐佸彉寮傚父
       if (item.exceptionType == 4) {
-        mutationCount++;
+        mutationCount++
+        // 涓磋繎瓒呮爣寮傚父
       } else if (item.exceptionType == 5) {
-        exceedingNearCount++;
+        exceedingNearCount++
+        // 鍗曟棩瓒呮爣娆℃暟涓寸晫寮傚父
       } else if (item.exceptionType == 6) {
-        exceedingCriticalDegree++;
+        exceedingCriticalDegree++
       }
 
       // 寮傚父绫诲瀷鑱氶泦搴�
       if (exception.length == 0) {
-        exception.push(item.exceptionType);
+        exception.push(item.exceptionType)
       }
       // 淇濆瓨鏂扮殑寮傚父绫诲瀷
       else if (exception.indexOf(item.exceptionType) == -1) {
-        exception.push(item.exceptionType);
+        exception.push(item.exceptionType)
       }
-    });
+    })
 
-    let sum = 0;
+    let sum = 0
     // 娆℃暟鍑�1锛岃寮傚父鍑虹幇2娆★紝绠楀鐜�1娆°�傚嚭鐜�3娆★紝绠楀鐜�2娆�...
     if (mutationCount > 1) {
-      sum = sum + mutationCount - 1;
+      sum = sum + mutationCount - 1
     }
     if (exceedingNearCount > 1) {
-      sum = sum + exceedingNearCount - 1;
+      sum = sum + exceedingNearCount - 1
     }
     if (exceedingCriticalDegree > 1) {
-      sum = sum + exceedingCriticalDegree - 1;
+      sum = sum + exceedingCriticalDegree - 1
     }
 
     switch (true) {
-      case (sum == 0 || sum == 1) :
-        exceptionTyprRecurRate = (sum / 3).toFixed(2);
-        break;
-      case (sum == 2|| sum >=3) :
-        exceptionTyprRecurRate = 1;
-        break;
+      case sum == 0 || sum == 1:
+        exceptionTyprRecurRate = (sum / 3).toFixed(2)
+        break
+      case sum == 2 || sum >= 3:
+        exceptionTyprRecurRate = 1
+        break
       default:
-        return 'error';
+        return 'error'
     }
 
-    exceptionTypeAggregation = (exception.length / 8).toFixed(2);
+    exceptionTypeAggregation = (exception.length / 8).toFixed(2)
 
-    let obj = {};
-    obj['exceptionRecurrence'] = exceptionTyprRecurRate;
-    obj['exceptionTypeAggregation'] = exceptionTypeAggregation;
+    let obj = {}
+    obj['exceptionRecurrence'] = exceptionTyprRecurRate
+    obj['exceptionTypeAggregation'] = exceptionTypeAggregation
 
-    return obj;
-},
-// 鍙傛暟锛氬璞℃暟缁�(璇ュ璞′腑鐨勫睘鎬т笉鑳芥槸寮曠敤绫诲瀷锛屽惁鍒欐嫹璐濈殑鍊艰繕鏄細鐩镐簰褰卞搷)
-    // 鍔熻兘锛氭嫹璐濊瀵硅薄鏁扮粍銆�
-shallowCopyList(val) {
-  if(val == 'arr'){
-    let tempList = [];
-    return tempList;
-  }else if(val == 'obj'){
-    let tempList = {};
-    return tempList;
-  }
-    
-},
-getRate(obj){
-  let a = {}
-  a.online = obj['dayOnline']
-  a.valid = obj['dayValid']
-  a.exceeding = obj['dayExceeding']
-  return a
-},
-
-/**
- * 鎵惧埌瀵硅薄鏁扮粍涓睘鎬nCode涓簐alue鐨勫璞� 娣诲姞杩涙暟缁勪腑
- * @param锛� 瀵硅薄鏁扮粍 锛宮nCode绛変簬value
- * @returns锛�
- */
-findValue(exceptionData,value){
-  if(exceptionData.length==0){
-    return []
-  }
-
-  let temp = []
-  exceptionData.forEach((res)=>{
-    if(res.mnCode == value){
-      temp.push(res)
+    return obj
+  },
+  // 鍙傛暟锛氬璞℃暟缁�(璇ュ璞′腑鐨勫睘鎬т笉鑳芥槸寮曠敤绫诲瀷锛屽惁鍒欐嫹璐濈殑鍊艰繕鏄細鐩镐簰褰卞搷)
+  // 鍔熻兘锛氭嫹璐濊瀵硅薄鏁扮粍銆�
+  shallowCopyList(val) {
+    if (val == 'arr') {
+      let tempList = []
+      return tempList
+    } else if (val == 'obj') {
+      let tempList = {}
+      return tempList
     }
-  })
-  return temp
-},
+  },
+  getRate(obj) {
+    let a = {}
+    a.online = obj['dayOnline']
+    a.valid = obj['dayValid']
+    a.exceeding = obj['dayExceeding']
+    return a
+  },
 
-/**
- * 璁$畻椋庨櫓鍊�
- * @param锛� 鏁扮粍銆備緷娆℃槸鍦ㄧ嚎鐜囷紝鏈夋晥鐜囷紝瓒呮爣鐜囷紝寮傚父绫诲瀷鑱氶泦搴︼紝寮傚父澶嶇幇鐜�
- * @returns锛�
- */
-calRiskValue(arr){
-  // 鐢�100鍑� 鏄洜涓鸿灞炴�ч渶瑕佽绠楃殑鏄闄╁�硷紝搴斿綋鏄绾跨巼锛屾棤鏁堢巼
-  // 涔樹互0.01鏄洜涓哄幓闄ょ櫨鍒嗗彿鍚庨渶瑕佸啀缂╁皬100鍊�
-  let weight = (
-    (100 - parseFloat(arr[0].slice(0, -1)))*0.01 * 0.1 +
-    (100 - parseFloat(arr[1].slice(0, -1)))*0.01 * 0.2 +
-    parseFloat(arr[2].slice(0, -1))*0.01 * 0.2 +
-    arr[3] * 0.2 +
-    arr[4] * 0.3
-  ).toFixed(2)
-  
-  return weight
-},
+  /**
+   * 鎵惧埌瀵硅薄鏁扮粍涓睘鎬nCode涓簐alue鐨勫璞� 娣诲姞杩涙暟缁勪腑
+   * @param锛� 瀵硅薄鏁扮粍 锛宮nCode绛変簬value
+   * @returns锛�
+   */
+  findValue(exceptionData, value) {
+    if (exceptionData.length == 0) {
+      return []
+    }
 
-/**
- * 瀵瑰垎鏋愬�煎拰寮傚父鍊艰绠楅闄╁��
- * @param锛� 鍒嗘瀽鏁版嵁锛屽紓甯告暟鎹紝寮�濮嬫椂闂达紝缁撴潫鏃堕棿
- * @returns锛氳〃鏍兼暟鎹�
- */
-merge(anaData,exceptionData,beginTime,endTime){
+    let temp = []
+    exceptionData.forEach((res) => {
+      if (res.mnCode == value) {
+        temp.push(res)
+      }
+    })
+    return temp
+  },
 
-  if (anaData.length == 0){
-    return []
-  } 
-  const table = []
-  let i = 0
-  anaData.forEach((res) =>{
-      let siteName = res.name
+  /**
+   * 璁$畻椋庨櫓鍊�
+   * @param锛� 鏁扮粍銆備緷娆℃槸鍦ㄧ嚎鐜囷紝鏈夋晥鐜囷紝瓒呮爣鐜囷紝寮傚父绫诲瀷鑱氶泦搴︼紝寮傚父澶嶇幇鐜�
+   * @returns锛�
+   */
+  calRiskValue(arr) {
+    // 鐢�100鍑� 鏄洜涓鸿灞炴�ч渶瑕佽绠楃殑鏄闄╁�硷紝搴斿綋鏄绾跨巼锛屾棤鏁堢巼
+    // 涔樹互0.01鏄洜涓哄幓闄ょ櫨鍒嗗彿鍚庨渶瑕佸啀缂╁皬100鍊�
+    /* arr[0]:鍦ㄧ嚎鐜� 90%
+     arr[1]:鏈夋晥鐜� 100%
+     arr[2]:瓒呮爣鐜� 2%
+     arr[3]:鍏稿瀷寮傚父澶嶇幇椋庨櫓 0.2
+     arr[4]:寮傚父绫诲瀷鑱氶泦椋庨櫓  0.5
+  */
+    let weight = (
+      (100 - parseFloat(arr[0].slice(0, -1))) * 0.01 * 0.1 +
+      (100 - parseFloat(arr[1].slice(0, -1))) * 0.01 * 0.2 +
+      parseFloat(arr[2].slice(0, -1)) * 0.01 * 0.2 +
+      arr[3] * 0.2 +
+      arr[4] * 0.3
+    ).toFixed(2)
+
+    return weight
+  },
+
+  /**
+   * 瀵瑰垎鏋愬�煎拰寮傚父鍊艰绠楅闄╁��
+   * @param锛� 鍒嗘瀽鏁版嵁锛屽紓甯告暟鎹紝寮�濮嬫椂闂达紝缁撴潫鏃堕棿
+   * @returns锛氳〃鏍兼暟鎹�
+   */
+  merge(anaData, exceptionData, beginTime, endTime) {
+    if (anaData.length == 0) {
+      return []
+    }
+    const table = []
+    let i = 0
+    anaData.forEach((res) => {
       // 浠庡垎鏋愭暟鎹腑寰楀埌璁惧缂栧彿
       let mnCode = res.mnCode
       // 鎵惧埌寮傚父鏁版嵁涓璵nCode绛変簬value鐨勫璞�
-      let d = this.findValue(exceptionData,mnCode)
+      let d = this.findValue(exceptionData, mnCode)
       // let temp = [...res,...d]
-      
+
       // 璁$畻鍦ㄧ嚎锛屾湁鏁堢巼锛岃秴鏍囩巼
       let r1 = this.getRate(res, beginTime, endTime)
-      
+
       // 璁$畻澶嶇幇鐜�
       let r2 = this.calRecur(d)
       i = i + 1
@@ -253,7 +256,6 @@
       if (weight >= 0.6) {
         obj.riskGrage = '楂橀闄�'
         obj.riskAdvice = '寤鸿瀵硅绔欑偣杩涜绾夸笅鎵ф硶妫�鏌ワ紝涓撻」鏁版嵁瀵规瘮'
-       
       } else if (weight < 0.6 && weight >= 0.2) {
         obj.riskGrage = '涓闄�'
         obj.riskAdvice = '寤鸿寮�灞曞父鎬佽拷韪垎鏋�'
@@ -265,5 +267,5 @@
     })
 
     return table
+  }
 }
-}
\ No newline at end of file

--
Gitblit v1.9.3