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/exception_common_function/index.js | 138 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 138 insertions(+), 0 deletions(-) diff --git a/src/utils/exception_common_function/index.js b/src/utils/exception_common_function/index.js new file mode 100644 index 0000000..0311b9b --- /dev/null +++ b/src/utils/exception_common_function/index.js @@ -0,0 +1,138 @@ +import dayjs from 'dayjs' +export default { + /** + * description锛氳繑鍥炴椂闂存暟缁勶紝闂撮殧15鍒嗛挓銆� + * @param锛� 寮傚父鐨勫紑濮�,寮傚父缁撴潫鏃堕棿 + * @createTime:2023-08-17 + * @returns锛氭瘮濡�12:00:00-13:00:00 鎵�浠ヨ繑鍥炵殑鏁扮粍鍏冪礌鏄� 12:00:00 ,12:15:00,12:30:00,12:45:00锛�13:00:00 + */ + descFiftyTime(begin, end) { + let time = []; + if (begin == end) { + time.push(begin); + return time; + } + time.push(begin); + let temp = dayjs(begin).add(15, 'minute').format('YYYY-MM-DD HH:mm:ss'); + while (temp != end) { + time.push(temp); + temp = dayjs(temp).add(15, 'minute').format('YYYY-MM-DD HH:mm:ss'); + } + // 鍔犱笂寮傚父鐨勭粨鏉熸椂闂� + time.push(temp); + return time; + }, + + /** + * description锛氳繑鍥炲紑濮嬫椂闂寸殑鍓�45鍒嗛挓鐨勬椂闂寸偣锛岀粨鏉熸椂闂村悗45鍒嗛挓鐨勬椂闂寸偣 + * @param锛� 寮傚父鐨勫紑濮嬫椂闂达紝寮傚父鐨勭粨鏉熸椂闂淬�� + * @returns锛氭暟缁勩�倀ime[0],time[1],time[2],time[3]鍒嗗埆浠h〃寮傚父鍖洪棿鍓�45鍒嗛挓鐨勬椂闂寸偣锛屽墠15鍒嗛挓鐨勬椂闂寸偣,鍚�15鍒嗛挓鐨勬椂闂寸偣锛屽悗45鍒嗛挓鐨勬椂闂寸偣 + */ + before45AndAfter45(begin, end) { + let time = []; + // 鍓嶄竴娈电殑寮�濮嬫椂闂� + const before45MinBegin = dayjs(begin) + .subtract(45, 'minute') + .format('YYYY-MM-DD HH:mm:ss'); + // 鍓嶄竴娈电殑缁撴潫鏃堕棿 + const before15MinBegin = dayjs(begin) + .subtract(15, 'minute') + .format('YYYY-MM-DD HH:mm:ss'); + + // 鍚庝竴娈电殑寮�濮嬫椂闂� + const after15MinBegin = dayjs(end) + .add(15, 'minute') + .format('YYYY-MM-DD HH:mm:ss'); + // 寰�鍚�40鍒嗛挓 + const after45MinEnd = dayjs(end) + .add(45, 'minute') + .format('YYYY-MM-DD HH:mm:ss'); + time.push(before45MinBegin); + time.push(before15MinBegin); + time.push(after15MinBegin); + time.push(after45MinEnd); + return time; + }, + + /** + * description锛氳繑鍥炴煇绔欑偣鍦ㄨ鏃舵鍘嗗彶鏁版嵁鐨刧et璇锋眰鍙傛暟 + * @param锛� 绔欑偣鍚嶇О锛� 寮�濮嬫椂闂达紝 缁撴潫鏃堕棿 + * @returns锛氬璞� + */ + requestGetParms(name, begin, end) { + return { + siteName: name, + beginTime: begin, + endTime: end + }; + }, + /** + * description锛氱浉宸灏戜釜15鍒嗛挓 璁$畻涓寘鎷紑濮嬫椂闂达紝缁撴潫鏃堕棿銆� + * @param锛� 寮傚父寮�濮嬫椂闂达紝寮傚父缁撴潫鏃堕棿 + * @returns锛氭暣鏁� + */ + diffFiftyMinutesNum(beginNormal, endNormal) { + // 灏嗗紑濮嬫椂闂村拰缁撴潫鏃堕棿杞崲涓篸ayjs瀵硅薄 + const start = dayjs(beginNormal).subtract(15, 'minute'); + const end = dayjs(endNormal); + + // 璁$畻缁撴潫鏃堕棿鍑忓幓寮�濮嬫椂闂翠腑闂寸浉宸灏戜釜鍗佸垎閽� + const diffInMinutes = end.diff(start, 'minute'); + const diffInTenMinutes = Math.floor(diffInMinutes / 15); + return diffInTenMinutes; + }, + /** + * description锛氬垽鏂璬ata涓槸鍚︽湁璇ユ棩鏈熸椂闂达紝瀛樺湪杩斿洖璇ユ椂闂村搴旂殑娴撳害鍊硷紝鍚﹀垯杩斿洖-1 + * @param锛� 鍔犱笂鍓嶅悗鍖洪棿鐨勫紓甯告暟鎹紝鏃堕棿瀛楃涓� + * @returns锛� + */ + findTimeInExceptionData(data, time) { + for (let i = 0; i < data.length; i++) { + if (data[i] == null) { + continue; + } + if (data[i]['lst'] == time) { + return data[i]['dustValue']; + } + } + return -1; + }, + /** + * description锛氭牴鎹紑濮嬪拰缁撴潫鏃堕棿,杩斿洖浠�15鍒嗛挓涓洪棿闅旂殑鏃堕棿鍜屽搴旂殑鍊� + * @param锛� 鍓嶅尯闂寸殑寮�濮嬫椂闂达紝 鍚庡尯闂寸殑缁撴潫鏃堕棿, 鍔犱笂鍓嶅悗鍖洪棿鐨勬�绘椂闂存鐨勫紓甯告暟鎹殑瀵硅薄鏁扮粍 + * @returns锛氬璞°�傚寘鍚簡鎶樼嚎鍥剧殑x杞达紝y杞寸殑閰嶇疆鏁版嵁 + */ + keepContinuousByEachFiftyMinutes( + intervalStarTime, + intervalEndTime, + headAndTailExceptionData + ) { + let xAxis = []; + let yAxis = []; + let obj = {}; + let current = intervalStarTime; + let tail = dayjs(intervalEndTime) + .add(15, 'minute') + .format('YYYY-MM-DD HH:mm:ss'); + while (current != tail) { + let value = this.findTimeInExceptionData( + headAndTailExceptionData, + current + ); + if (value != -1) { + xAxis.push(current); + yAxis.push(value); + } else { + xAxis.push(current); + yAxis.push(null); + } + current = dayjs(current) + .add(15, 'minute') + .format('YYYY-MM-DD HH:mm:ss'); + } + obj['xAxis'] = xAxis; + obj['yAxis'] = yAxis; + return obj; + }, + +} \ No newline at end of file -- Gitblit v1.9.3