From cc890f987b770e5a73f5ef12d41b25f6bb448fcd Mon Sep 17 00:00:00 2001 From: zmc <zmc_li@foxmail.com> Date: 星期四, 23 十一月 2023 16:37:45 +0800 Subject: [PATCH] 1.增加了风险模型跳转逻辑 2.修改了风险模型页面部分逻辑 --- src/utils/risk_estimate_common_function/index.js | 319 +++++++++++++++++++++++++++------------------------- 1 files changed, 167 insertions(+), 152 deletions(-) diff --git a/src/utils/risk_estimate_common_function/index.js b/src/utils/risk_estimate_common_function/index.js index bfcfb96..84295b7 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,177 @@ * @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); + // 淇濆瓨鏂扮殑寮傚父绫诲瀷 鏁版嵁瓒呬綆銆侀暱鏃堕棿鏃犳尝鍔ㄧ瓑涓ょ被寮傚父鏆備笉绾冲叆鍒嗘瀽 + else if ( item.exceptionType!='1' && item.exceptionType!='3' && exception.indexOf(item.exceptionType) == -1) { + 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); - - 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 -}, + // 鏁版嵁瓒呬綆銆侀暱鏃堕棿鏃犳尝鍔ㄧ瓑涓ょ被寮傚父鏆備笉绾冲叆鍒嗘瀽 + exceptionTypeAggregation = (exception.length / 6).toFixed(2) -/** - * 鎵惧埌瀵硅薄鏁扮粍涓睘鎬nCode涓簐alue鐨勫璞� 娣诲姞杩涙暟缁勪腑 - * @param锛� 瀵硅薄鏁扮粍 锛宮nCode绛変簬value - * @returns锛� - */ -findValue(exceptionData,value){ - if(exceptionData.length==0){ - return [] - } + let obj = {} + obj['exceptionRecurrence'] = exceptionTyprRecurRate + obj['exceptionTypeAggregation'] = exceptionTypeAggregation - let temp = [] - exceptionData.forEach((res)=>{ - if(res.mnCode == value){ - temp.push(res) + // 淇濆瓨璇ユ椂娈靛嚭鐜扮殑寮傚父 + obj['exception'] = exception + + // 涓夌被寮傚父鍑虹幇鐨勬鏁� + obj['mutationCount'] = mutationCount + obj['exceedingNearCount'] = exceedingNearCount + obj['exceedingCriticalDegree'] = exceedingCriticalDegree + + + 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 @@ -247,23 +262,23 @@ obj.region = '閲戝北鍖�' obj.monitorType = '鎵皹' obj.siteName = res.name + obj.mnCode = res.mnCode obj.beginTime = beginTime obj.endTime = endTime obj.riskValue = weight if (weight >= 0.6) { obj.riskGrage = '楂橀闄�' - obj.riskAdvice = '寤鸿瀵硅绔欑偣杩涜绾夸笅鎵ф硶妫�鏌ワ紝涓撻」鏁版嵁瀵规瘮' - + obj.riskAdvice = '1.鑻ヤ笉娑夊強瓒呮爣鎴栧湪绾跨巼銆佹湁鏁堢巼寮傚父锛屽父鎬佹暟鎹鏍稿嵆鍙紱\n2.鑻ユ秹鍙婅秴鏍囨垨鍦ㄧ嚎鐜囥�佹湁鏁堢巼绛夊紓甯革紝寤鸿閫氳繃瀹堟硶鏈嶅姟灏忕▼搴忋�佺洃娴嬬洃绠″井淇$兢绛夌嚎涓婃柟寮忔彁绀虹珯鐐规墍灞炲崟浣嶏紝鍙婃椂寮�灞曡嚜鏌ヨ嚜绾狅紱' } else if (weight < 0.6 && weight >= 0.2) { obj.riskGrage = '涓闄�' - obj.riskAdvice = '寤鸿寮�灞曞父鎬佽拷韪垎鏋�' + obj.riskAdvice = '1.寤鸿閫氳繃瀹堟硶鏈嶅姟灏忕▼搴忋�佺洃娴嬬洃绠″井淇$兢绛夌嚎涓婃柟寮忔彁绀虹珯鐐规墍灞炲崟浣嶏紝鑱氱劍褰撳墠瀛樺湪鐨勯棶棰樻垨闅愭偅锛屽強鏃跺紑灞曡嚜鏌ヨ嚜绾狅紱\n2.鑻ュ悓鏃跺瓨鍦ㄥ湪绾跨巼鎴栨湁鏁堢巼鏈堝害涓嶈揪鏍囷紝寤鸿鐢佃瘽閫氱煡璇ョ珯鐐规墍灞炲崟浣嶈繘琛屽簲鎬ョ淮鎶わ紝骞惰繘琛屼笓椤瑰鏍革紱' } else { obj.riskGrage = '浣庨闄�' - obj.riskAdvice = '寤鸿寮曞浼佷笟闀挎�佷繚鎸�' + obj.riskAdvice = '1.寤鸿鍙婃椂鎻愰啋璇ョ珯鐐规墍灞炲崟浣嶈繘琛屽簲鎬ョ淮鎶わ紱\n2.鑻ュ悓鏃跺瓨鍦ㄨ秴鏍囥�佷复鐣岃秴鏍囥�侀噺绾х獊鍙樼瓑寮傚父鏃讹紝寤鸿灏嗚绔欑偣绉讳氦鐜鎵ф硶澶ч槦寮�灞曠幇鍦烘墽娉曟鏌ワ紱\n3.鑻ユ寔缁袱鏈堝強浠ヤ笂涓洪珮椋庨櫓锛屽缓璁皢璇ョ珯鐐圭撼鍏ュ勾搴︽娊娴嬫瘮瀵规竻鍗曪紱' } table.push(obj) }) return table + } } -} \ No newline at end of file -- Gitblit v1.9.3