ZZJ
2022-03-25 52ad37fba37a1ae72f124106627227a09836be5b
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import { getPollConfig, changeRunType, getCamerasByServer, statisticRunInfo, updateChannelCount } from "@/api/pollConfig";
import { getSystemSummaryInfo, getSysThresholds } from "@/api/system"
 
export default class PollData {
  public Config: Object = {};
  public SearchName: String = "";
  public CameraList: Array<object> = [];
  public Enabled: boolean = false;
 
  //总算力
  public channelTotal: number = 0;
 
  public Running: number = 0;
  public Idle: number = 0;
  //实时全部打开
  public RealTimeSum: number = 0;
  //实时算力总数
  public RealTimeValidCount: number = 0;
  //实时配置不全
  public RealTimeInvalid: number = 0;
  //实时正在处理
  public RealTimeRun: number = 0;
  //实时故障
  public RealTimeNoDeal: number = 0;
 
 
  //轮询算力总数
  public PollValidCount: number = 0;
  //轮询全部打开
  public PollSum: number = 0;
  //轮询正在执行
  public PollRun: number = 0;
  //轮询配置不全
  public PollInvalid: number = 0;
  //轮询故障
  public PollNoDeal: number = 0;
  public PollChannelTotal: number = 0;
 
 
  //数据栈算力总数
  public stackChannelCount: number = 0;
  //数据栈总数
  public stackTotal: number = 0;
  //数据栈配置不全
  public stackInvalidCount: number = 0;
  //数据栈正在执行
  public stackRunningCount: number = 0;
  //数据栈故障
  public stackNoDeal: number = 0;
 
 
  //本地算力通道数
  public localVideo: number = 0;
 
  public CpuUsedPercent: number = 0;
  public MemUsedPercent: number = 0;
  public GpuUsedPercent: number = 0;
  public DiskUsePercent: number = 0;
  public barCharts: Array<any> = [];
  public Thresholds: Array<object> = [];
 
  //算力配置中滑块数据
  public sliderList: Array<any> = [];
 
  public init() {
    this.fetchPollConfig();
    this.fetchPollList();
    this.sysThresholds();
    this.statisticTaskInfo();
  }
 
  public async fetchPollConfig() {
    const rsp: any = await getPollConfig();
    if (rsp && rsp.success) {
      this.Config = rsp.data;
      if (rsp.data.enable) {
        this.Enabled = true;
      }
    }
  }
 
  public async fetchPollList() {
    this.CameraList = []
    let rsp: any = await getCamerasByServer({ cameraName: this.SearchName });
    if (rsp && rsp.success) {
      if (rsp.data) {
        this.CameraList = rsp.data.sort(function (obj1: any, obj2: any) {
          var val1 = obj1.run_type;
          var val2 = obj2.run_type;
          return (val2 - val1)
        });
      }
    }
 
    // 根据rtsp 提取ip地址
    const ipReg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
    this.CameraList.forEach((cam: any) => {
      // 国标摄像机不显示ip
      if (cam.type === 1) {
        cam.ip = "-"
        return
      }
      let ip = ipReg.exec(cam.rtsp)
      if (ip.length > 0) {
        cam.ip = ip[0]
      }
    })
  }
 
  public async switchType(id: string, type: number) {
    let rsp: any = await changeRunType({ camera_ids: [id], run_type: type });
  }
 
  public async sysThresholds() {
    let rsp: any = await getSysThresholds()
    if (rsp && rsp.success) {
      this.Thresholds = rsp.data;
    }
  }
  public async statistics() {
    let list = []
 
    let rsp: any = await getCamerasByServer({ cameraName: "" });
    if (rsp && rsp.success) {
      list = list.concat(rsp.data);
    }
 
    let RealTimeSum = 0, RealTimeRun = 0, PollSum = 0, PollRun = 0;
 
    list.forEach((cam: any) => {
      if (cam.run_type === 1) {
        RealTimeSum++
        if (cam.is_running) {
          RealTimeRun++
        }
      }
 
      if (cam.run_type === 0) {
        PollSum++
        if (cam.is_running) {
          PollRun++
        }
      }
    })
 
    this.Running = RealTimeRun + PollRun
    this.Idle = RealTimeSum + PollSum - this.Running
 
    // 计算系统信息
    rsp = await getSystemSummaryInfo()
    if (rsp && rsp.success && rsp.data.cpu) {
      let sysinfo = rsp.data
 
      // cpu
      if (sysinfo.cpu) {
        let cpuLoad = sysinfo.cpu.reduce((pre, item) => {
          return pre + item;
        }, 0)
 
        this.CpuUsedPercent = Number((cpuLoad / sysinfo.cpu.length).toFixed(2))
      }
 
      // 内存
      this.MemUsedPercent = Number(sysinfo.mem.usedPercent.toFixed(2))
      // 硬盘使用情况
      this.DiskUsePercent = Number(sysinfo.disk.usedPercent.toFixed(2))
 
      if (sysinfo.gpu) {
        let gpuLoad = 0, gpuTotal = 0;
 
        for (let i = 0; i < sysinfo.gpu.length; i++) {
          gpuLoad += sysinfo.gpu[i].used;
          gpuTotal += sysinfo.gpu[i].memory;
        }
        this.GpuUsedPercent = Number((gpuLoad / gpuTotal * 100).toFixed(2))
      }
      this.barCharts = [this.DiskUsePercent,this.CpuUsedPercent,this.GpuUsedPercent,this.MemUsedPercent]
    }
 
    console.log(this);
    
  }
 
  public async statisticTaskInfo() {
    let res: any = await statisticRunInfo({});
    if (res && res.success) {
      // console.log(res,'统计实时、轮询数量')
      this.RealTimeSum = res.data.realTotal
      this.RealTimeRun = res.data.realRunningCount
      this.RealTimeValidCount = res.data.realValidCount
      this.RealTimeInvalid = res.data.realInvalidCount
      this.RealTimeNoDeal = this.RealTimeSum - this.RealTimeRun - this.RealTimeInvalid
 
      this.channelTotal = res.data.channelTotal
 
      this.PollValidCount = res.data.pollChannelCount
      this.PollSum = res.data.pollTotal
      this.PollRun = res.data.pollRunningCount
      this.PollInvalid = res.data.pollInvalidCount
      this.PollNoDeal = this.PollSum - this.PollRun - this.PollInvalid
      this.PollChannelTotal = res.data.pollChannelCount
 
      this.stackChannelCount = res.data.stackChannelCount
      this.stackTotal = res.data.stackTotal
      this.stackInvalidCount = res.data.stackInvalidCount
      this.stackRunningCount = res.data.stackRunningCount
      this.stackNoDeal = this.stackTotal - this.stackInvalidCount - this.stackRunningCount
 
      this.localVideo = res.data.stackChannelCount
 
      // this.Running = this.RealTimeRun + this.PollRun
      // this.Idle = this.RealTimeSum + this.PollSum - this.Running
      let totalCount = res.data.channelTotal
      let realCount = res.data.realValidCount
      let pollCount = res.data.pollChannelCount
      this.sliderList = [0,realCount,realCount + pollCount]
      // if(realCount + pollCount == totalCount){
      //   this.sliderList = [0,realCount,realCount + pollCount]
      // }else{
      //   this.sliderList = [0,realCount,realCount + pollCount,totalCount]
      // }
      
    }
  }
 
  public async updateChannelCount(fileChannelCount,pollChannelCount){
    let res: any = await updateChannelCount({
      videoChannelCount: fileChannelCount,
      pollChannelCount: pollChannelCount
    })
    this.statisticTaskInfo()
  }
}