From eeef5d4039d2b3fee6854ddc2789aa23232b2cfb Mon Sep 17 00:00:00 2001 From: zmc <zmc_li@foxmail.com> Date: 星期三, 27 九月 2023 17:24:10 +0800 Subject: [PATCH] 登陆页换了背景,加了风险排名 --- src/utils/risk_estimate_common_function/index.js | 148 +++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 136 insertions(+), 12 deletions(-) diff --git a/src/utils/risk_estimate_common_function/index.js b/src/utils/risk_estimate_common_function/index.js index 50cae19..4c7092c 100644 --- a/src/utils/risk_estimate_common_function/index.js +++ b/src/utils/risk_estimate_common_function/index.js @@ -1,4 +1,5 @@ import dayjs from 'dayjs'; +// import exceptionApi from '../../api/exceptionApi'; export default { /** * 璁$畻鏃ユ湡鐩稿樊鍑犲ぉ @@ -9,6 +10,7 @@ getDaysDifference(startDate, endDate) { return dayjs(endDate).diff(startDate, 'day') + 1; }, + /** * 浠庡垎鏋愭暟鎹暟缁勪腑璁$畻鏈�灏忓拰澶у�� ,骞冲潎鍊硷紝 鍦ㄧ嚎鐜囷紝鏈夋晥鐜囷紝瓒呮爣鐜囷紙鍚庝笁涓�间负0~100鍙栧�硷級 * @param锛氬垎鏋愯〃涓殑鏁版嵁 @@ -31,7 +33,6 @@ 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) => { @@ -49,7 +50,6 @@ }); // 璁$畻鍧囧�� avg = sumAvg / dayDiff; - // console.log('sumavg:',sumAvg,dayDiff); online = sumOnline / dayDiff; valid = sumValid / dayDiff; exceeding = sumExceeding / dayDiff; @@ -64,12 +64,23 @@ return obj; }, + + + /** - * 璁$畻寮傚父绫诲瀷鑱氶泦搴� 寮傚父澶嶇幇鐜� + * 璁$畻寮傚父绫诲瀷鑱氶泦搴︼細璇ユ椂娈靛嚭鐜扮殑寮傚父绫诲瀷鏁伴噺闄�8 + * 寮傚父澶嶇幇鐜�: 閲忕骇绐佸彉,瓒呮爣涓磋繎鍜岃秴鏍囨鏁颁复鐣屽湪璇ユ椂娈靛嚭鐜扮殑绱澶嶇幇姝ゆ闄�3锛堟瘮濡傞噺绾х獊鍙樺嚭鐜�3娆★紝绠椾綔澶嶇幇2娆★級 * @param锛� 寮傚父鏁版嵁鏁扮粍 * @returns锛� */ calRecur(exceptionArr) { + if(exceptionArr.length == 0){ + let obj = {}; + obj['exceptionRecurrence'] = 0; + obj['exceptionTypeAggregation'] = 0; + + return obj; + } // 鍏稿瀷寮傚父澶嶇幇鐜� let exceptionTyprRecurRate = 0; // 閲忕骇绐佸彉 @@ -115,14 +126,7 @@ 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; @@ -145,5 +149,125 @@ 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 temp +}, + +/** + * 璁$畻椋庨櫓鍊� + * @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 +}, + +/** + * 瀵瑰垎鏋愬�煎拰寮傚父鍊艰绠楅闄╁�� + * @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 temp = [...res,...d] + + // 璁$畻鍦ㄧ嚎锛屾湁鏁堢巼锛岃秴鏍囩巼 + let r1 = this.getRate(res, beginTime, endTime) + + // 璁$畻澶嶇幇鐜� + let r2 = this.calRecur(d) + i = i + 1 + // 鏁扮粍鐨勬嫹璐� 闃叉鍦板潃寮曠敤 + let temp = this.shallowCopyList('arr') + temp.push(r1['online']) + temp.push(r1['valid']) + temp.push(r1['exceeding']) + temp.push(r2['exceptionRecurrence']) + temp.push(r2['exceptionTypeAggregation']) + // 璁$畻椋庨櫓鍊� + let weight = this.calRiskValue(temp) + + // 瀵硅薄鐨勬嫹璐� 闃叉鍦板潃寮曠敤 + let obj = this.shallowCopyList('obj') + + // 鏋勬垚琛ㄦ牸鐨勪竴琛� + obj.region = '閲戝北鍖�' + obj.monitorType = '鎵皹' + obj.siteName = res.name + obj.beginTime = beginTime + obj.endTime = endTime + obj.riskValue = weight + if (weight >= 0.6) { + obj.riskGrage = '楂橀闄�' + obj.riskAdvice = '寤鸿瀵硅绔欑偣杩涜绾夸笅鎵ф硶妫�鏌ワ紝涓撻」鏁版嵁瀵规瘮' + + } else if (weight < 0.6 && weight >= 0.2) { + obj.riskGrage = '涓闄�' + obj.riskAdvice = '寤鸿寮�灞曞父鎬佽拷韪垎鏋�' + } else { + obj.riskGrage = '浣庨闄�' + obj.riskAdvice = '寤鸿寮曞浼佷笟闀挎�佷繚鎸�' + } + table.push(obj) + }) + + return table +} +} \ No newline at end of file -- Gitblit v1.9.3