From 03094b048acfbb444bb298273d698189d18a1a0f Mon Sep 17 00:00:00 2001 From: zmc <zmc_li@foxmail.com> Date: 星期四, 23 十一月 2023 17:40:55 +0800 Subject: [PATCH] 1. 修改了风险模型的统计信息的函数 --- src/utils/risk_estimate_common_function/index.js | 309 +++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 224 insertions(+), 85 deletions(-) diff --git a/src/utils/risk_estimate_common_function/index.js b/src/utils/risk_estimate_common_function/index.js index 50cae19..9f6aaa3 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 dayjs from 'dayjs' +// import exceptionApi from '../../api/exceptionApi'; export default { /** * 璁$畻鏃ユ湡鐩稿樊鍑犲ぉ @@ -7,143 +8,281 @@ * @returns锛� */ getDaysDifference(startDate, endDate) { - return dayjs(endDate).diff(startDate, 'day') + 1; + 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 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); - console.log('鏃ユ湡闂撮殧', dayDiff); - 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)) + + sumOnline = sumOnline + Number(item.dayOnline) + sumValid = sumValid + Number(item.dayValid) + sumExceeding = sumExceeding + Number(item.dayExceeding) + }) // 璁$畻鍧囧�� - 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); + 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 + * 寮傚父澶嶇幇鐜�: 閲忕骇绐佸彉,瓒呮爣涓磋繎鍜岃秴鏍囨鏁颁复鐣屽湪璇ユ椂娈靛嚭鐜扮殑绱澶嶇幇姝ゆ闄�3锛堟瘮濡傞噺绾х獊鍙樺嚭鐜�3娆★紝绠椾綔澶嶇幇2娆★級 * @param锛� 寮傚父鏁版嵁鏁扮粍 * @returns锛� */ calRecur(exceptionArr) { - // 鍏稿瀷寮傚父澶嶇幇鐜� - let exceptionTyprRecurRate = 0; + if (exceptionArr.length == 0) { + let obj = {} + obj['exceptionRecurrence'] = 0 + obj['exceptionTypeAggregation'] = 0 + + return obj + } + // 閲忕骇绐佸彉 - let mutationCount = 0; + let mutationCount = 0 // 瓒呮爣涓磋繎 - let exceedingNearCount = 0; + let exceedingNearCount = 0 // 瓒呮爣娆℃暟涓寸晫 - let exceedindCriticalDegree = 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) { - exceedindCriticalDegree++; + 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 + exceedindCriticalDegree - 1; + sum = sum + exceedingNearCount - 1 } - if (exceedindCriticalDegree > 1) { - sum = sum + exceedindCriticalDegree - 1; + if (exceedingCriticalDegree > 1) { + sum = sum + exceedingCriticalDegree - 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; + + switch (true) { + 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 / 6).toFixed(2) + + let obj = {} + obj['exceptionRecurrence'] = exceptionTyprRecurRate + obj['exceptionTypeAggregation'] = exceptionTypeAggregation + + // 淇濆瓨璇ユ椂娈靛嚭鐜扮殑寮傚父 + 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 + } + }, + 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 [] } - exceptionTypeAggregation = exception.length / 8; + let temp = [] + exceptionData.forEach((res) => { + if (res.mnCode == value) { + temp.push(res) + } + }) + return temp + }, - let obj = {}; - obj['exceptionRecurrence'] = exceptionTyprRecurRate; - obj['exceptionTypeAggregation'] = exceptionTypeAggregation; + /** + * 璁$畻椋庨櫓鍊� + * @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 obj; + 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.mnCode = res.mnCode + obj.beginTime = beginTime + obj.endTime = endTime + obj.riskValue = weight + if (weight >= 0.6) { + obj.riskGrage = '楂橀闄�' + obj.riskAdvice = '1.鑻ヤ笉娑夊強瓒呮爣鎴栧湪绾跨巼銆佹湁鏁堢巼寮傚父锛屽父鎬佹暟鎹鏍稿嵆鍙紱\n2.鑻ユ秹鍙婅秴鏍囨垨鍦ㄧ嚎鐜囥�佹湁鏁堢巼绛夊紓甯革紝寤鸿閫氳繃瀹堟硶鏈嶅姟灏忕▼搴忋�佺洃娴嬬洃绠″井淇$兢绛夌嚎涓婃柟寮忔彁绀虹珯鐐规墍灞炲崟浣嶏紝鍙婃椂寮�灞曡嚜鏌ヨ嚜绾狅紱' + } else if (weight < 0.6 && weight >= 0.2) { + obj.riskGrage = '涓闄�' + obj.riskAdvice = '1.寤鸿閫氳繃瀹堟硶鏈嶅姟灏忕▼搴忋�佺洃娴嬬洃绠″井淇$兢绛夌嚎涓婃柟寮忔彁绀虹珯鐐规墍灞炲崟浣嶏紝鑱氱劍褰撳墠瀛樺湪鐨勯棶棰樻垨闅愭偅锛屽強鏃跺紑灞曡嚜鏌ヨ嚜绾狅紱\n2.鑻ュ悓鏃跺瓨鍦ㄥ湪绾跨巼鎴栨湁鏁堢巼鏈堝害涓嶈揪鏍囷紝寤鸿鐢佃瘽閫氱煡璇ョ珯鐐规墍灞炲崟浣嶈繘琛屽簲鎬ョ淮鎶わ紝骞惰繘琛屼笓椤瑰鏍革紱' + } else { + obj.riskGrage = '浣庨闄�' + obj.riskAdvice = '1.寤鸿鍙婃椂鎻愰啋璇ョ珯鐐规墍灞炲崟浣嶈繘琛屽簲鎬ョ淮鎶わ紱\n2.鑻ュ悓鏃跺瓨鍦ㄨ秴鏍囥�佷复鐣岃秴鏍囥�侀噺绾х獊鍙樼瓑寮傚父鏃讹紝寤鸿灏嗚绔欑偣绉讳氦鐜鎵ф硶澶ч槦寮�灞曠幇鍦烘墽娉曟鏌ワ紱\n3.鑻ユ寔缁袱鏈堝強浠ヤ笂涓洪珮椋庨櫓锛屽缓璁皢璇ョ珯鐐圭撼鍏ュ勾搴︽娊娴嬫瘮瀵规竻鍗曪紱' + } + table.push(obj) + }) + + return table } -}; +} -- Gitblit v1.9.3