-
Notifications
You must be signed in to change notification settings - Fork 0
/
avgBandWidthDisplay.user.js
118 lines (116 loc) · 3.76 KB
/
avgBandWidthDisplay.user.js
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
// ==UserScript==
// @name 带宽统计增强
// @namespace http://tampermonkey.net/
// @version 0.2.1
// @description 增加对应的图表
// @author 易波
// @match https://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=165.10
// @grant none
// ==/UserScript==
(function () {
'use strict';
var ShowLatestDays = 7; // 显示最近多少天的数据
var MaxAvgTimesw = 4; // Y轴限高
var DebugOn = false; // 开启调试
//---------------以下代码请勿修改-----------------
var parentNode;
var data = {}
try{
$('.panel-body script').each((i, x) => {
var chartParams = JSON.parse(x.innerText.slice('echartsKmgV2('.length, -2))
var panel = $(x).closest('.panel')
var title = panel.find('>.panel-heading').text().split(' ')[0]
data[title] = chartParams
parentNode = panel.parent()
})
}catch(e){
console.log("no chart yet");
return
}
if(!Object.entries(data).length){
console.log("no chart yet");
return
}
if(!(data.UserCount && data.Bandwidth)){
console.log("miss some chart");
return
}
data.AvgBandwidth = {
DomId: "chartAvgBandwidth",
YMin: +Infinity,
YMax: -Infinity,
Data: [],
}
var YTotal = 0
var YCnt = 0
var sevenDaysAgo = +moment().subtract(3, 'days')
data.UserCount.Data.forEach((item, idx) => {
var bwItem = data.Bandwidth.Data[idx]
if (item[0] < sevenDaysAgo) {
return
}
if (item[0] == bwItem[0]) {
var avgBw = bwItem[1] / item[1]
if (avgBw == Infinity) {
DebugOn && console.log(bwItem[1], item[1], "got Infinity")
} else {
// console.log(item[0], bwItem[1], item[1], avgBw)
data.AvgBandwidth.Data.push([
item[0],
avgBw,
])
if (data.AvgBandwidth.YMax < avgBw) {
data.AvgBandwidth.YMax = avgBw
}
if (data.AvgBandwidth.YMin > avgBw) {
data.AvgBandwidth.YMin = avgBw
}
YTotal += avgBw
YCnt++
}
}
});
var YAvg = YTotal / YCnt
if (data.AvgBandwidth.YMax > MaxAvgTimesw * YAvg) {
data.AvgBandwidth.YMax = MaxAvgTimesw * YAvg
}
//console.log("YAvg", YTotal,YCnt, YAvg)
parentNode.append(`<div class="panel panel-default">
<div class="panel-heading">AvgBandwidth</div>
<div class="panel-body">
<div style="height:220px;overflow:hidden;">
<div id="chartAvgBandwidth" style="margin: 5px; width: 100%; height: 200px; -webkit-tap-highlight-color: transparent; user-select: none; position: relative;">
</div>
</div>
</div>
</div>`)
DebugOn && console.log(data.AvgBandwidth)
echartsKmgV2(data.AvgBandwidth)
setTimeout(() => {
var dom = document.getElementById('chartAvgBandwidth')
var chart = echarts.getInstanceByDom(dom)
window.zchart = chart
DebugOn && console.log(chart)
var option = chart.getOption()
DebugOn && console.log(option)
option.series[0].markLine = {
lineStyle: {
color: "#f00"
},
data: [{
name: '报警预测值',
yAxis: YAvg
}],
}
option.markLine = null
option.animation = true;
console.log(option)
// chart.setOption(option)
chart.dispose()
var newChart = echarts.init(dom)
newChart.setOption(option)
window.zchart = newChart
}, 2000)
// https://echarts.apache.org/en/api.html#echarts
})();