-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·153 lines (146 loc) · 3.84 KB
/
index.html
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
<HTML>
<BODY>
<form onsubmit="return false;">
<select id="months" >
</select>
1st day: <input id="first" type=number size="1" >
Monthly limit: <input id="limit" type=number size=10 > Gb
</form>
<div id="container" style="width:100%; height:400px;"></div>
<script src="js/jquery-min.js"></script>
<script src="js/highcharts.js"></script>
<script>
<!--
var createChart=function (datePrefix,firstday,limit) {
limit=parseInt(limit);
firstDay=new Date();
firstDay.setFullYear(parseInt(datePrefix.substring(0,4)),parseInt(datePrefix.substring(5))-1,firstday);
firstDay.setHours(0,0,0,0);
lastDay=new Date();
lastDay.setFullYear(parseInt(datePrefix.substring(0,4)),parseInt(datePrefix.substring(5)),firstday-1);
lastDay.setHours(0,0,0,0);
$.get('meres.txt',function(data) {
dailyConsumption=[];
left=[];
var rows=data.split('\n');
rows.splice(0,1);
dates=[];
$.each(rows,function(index,value) {
fields=value.split('-');
if (fields.length>1) {
str=fields[0]+"-"+fields[1];
if ($.inArray(str,dates)==-1) {
dates.push(str);
}
}
});
$( "#months" ).html("");
$.each(dates,function(index,value) {
html="<option"+(value==datePrefix?" selected=\"selected\"":"")+">"+value+"</option>";
$(html).appendTo("#months");
});
$.each(rows,function(index,value) {
var cons=value.split(',');
date=new Date(cons[0]);
if (date>=firstDay && date<lastDay) {
dailyConsumption.push([date.getTime(),parseInt(cons[3])/1024/1024]);
}
});
dailyConsumption.sort( function (a,b) {
return a[0]<b[0]?-1:a[0]>b[0]?1:0;
});
MbLeft=limit*1024;
left=[[firstDay.getTime(),limit]];
lastData=left[0][0];
$.each(dailyConsumption, function(index,value) {
MbLeft-=value[1];
lastData=value[0]+(24*60*60*1000/2);
left.push([lastData,MbLeft/1024]);
});
if (lastDay.getTime()-lastData>4*24*3600*1000) {
msAvg=((limit*1024-MbLeft))/(lastData-firstDay.getTime());
prognosis=msAvg*(lastDay.getTime()-firstDay.getTime());
left.push([lastDay.getTime(),((limit*1024)-prognosis)/1024]);
}
$('#container').highcharts({
chart: {
},
title: {
text: 'Traffic analysis'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%e. %b',
year: '%b'
}
},
yAxis: [
{
min: 0,
id: "cucc",
title: {
text: 'data in Megabytes '
},
},
{
id: "mucc",
title: {
text: 'data in Gigabytes '
},
opposite: true,
min: 0
}
],
tooltip: {
formatter: function () {
return "<b>"+Highcharts.dateFormat("%b %e",this.x)+
"</b><br/>"+this.series.userOptions.tooltipOptions.valuePrefix+
Highcharts.numberFormat(this.y,2)+
this.series.userOptions.tooltipOptions.valueSuffix;
}
},
series: [{
type: 'column',
name: 'Daily Consumption',
data: dailyConsumption,
yAxis: "cucc",
tooltipOptions: {
valuePrefix:"Consumption: ",
valueSuffix:" Mb" }
},
{
type: 'spline',
name: 'left',
data: left,
yAxis: "mucc",
tooltipOptions: {
valuePrefix:"Left: ",
valueSuffix:" Gb" }
}
]
});
},'text');
};
if (!$( "#first" ).val()) {
$( "#first" ).val(8);
}
if (!$( "#limit" ).val()) {
$( "#limit" ).val(8);
}
currentDatePrefix=new Date().toISOString().substring(0,7);
createChart(currentDatePrefix,
$("#first").val(),
$("#limit").val());
var recreate=function() {
createChart($( "#months option:selected" ).val(),
$("#first").val(),
$("#limit").val());
};
$( "#months" ).change( recreate);
$( "#limit" ).change( recreate);
$( "#first" ).change( recreate);
-->
</script>
</BODY>
</HTML>