zmc
2023-11-24 e7ce285475a1355eeaeaba1855e3cd615eafa13b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// import dayjs from 'dayjs';
import exceptionApi from '@/api/exceptionApi.js'
import index from '@/utils/risk_estimate_common_function/index.js'
 
export default {
  // 根据设备编号进行分组
  groupByMncode(analysisData) {
    const groupedData = {}
    for (let obj of analysisData) {
      const mnCode = obj.mnCode
      if (!groupedData[mnCode]) {
        groupedData[mnCode] = []
      }
      groupedData[mnCode].push(obj)
    }
    return groupedData
  },
 
  fetchData(beginTime, endTime) {
    return new Promise((resolve, reject) => {
      // 获取统计分析数据
      exceptionApi.analysisdataByTimeAndType(beginTime, endTime, 'day').then((response) => {
        const chartData = response.data.data
        console.log('fenxi:', chartData)
        // 获取异常数据
        exceptionApi
          .exceptiondata1({
            siteName: '',
            beginTime: beginTime,
            endTime: endTime
          })
          .then((res) => {
            let result = this.merge(chartData, res.data.data, beginTime, endTime)
            console.log('名字为:', result.siteName, result.max)
            resolve(result.siteName)
            // return result.siteName
          })
      })
    })
  },
 
  // 企业异常详情
  exceptiondataCount(beginTime, endTime, type) {
    exceptionApi.analysisdataByTimeAndType(beginTime, endTime, type).then((res) => {
      let obj = index.calRecur(res.data.data)
      this.bill.exceptionRecurrence = obj['exceptionRecurrence']
      this.bill.exceptionTypeAggregation = obj['exceptionTypeAggregation']
    })
  },
 
  merge(anaData, exceptionData, beginTime, endTime) {
    if (anaData.length == 0) {
      return []
    }
    let i = 0
    // 对设备编号进行分组
    let groupeObj = this.groupByMncode(anaData)
    // 保存风险值和站点名字
    let weightAndName = []
    for (let item in groupeObj) {
      // item是设备编号, 获得item对应得数据
      let groupBySameMncode = groupeObj[item]
 
      // 从分析数据中得到设备编号
      let mnCode = item
      // 找到异常数据中mnCode等于value的对象
      let d = index.findValue(exceptionData, mnCode)
      // let temp = [...res,...d]
 
      // 计算在线,有效率,超标率
      // 有问题
      let r1 = index.calBillData(groupBySameMncode, beginTime, endTime)
 
      // 计算复现率
      let r2 = index.calRecur(d)
      i = i + 1
      // 数组的拷贝 防止地址引用
      let temp = index.shallowCopyList('arr')
      temp.push(r1['online'])
      temp.push(r1['valid'])
      temp.push(r1['exceeding'])
      temp.push(r2['exceptionRecurrence'])
      temp.push(r2['exceptionTypeAggregation'])
      // 计算风险值
      let weight = index.calRiskValue(temp)
 
      // 对象的拷贝 防止地址引用
      let obj = index.shallowCopyList('obj')
      obj.riskValue = weight
      // 添加该设备编号对应得站点名字
      obj.name = groupBySameMncode[0].name
      weightAndName.push(obj)
    }
 
    // 获得最大风险值得名字
    const result1 = this.compare_riskWeight(weightAndName)
    return result1
  },
 
  compare_riskWeight(arr) {
    const obj = {
      max: -1,
      siteName: ''
    }
 
    arr.forEach((item) => {
      if (item.riskValue > obj.max) {
        obj.max = item.riskValue
        obj.siteName = item.name
      }
    })
    return obj
  }
}