Skip to content

Commit 6e971c5

Browse files
author
pszgp
committed
HWUIDashboard - use csv files (extracted from mysql) for devices usage graphics
1 parent b31e22c commit 6e971c5

File tree

843 files changed

+542997
-550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

843 files changed

+542997
-550
lines changed

images/linen-bg.jpg

4.05 KB
Loading

images/linen-header.jpg

3.53 KB
Loading

images/linen-red.jpg

7.11 KB
Loading

images/linen-side.jpg

5.23 KB
Loading

src/java/homework/nott/util/CSVParser.java

+681
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package homework.nott.util;
6+
7+
/**
8+
*
9+
* @author pszgp, 17 july 2012
10+
*/
11+
public class DateDeviceUsage {
12+
13+
String date = null;//day, month, or year...
14+
long nbytes=0L;//data usage for the specified date
15+
16+
public DateDeviceUsage(String date, long nbytes)
17+
{
18+
this.date = date;
19+
this.nbytes = nbytes;
20+
}
21+
22+
public String getDate() {
23+
return date;
24+
}
25+
26+
public void setDate(String date) {
27+
this.date = date;
28+
}
29+
30+
public long getNbytes() {
31+
return nbytes;
32+
}
33+
34+
public void setNbytes(long nbytes) {
35+
this.nbytes = nbytes;
36+
}
37+
38+
}
+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package homework.nott.util;
6+
7+
import java.util.ArrayList;
8+
import java.util.HashMap;
9+
import java.util.TreeMap;
10+
11+
/**
12+
*
13+
* @author pszgp, 23 april 2012
14+
*/
15+
public class Device {
16+
private String timestamp;//as date string, not unix timestamp
17+
private String ip;
18+
private String name;
19+
private String type;
20+
private String user;
21+
private long allowance;
22+
private long nbytes;
23+
private double nbytesMb;
24+
25+
public double getNbytesMb() {
26+
return (double) (nbytes / (1024 * 1024));
27+
}
28+
29+
private TreeMap<Integer,TreeMap<Integer,TreeMap<Integer,Long>>> usage;
30+
private TreeMap<Integer,TreeMap<Integer,TreeMap<Integer,Long>>> usageFlows;//from flows...
31+
//total usage, split per years, months, days using the usage map
32+
private ArrayList<TreeMap> totalUsageSplitDetails = new ArrayList();
33+
private ArrayList<TreeMap> totalUsageSplitDetailsFlows = new ArrayList();//from flows (30 april 2012)
34+
private long totalUsage;
35+
private long totalUsageFlows;
36+
private String macaddr;
37+
private HashMap<String, Long> nbytesMonths;
38+
39+
public ArrayList<TreeMap> getTotalUsageSplitDetails() {
40+
return totalUsageSplitDetails;
41+
}
42+
43+
public ArrayList<TreeMap> getTotalUsageSplitDetailsFlows() {
44+
return totalUsageSplitDetailsFlows;
45+
}
46+
//not for beans, but for use in the code
47+
public void setTotalUsageDetailsFlows(ArrayList totalUsageDetailsFlows)
48+
{
49+
this.totalUsageSplitDetailsFlows = totalUsageDetailsFlows;
50+
}
51+
52+
private String MONTHS[] = new String[]{"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
53+
"AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
54+
55+
public static String[] getMONTHs(){
56+
return new String[]{"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
57+
"AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
58+
}
59+
public static String getMONTH(int month){
60+
return getMONTHs()[month];
61+
}
62+
public static int getMONTHId(String MONTH){
63+
for (int i=0; i< getMONTHs().length; i++)
64+
{
65+
String month = getMONTHs()[i];
66+
if (month.equals(MONTH))
67+
return i;
68+
}
69+
return -1;
70+
}
71+
72+
public void setTotalUsageSplitDetails() {
73+
try{
74+
if (usage==null) return;
75+
76+
this.totalUsageSplitDetails = new ArrayList();
77+
78+
for (Integer year: usage.keySet()){
79+
TreeMap<Integer,TreeMap<Integer, Long>> yearUsage = usage.get(year);
80+
for (Integer month: yearUsage.keySet())
81+
{
82+
TreeMap<Integer,Long> monthUsage = yearUsage.get(month);
83+
for (Integer day: monthUsage.keySet()){
84+
85+
long dayUsage = monthUsage.get(day);
86+
87+
TreeMap<String,Long> mapDay = new TreeMap();
88+
String monthName = MONTHS[month];
89+
String dateName = day + " "+ monthName+" "+year;
90+
91+
mapDay.put(dateName, dayUsage);
92+
93+
this.totalUsageSplitDetails.add(mapDay);
94+
}
95+
}
96+
}
97+
}catch(Exception e){e.printStackTrace();};
98+
}
99+
100+
public void setTotalUsageSplitDetailsFlows() {
101+
try{
102+
if (usageFlows==null) return;
103+
104+
this.totalUsageSplitDetailsFlows = new ArrayList();
105+
106+
for (Integer year: usageFlows.keySet()){
107+
TreeMap<Integer,TreeMap<Integer, Long>> yearUsage = usageFlows.get(year);
108+
for (Integer month: yearUsage.keySet())
109+
{
110+
TreeMap<Integer,Long> monthUsage = yearUsage.get(month);
111+
for (Integer day: monthUsage.keySet()){
112+
113+
long dayUsage = monthUsage.get(day);
114+
115+
TreeMap<String,Long> mapDay = new TreeMap();
116+
String monthName = MONTHS[month];
117+
String dateName = day + " "+ monthName+" "+year;
118+
119+
mapDay.put(dateName, dayUsage);
120+
121+
this.totalUsageSplitDetailsFlows.add(mapDay);
122+
}
123+
}
124+
}
125+
}catch(Exception e){e.printStackTrace();};
126+
}
127+
128+
public long getAllowance() {
129+
return allowance;
130+
}
131+
132+
public void setAllowance(long allowance) {
133+
this.allowance = allowance;
134+
}
135+
136+
public long getNbytes() {
137+
return nbytes;
138+
}
139+
140+
public void setNbytes(long nbytes) {
141+
this.nbytes = nbytes;
142+
}
143+
144+
public Device(String timestamp, String ip, String name, String type, String user, long allowance, long nbytes)
145+
{
146+
this.timestamp = timestamp;
147+
this.ip = ip;
148+
this.name = name;
149+
this.type = type;
150+
this.user = user;
151+
this.allowance = allowance;
152+
this.nbytes = nbytes;
153+
}
154+
public String getTimestamp()
155+
{
156+
return this.timestamp;
157+
}
158+
public void setTimestamp(String timestamp)
159+
{
160+
this.timestamp = timestamp;
161+
}
162+
163+
public String getType() {
164+
return type;
165+
}
166+
167+
public void setType(String type) {
168+
this.type = type;
169+
}
170+
public String getIp()
171+
{
172+
return this.ip;
173+
}
174+
175+
public void setIp(String ip) {
176+
this.ip = ip;
177+
}
178+
179+
public String getUser() {
180+
return user;
181+
}
182+
183+
public void setUser(String user) {
184+
this.user = user;
185+
}
186+
187+
public void setName(String name) {
188+
this.name = name;
189+
}
190+
191+
public String getName() {
192+
return name;
193+
}
194+
195+
public String toString(){
196+
return "Device=[timestamp:"+timestamp+";ip:"+ip+";name:"+name+";type:"+type+";user:"+user+";allowance="+allowance+";usage="+nbytes+"]";
197+
}
198+
199+
public void setUsage(TreeMap<Integer, TreeMap<Integer, TreeMap<Integer, Long>>> usage) {
200+
this.usage = new TreeMap(usage);
201+
this.setTotalUsageSplitDetails();
202+
}
203+
204+
public void setUsageFlows(TreeMap<Integer, TreeMap<Integer, TreeMap<Integer, Long>>> usage) {
205+
this.usageFlows = new TreeMap(usage);
206+
this.setTotalUsageSplitDetailsFlows();
207+
}
208+
209+
public TreeMap getUsage()
210+
{
211+
return this.usage;
212+
}
213+
214+
public TreeMap getUsageFlows()
215+
{
216+
return this.usage;
217+
}
218+
public void setTotalUsage(long totalUsage) {
219+
this.totalUsage = totalUsage;
220+
}
221+
public long getTotalUsage()
222+
{
223+
return this.totalUsage;
224+
}
225+
226+
public void setTotalUsageFlows(long totalUsage) {
227+
this.totalUsageFlows = totalUsageFlows;
228+
}
229+
public long getTotalUsageFlows()
230+
{
231+
return this.totalUsageFlows;
232+
}
233+
234+
public String getMacaddr() {
235+
return this.macaddr;
236+
}
237+
238+
public void setMacaddr(String macaddr) {
239+
this.macaddr = macaddr;
240+
}
241+
242+
public void setNbytesMonths(HashMap<String, Long> nbytesMonths) {
243+
this.nbytesMonths = new HashMap(nbytesMonths);
244+
}
245+
public HashMap<String, Long> getNbytesMonths() {
246+
return this.nbytesMonths;
247+
}
248+
249+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package homework.nott.util;
6+
7+
import java.sql.Timestamp;
8+
9+
/**
10+
*
11+
* @author pszgp, 12 july 2012, replace the Device class, add the downloaded/uploaded nbytes
12+
*/
13+
class DeviceData {
14+
private final String ip;
15+
private final int day;
16+
private final int month;
17+
private final int year;
18+
private final Timestamp tstamp;
19+
private final int nbytesDownload;
20+
private final int nbytesMb;
21+
private final int nbytesDownloadMb;
22+
private final int nbytsUpload;
23+
private final int nbytsUploadMb;
24+
private final int nbytes;
25+
private final int hour;
26+
27+
DeviceData(String ip, int hour, int day, int month, int year, Timestamp t, int nbytesDownload, int nbytesUpload, int nbytes) {
28+
this.ip = ip;
29+
this.hour = hour;
30+
this.day = day;
31+
this.month = month;
32+
this.year = year;
33+
this.tstamp = t;
34+
this.nbytesDownload = nbytesDownload;
35+
this.nbytesDownloadMb = nbytesDownload/(1024*1024);
36+
this.nbytsUpload = nbytesUpload;
37+
this.nbytsUploadMb = nbytesUpload/(1024*1024);
38+
this.nbytes = nbytes;
39+
this.nbytesMb = nbytes/(1024*1024);
40+
}
41+
42+
}

0 commit comments

Comments
 (0)