Skip to content

Commit 8187c8a

Browse files
author
pszgp
committed
Dashboard graphs for devices and urls
1 parent ea4a902 commit 8187c8a

29 files changed

+5439
-873
lines changed
-205
Original file line numberDiff line numberDiff line change
@@ -1,205 +0,0 @@
1-
/*
2-
* To change this template, choose Tools | Templates
3-
* and open the template in the editor.
4-
*/
5-
6-
7-
// d3 barchart sample from : "http://www.guerino.net"
8-
//var dataSet = [{legendLabel: "Data Usage: 2012 APRIL", magnitude: 54.45},
9-
//{legendLabel: "Data Usage: 2012 MAY", magnitude: 21.1}];
10-
11-
var hwColour = "#64A0DE";
12-
13-
function drawHorizontalBarChart(chartID, selectString, colors, values, months) {
14-
15-
//alert(values);
16-
//alert(values.indexOf("{"));
17-
18-
var deviceIp = "${deviceIp}";
19-
var monthId = "${monthId}";
20-
var monthName = "${month}";
21-
22-
var MONTHS = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER",
23-
"OCTOBER", "NOVEMBER", "DECEMBER"];
24-
if (values.indexOf("{")==0)
25-
{
26-
values = values.substring(1, values.length-1);
27-
//alert(values);
28-
values = values.split(",");
29-
//alert(values);
30-
}
31-
32-
if (values==null)
33-
d3.csv("data/HW/HWStatsUsageFlows_sql_.csv", function (data) {
34-
values = data;
35-
});
36-
/*if (deviceIp!=null)
37-
values = data.filter(function(d) {
38-
var date = d.ipdate;
39-
date = date.substring(date.indexOf(" ")+1);
40-
var deviceMonth = date.split("-")[1];
41-
if (deviceMonth.indexOf("0")==0)
42-
deviceMonth=deviceMonth.substring(1);
43-
deviceMonth--;
44-
//alert(deviceMonth+" "+monthId+" "+(deviceMonth==monthId));
45-
//exit;
46-
//if (d.ipaddr == deviceIp)
47-
// if (deviceMonth == monthId)
48-
// return true;
49-
//return false;
50-
return ((d.ipaddr == deviceIp) && (deviceMonth == monthId));
51-
});
52-
//alert(values);
53-
/*values.forEach(function(d) {
54-
var date = d.ipdate;
55-
date = date.substring(date.indexOf(" ")+1);
56-
var day = date.split("-")[2];
57-
//to avoid null values set the non used values to default:
58-
d.date = date; d.ipaddr = deviceIp; d.last = date;
59-
//set the values used for the graph
60-
d.ipdate = day + monthName;//parse(date);
61-
d.bytes =+ d.bytes;
62-
d.bytes = d.bytes/(1024*1024);
63-
d.bytes = d.bytes.toFixed(2);
64-
//set the link to details of the day...
65-
d.link = "deviceday.htm?ip="+deviceIp+"&month="+monthName+"&monthId="+monthId+"&day="+day;
66-
});*/
67-
var data = [];
68-
for (var i=0;i<values.length;i++)
69-
{
70-
var d = values[i];
71-
var date = d;
72-
date = date.substring(0, date.indexOf("="));
73-
if (months)
74-
{
75-
date = +date;
76-
date = MONTHS[date];
77-
}
78-
else
79-
date = date+monthName;
80-
81-
var nbytes = d.substring(d.indexOf("=")+1, d.length);
82-
nbytes = +nbytes;
83-
nbytes = nbytes / (1024*1024);
84-
nbytes = nbytes.toFixed(2);//decimals, Math.floor(): no decimals
85-
86-
var object = {};
87-
object.date = date;
88-
object.bytes = nbytes;
89-
90-
data[i] = object;
91-
92-
//alert(object);
93-
}
94-
95-
for (var i=0;i<data.length;i++)
96-
{
97-
var d = data[i];
98-
//alert(d.date+" "+d.bytes);
99-
}
100-
//alert(data);
101-
102-
/*var data=[1,2,3,4];
103-
data.forEach(function(d){
104-
data.date = 1;
105-
data.bytes = 2;
106-
alert(data.date+" "+data.bytes);
107-
return data;
108-
});*/
109-
/*values.forEach(function(d){
110-
//alert(d+" "+d.indexOf("="));
111-
var date = d;
112-
date = date.substring(0, date.indexOf("="));
113-
var nbytes = d.substring(d.indexOf("=")+1, d.length);
114-
nbytes = +nbytes;
115-
//alert(d+" "+date+" and "+nbytes);
116-
d.date = date;
117-
d.nbytes = nbytes;
118-
var data={"date":date, "nbytes": nbytes};
119-
data.date = data["date"];
120-
data.nbytes = data["nbytes"];
121-
alert(data.date+" "+d.nbytes);
122-
d.date = data.date;
123-
d.nbytes = data.nbytes;
124-
d = data;
125-
return d;
126-
//return data;
127-
//alert(d.nbytes+" "+d.date);
128-
});*/
129-
130-
//alert(values);
131-
132-
values = data;
133-
//alert(values);
134-
//values.forEach(function(d){alert(d.date+" "+d.bytes);});
135-
136-
var canvasWidth = 700;
137-
var barsWidthTotal = 300;
138-
var barHeight = 20;
139-
var barsHeightTotal = barHeight * values.length;
140-
//var canvasHeight = 200;
141-
var canvasHeight = values.length * barHeight + 10; // +10 puts a little space at bottom.
142-
var legendOffset = barHeight/2;
143-
var legendBulletOffset = 30;
144-
var legendTextOffset = 40;
145-
146-
var x = d3.scale.linear().domain([0, d3.max(values, function(d) { return d.bytes; })]).rangeRound([0, barsWidthTotal]);
147-
var y = d3.scale.linear().domain([0, values.length]).range([0, barsHeightTotal]);
148-
149-
// Create the svg drawing canvas...
150-
var canvas = d3.select(selectString)
151-
.append("svg:svg")
152-
.attr("width", canvasWidth)
153-
.attr("height", canvasHeight);
154-
155-
// Draw individual hyper text enabled bars...
156-
canvas.selectAll("rect")
157-
.data(values)
158-
.enter()
159-
.append("svg:rect")
160-
.attr("x", 0) // Right to left
161-
.attr("y", function(d, i) { return y(i); })
162-
.attr("height", barHeight)
163-
.style("fill", "black" )
164-
.style("stroke", "black" )
165-
.attr("width", function(d) { if (d.bytes<100) return 1; else return x(d.bytes/10); })
166-
.style("fill", function(d, i) { colorVal = hwColour; return colorVal; } )
167-
.attr("index_value", function(d, i) { return "index-" + i; })
168-
.attr("class", function(d, i) { return "bars-" + chartID + "-bar-index-" + i; })
169-
.attr("color_value", function(d, i) { return hwColour; })
170-
.style("stroke", "black");
171-
172-
// Create text values that go at end of each bar...
173-
canvas.selectAll("text")
174-
.data(values) // Bind dataSet to text elements
175-
.enter().append("svg:text") // Append text elements
176-
.attr("x", x)
177-
.attr("y", function(d, i) { return y(i); })
178-
.attr("dx", function(d) { return barsWidthTotal;})//return x(d.bytes/10) + 100; })
179-
.attr("dy", barHeight-5)
180-
//.attr("text-anchor", "end")
181-
.text(function(d) { return d.date+":\t"+d.bytes + " Mb";})
182-
.attr("fill", "black");
183-
184-
// Create hyper linked text at right that acts as label key...
185-
canvas.selectAll("a.legend_link")
186-
.data(values) // Instruct to bind dataSet to text elements
187-
.enter().append("svg:a")
188-
.attr("xlink:href", function(d) { return d.link; })
189-
.append("text")
190-
.attr("text-anchor", "center")
191-
.attr("x", barsWidthTotal + legendBulletOffset + legendTextOffset)
192-
.attr("y", function(d, i) { return legendOffset + i*barHeight; } )
193-
.attr("dx", 0)
194-
.attr("dy", "5px")
195-
.text(function(d) { return d.ipdate;})//legendLabel
196-
.style("fill", "Black")
197-
//.on('mouseover', synchronizedMouseOver)
198-
//.on("mouseout", synchronizedMouseOut)
199-
.attr("index_value", function(d, i) { return "index-" + i; })
200-
.attr("class", function(d, i) { return "bars-" + chartID + "-legendText-index-" + i; });
201-
202-
// });//dataSet function end
203-
};//draw function end
204-
205-

web/WEB-INF/jsp/centertop.jsp

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
Author : pszgp
55
--%>
66
<div id="users_content">
7-
<h2>Current year: <y id="currentYear"></y></h2>
7+
8+
<style>
9+
body{
10+
font: 12px Verdana, sans-serif;
11+
}
12+
</style>
13+
14+
<!--h2>Current year: <y id="currentYear"></y></h2>
815
<script language="javascript">
916
document.getElementById("currentYear").innerHTML = new Date().getFullYear();
1017
</script>

web/WEB-INF/jsp/dashboard.jsp

+83-80
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,95 @@ the index of the dashboard application
44
<%@include file="header.jsp" %>
55
<%@include file="leftmenu.jsp" %>
66

7-
<div id="users_content">
8-
<h3>Welcome to the dashboard page of the Homework database.</h3>
9-
10-
<h3>Total bandwidth usage per devices:</h3>
11-
<table>
12-
<tr style="background-color: #64A0DE;""><!--th>User</th--><th>Device Name</th><th>Device Type</th><th>Device Ip</th><th>Usage(Mb)</th><th>Allowance (Mb)</th></tr>
13-
<c:set var="rowCount" value="0"/>
14-
<c:forEach var="device" items="${devices}">
15-
<c:set var="rowCount" value="${rowCount+1}"/>
16-
<c:choose>
17-
<c:when test='${(rowCount)%2 eq 0}'>
18-
<tr style="background-color: #64A0DE;">
19-
</c:when>
20-
<c:otherwise>
21-
<tr style="">
22-
</c:otherwise>
23-
</c:choose>
24-
<!--td><a href="user.htm?name=${device.user}">${device.user}</td-->
25-
<td>${device.name}</td><td>${device.type}</td>
26-
<td><a href="device.htm?ip=${device.ip}">${device.ip}</a></td>
27-
<td><fmt:formatNumber maxFractionDigits="2" minFractionDigits="2"
28-
value="${device.nbytes/(1024*1024)}"/>Mb</td><!--${device.nbytesMb}-->
29-
<!--value="${device.nbytes/(1024*1024)} = ${device.nbytesMonths}"/></td-->
30-
<td><fmt:formatNumber maxFractionDigits="2" minFractionDigits="2"
31-
value="${device.allowance/(1024*1024)}"/></td>
32-
</tr>
33-
</c:forEach>
34-
</table>
35-
<br/>
36-
37-
38-
<table>
39-
<tr style="vertical-align: top"><td>
40-
<%@include file="dashboard_stacked.jsp"%>
41-
</td>
42-
<td style="widht: 30px;"></td>
43-
<td>
44-
<h3>Total bandwidth usage per months:</h3>
45-
<c:set var="monthsNames" scope="request">JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER
46-
</c:set>
47-
<table>
48-
<tr style="background-color: #64A0DE;""><th>Month</th><th>Device</th><th>Usage (Mb)</th></tr>
7+
<script type="text/javascript" src="js/device_bars.js"> </script>
8+
9+
<script type="text/javascript" src="js/tabber.js"></script>
10+
<!-- tabs to view as table or graph; 28 aug. 2012
11+
tabber.js from: http://www.barelyfitz.com/projects/tabber/example.html -->
12+
<link rel="stylesheet" href="js/tabber/tabber.css" type="text/css" media="screen"/>
13+
<link rel="stylesheet" href="js/tabber/tabber_print.css" type="text/css" media="print"/>
14+
<style>
15+
.tabber{display: none;}
16+
body{
17+
font: 12px Verdana, sans-serif;
18+
}
19+
</style>
20+
21+
<div id="users_content">
22+
23+
<h3>Welcome to the dashboard page of the Homework database.</h3>
24+
<h4>Years considered: ${years}</h4>
25+
<h4>Total bandwidth usage per devices:</h4>
26+
27+
<div class ="tabber">
28+
<div class="tabbertab" title="Table view">
29+
<h3>Table view:</h3>
30+
<table width="400px">
31+
<tr style="background-color: #64A0DE; height: 10px;"><!--th>User</th--><th>Device Name</th><th>Device Type</th><th>Device Ip</th><th>Usage(Mb)</th><th>Allowance (Mb)</th></tr>
4932
<c:set var="rowCount" value="0"/>
50-
<c:forEach var="monthData" items="${dataMonthsDevices}">
51-
<c:forEach var="devicesMonth" items="${monthData.value}">
52-
<c:set var="containsDevice" value="false" />
53-
<c:forEach var="item" items="${devicesIps}">
54-
<c:if test="${item eq devicesMonth.key}">
55-
<c:set var="containsDevice" value="true" />
56-
</c:if>
57-
</c:forEach>
58-
<c:if test="${containsDevice==true}">
59-
<c:set var="rowCount" value="${rowCount+1}"/>
60-
<c:choose>
61-
<c:when test='${(rowCount)%2 eq 0}'>
62-
<tr style="background-color: #64A0DE;">
63-
</c:when>
64-
<c:otherwise>
65-
<tr style="">
66-
</c:otherwise>
67-
</c:choose>
68-
<td>${monthData.key}.
69-
<c:set var="mCount" value="0"></c:set>
70-
<c:forEach var="m" items="${monthsNames}">
71-
<c:set var="mCount" value="${mCount+1}"/>
72-
<c:if test="${mCount==(monthData.key)}">
73-
<c:out value="${m}"/>
74-
</c:if>
75-
</c:forEach>
76-
</td>
77-
<td>${devicesMonth.key}</td>
33+
<c:forEach var="device" items="${devices}">
34+
<c:set var="rowCount" value="${rowCount+1}"/>
35+
<c:choose>
36+
<c:when test='${(rowCount)%2 eq 0}'>
37+
<tr style="background-color: #64A0DE;">
38+
</c:when>
39+
<c:otherwise>
40+
<tr style="">
41+
</c:otherwise>
42+
</c:choose>
43+
<!--td><a href="user.htm?name=${device.user}">${device.user}</td-->
44+
<td height="10px">${device.name}</td><td>${device.type}</td>
45+
<td><a href="device.htm?ip=${device.ip}">${device.ip}</a></td>
7846
<td><fmt:formatNumber maxFractionDigits="2" minFractionDigits="2"
79-
value="${devicesMonth.value/(1024*1024)}"/>Mb
80-
</td>
81-
</tr>
82-
</c:if>
83-
</c:forEach>
47+
value="${device.nbytes/(1024*1024)}"/>Mb</td><!--${device.nbytesMb}-->
48+
<!--value="${device.nbytes/(1024*1024)} = ${device.nbytesMonths}"/></td-->
49+
<td><fmt:formatNumber maxFractionDigits="2" minFractionDigits="2"
50+
value="${device.allowance/(1024*1024)}"/></td>
51+
</tr>
8452
</c:forEach>
8553
</table>
86-
</td>
87-
</tr>
54+
</div>
55+
<!--/td>
56+
<td style="vertical-align: top;"-->
57+
<div class="tabbertab" title="Graph view">
58+
<h3>Graph view - horizontal stacked barchart:</h3>
59+
<table><tr><td height="40px;"></td></tr>
60+
<tr><td>
61+
<div class="div_RootBody" id="bar_chart_1">
62+
<div class="chart"></div>
63+
</div>
64+
<script type="text/javascript">
65+
//chartID, selectString, deviceIp, colors, values, months, devicesAll, monthName
66+
drawHorizontalBarChart("Bars1", "#bar_chart_1 .chart", "null", "colorScale10", "${devicesTotal}", false, true, "null");//dataSet
67+
</script>
68+
</td>
69+
</tr>
70+
</table>
71+
<br/>
72+
</div>
73+
74+
<div class="tabbertab" title="Months graph view">
75+
<h3>Graph view - vertical stacked barchart per months:</h3>
76+
<%@include file="dashboard_stacked.jsp" %>
77+
</div>
78+
79+
<div class="tabbertab" title="Days & hours graph view">
80+
<h3>Partition sunburst (d3) for devices usage:</h3>
81+
<br/>Move the mouse over to see the labels. <br/>
82+
Circles represent (from most inner to external): devices, years, months, days, hourly usage.<br/>
8883

89-
</table>
84+
<script type="text/javascript" src="js/d3/d3.v2.js"></script>
85+
<div id="chart"></div>
86+
<script type="text/javascript" src="js/sunburstchart/sunburstd3.js"></script>
87+
<script type="text/javascript">
88+
var file = "js/sunburstchart/devicesUsage.json";
89+
//complete data: all devices, per years, months, days, hours
90+
drawPartitionSunburst(file);
91+
</script>
9092

91-
<br/>
9293

93-
</div>
94+
</div><!-- end of the tabber -->
95+
96+
</div> <!-- end of the content -->
9497
</body>
9598
</html>

0 commit comments

Comments
 (0)