whychdw
2019-12-03 b6f0fbd68c5eef78bb8004a579fea4cee8b2dbaf
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
"use strict";
 
// 获取页面的根目录并返回
 
function getPageRoot(module, parent) {
    var rs = "#" + module.id + ' .bui-page';
    if (parent) {
        rs = $(rs).parent().get(0);
    }
    return rs;
}
 
/*从多维数组中获取最大值*/
function getMaxFromArr(arr) {
    var newArray = arr.join(",").split(",");
    return Math.max.apply({}, newArray);
}
 
/*从多维数组中获取最小值*/
function getMinFromArr(arr) {
    var newArray = arr.join(",").split(",");
    return Math.min.apply({}, newArray);
}
/*从多维数组中获取和*/
function getSumFromArr(arr) {
    var newArray = arr.join(",").split(",");
    var sum = 0;
    for (var i = 0; i < newArray.length; i++) {
        var _newArray = newArray[i];
        sum += Number(_newArray);
    }
    return sum;
}
 
function Title() {
    this.min = 0; //最小值
    this.max = 0; //最大值
    this.avg = 0; //平均值
    this.sum = 0; //总和
    this.ahight = 0; //高告警阀值
    this.alow = 0; //低告警阀值
    this.clow = 0; //次低更换阀值
    this.lc = 0; //低告警单体数
    this.lp = 0; //低告警百分比
}
function createTitle() {
    var obj = new Object();
    obj.min = 0;
    obj.max = 0;
    obj.avg = 0;
    obj.sum = 0;
    obj.ahight = 0;
    obj.alow = 0;
    obj.clow = 0;
    obj.lc = 0;
    obj.lp = 0;
    return obj;
}
 
Title.prototype.setMin = function (min) {
    this.min = min;
};
 
Title.prototype.getMin = function () {
    return this.min;
};
 
Title.prototype.setMax = function (max) {
    this.max = max;
};
 
Title.prototype.getMax = function () {
    return this.max;
};
 
Title.prototype.setAvg = function (avg) {
    this.avg = avg;
};
 
Title.prototype.getAvg = function () {
    return this.avg;
};
 
Title.prototype.setSum = function (sum) {
    this.sum = sum;
};
 
Title.prototype.getSum = function () {
    return this.sum;
};
 
Title.prototype.setAhight = function (ahight) {
    this.ahight = ahight;
};
 
Title.prototype.getAhight = function () {
    return this.ahight;
};
 
Title.prototype.setAlow = function (alow) {
    this.alow = alow;
};
 
Title.prototype.getAlow = function () {
    return this.alow;
};
 
Title.prototype.setClow = function (clow) {
    this.clow = clow;
};
 
Title.prototype.getClow = function () {
    return this.clow;
};
 
Title.prototype.setLc = function (lc) {
    this.lc = lc;
};
 
Title.prototype.getLc = function () {
    return this.lc;
};
 
Title.prototype.setLp = function (lp) {
    this.lp = lp;
};
 
Title.prototype.getLp = function () {
    return lp;
};
 
Title.prototype.getAllTile = function (lname) {
    //alert(this.avg);
    var title = "";
    var maxText = '最大值'; //最大值
    var minText = '最小值'; //最小值
    var avgText = '平均值'; //平均值
    var lowText = '落后值'; //落后值
    var lcText = '落后数量'; //落后数量
    var lpText = '落后数量比'; //落后数量比
    if ("Voltage" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(3))+"V;"+minText+"="+(parseFloat(this.min).toFixed(3))+"V;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"V;"+lowText+"="+this.alow+"V;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(3) + "V;" + minText + "=" + parseFloat(this.min).toFixed(3) + "V;" + avgText + "=" + parseFloat(this.avg).toFixed(3) + "V;累加和=" + parseFloat(this.sum).toFixed(3) + "V";
    } else if ("Resistance" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(3))+"mΩ;"+minText+"="+(parseFloat(this.min).toFixed(3))+"mΩ;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"mΩ;"+lowText+"="+this.alow+"mΩ;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(3) + "mΩ;" + minText + "=" + parseFloat(this.min).toFixed(3) + "mΩ;" + avgText + "=" + parseFloat(this.avg).toFixed(3) + "mΩ";
    } else if ("Temperature" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(1))+"℃;"+minText+"="+(parseFloat(this.min).toFixed(1))+"℃;"+avgText+"="+(parseFloat(this.avg).toFixed(1))+"℃;"+lowText+"="+this.alow+"℃;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(1) + "℃;" + minText + "=" + parseFloat(this.min).toFixed(1) + "℃;" + avgText + "=" + parseFloat(this.avg).toFixed(1) + "℃";
    } else if ("Conductance" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(0))+";"+minText+"="+(parseFloat(this.min).toFixed(0))+";"+avgText+"="+(parseFloat(this.avg).toFixed(0))+";"+lowText+"="+this.alow+";"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(0) + ";" + minText + "=" + parseFloat(this.min).toFixed(0) + ";" + avgText + "=" + parseFloat(this.avg).toFixed(0);
    } else if ("MonJHCurr" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(3))+"V;"+minText+"="+(parseFloat(this.min).toFixed(3))+"V;"+avgText+"="+(parseFloat(this.avg).toFixed(3))+"V;"+lowText+"="+this.alow+"V;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(3) + "mA;" + minText + "=" + parseFloat(this.min).toFixed(3) + "mA;" + avgText + "=" + parseFloat(this.avg).toFixed(3) + "mA";
    } else if ("Serpercent" == lname || "Percent_total_capacity" == lname) {
        //title=maxText+"="+this.max+"%;"+minText+"="+this.min+"%;"+avgText+"="+this.avg+"%;"+lowText+"="+this.alow+"%;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + this.max + "%;" + minText + "=" + this.min + "%;" + avgText + "=" + this.avg + "%";
    } else if ("Actual_capacity" == lname || "Residual_capacity" == lname) {
        //title=maxText+"="+(parseFloat(this.max).toFixed(0))+"AH;"+minText+"="+(parseFloat(this.min).toFixed(0))+"AH;"+avgText+"="+(parseFloat(this.avg).toFixed(0))+"AH;"+lowText+"="+this.alow+"AH;"+lcText+"="+this.lc+";"+lpText+"="+this.lp+"%";
        title = maxText + "=" + parseFloat(this.max).toFixed(0) + "AH;" + minText + "=" + parseFloat(this.min).toFixed(0) + "AH;" + avgText + "=" + parseFloat(this.avg).toFixed(0) + "AH";
    }
    return title;
};
 
//将秒转化成时:分:秒
function formatSeconds(value) {
    if (value > 0) {} else {
        value = 0;
    }
    var theTime = parseInt(value); // 秒
    var theTime1 = 0; // 分
    var theTime2 = 0; // 小时
    // alert(theTime);
    if (theTime >= 60) {
        theTime1 = parseInt(theTime / 60);
        theTime = parseInt(theTime % 60);
        //alert(theTime1+"-"+theTime);
        if (theTime1 >= 60) {
            theTime2 = parseInt(theTime1 / 60);
            theTime1 = parseInt(theTime1 % 60);
        }
    }
    var result = (theTime < 10 ? "0" : "") + parseInt(theTime);
    if (theTime1 >= 0) {
        result = (theTime1 < 10 ? "0" : "") + parseInt(theTime1) + ":" + result;
    }
    if (theTime2 >= 0) {
        result = (theTime2 < 10 ? "0" : "") + parseInt(theTime2) + ":" + result;
    }
    //console.info(result);
    return result;
}
 
// 延时计时器
function Timeout() {
    this.timer = null;
    this.time = '';
    this.callback = '';
}
// 开启计时器并添加
Timeout.prototype.start = function (callback, time, exe) {
    // 先关闭计时器
    this.stop();
    // 配置执行函数
    if (typeof callback == 'function' && typeof time == 'number') {
        this.callback = callback;
        this.time = time;
        if (exe != 'exe') {
            callback();
        }
        this.timer = setTimeout(callback, time);
    } else {
        console.warn('未完整配置参数!');
    }
};
// 开启计时器
Timeout.prototype.open = function () {
    var callback = this.callback;
    var time = this.time;
    this.start(callback, time, 'exe');
};
 
// 关闭计时器
Timeout.prototype.stop = function () {
    clearTimeout(this.timer);
};
 
// 对新旧数据进行对比
function HandleData() {};
 
// 对新旧数据进行对比处理
HandleData.prototype.handle = function (oldData, newData, keys) {
    // 剔除旧数据
    this.del(oldData, newData, keys);
 
    // 添加新数据
    this.add(oldData, newData, keys);
};
// 添加新数据
HandleData.prototype.add = function (oldData, newData, keys) {
    // 遍历新数据
    for (var i = 0; i < newData.length; i++) {
        var _newData = newData[i];
        var isExist = this.checkObjIsExist(_newData, oldData, keys);
        if (isExist.code == 0) {
            oldData.push(_newData);
        }
    }
};
// 提出旧数据
HandleData.prototype.del = function (oldData, newData, keys) {
    // 遍历旧数据
    for (var i = 0; i < oldData.length; i++) {
        var _oldData = oldData[i];
        var isExist = this.checkObjIsExist(_oldData, newData, keys);
        if (isExist.code == 0) {
            oldData.splice(i, 1);
            i--;
        }
    }
};
// 检测对象是否存在于对象数组中
HandleData.prototype.checkObjIsExist = function (obj, objs, keys) {
    var result = {
        code: 0,
        index: -1,
        data: {}
    };
    // 遍历数组
    for (var i = 0; i < objs.length; i++) {
        var _objs = objs[i];
        var equal = true; // 相等
        // 遍历keys
        for (var k = 0; k < keys.length; k++) {
            var key = keys[k];
            if (_objs[key] == undefined || _objs[key] != obj[key]) {
                equal = false;
                break;
            }
        }
 
        // 存在属性值一致的对象
        if (equal) {
            result.code = 1;
            result.index = i;
            result.data = _objs;
        }
    }
 
    return result;
};
 
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(), //day
        "h+": this.getHours(), //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds() //millisecond
    };
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    }return format;
};
 
// 电池告警名称
var battAlarmTypes = [{
    value: 119001,
    text: '组端电压告警',
    unit: "V"
}, {
    value: 119002,
    text: '电池电流告警',
    unit: "A"
}, {
    value: 119003,
    text: '单体电压告警',
    unit: 'V'
}, {
    value: 119004,
    text: '单体温度告警',
    unit: '℃'
}, {
    value: 119005,
    text: '单体内阻告警',
    unit: 'mΩ'
}];
 
// 电池告警类型
var almSignalId = [{
    value: 0,
    text: '无告警'
}, {
    value: 1,
    text: '下限告警'
}, {
    value: 2,
    text: '上限告警'
}];
 
// 根据value的值获取文本值
function getTextByVal(value, list) {
    var rs = "未知";
    // 遍历list
    for (var i = 0; i < list.length; i++) {
        var _list = list[i];
        if (_list.value == value) {
            rs = _list.text;
        }
    }
    return rs;
}
 
// 根据value的值获取单位
function getTextByUnit(value, list) {
    var rs = "";
    // 遍历list
    for (var i = 0; i < list.length; i++) {
        var _list = list[i];
        if (_list.value == value && _list.unit) {
            rs = _list.unit;
        }
    }
    return rs;
}