From 7299dbfe252e8cec037032670058f1bbb0424eff Mon Sep 17 00:00:00 2001 From: John Costa Date: Sun, 23 Apr 2017 23:09:15 -0400 Subject: [PATCH] completed final three charts, added filtering for other category --- WebContent/html/javascript/statistics.jsp | 131 ++++++++++++++++++-- WebContent/html/webpages/statisticsPage.jsp | 8 +- src/database/StatisticsQueries.java | 31 ++++- src/entities/Statistics.java | 5 +- 4 files changed, 161 insertions(+), 14 deletions(-) diff --git a/WebContent/html/javascript/statistics.jsp b/WebContent/html/javascript/statistics.jsp index c84980b..47bd52f 100644 --- a/WebContent/html/javascript/statistics.jsp +++ b/WebContent/html/javascript/statistics.jsp @@ -18,12 +18,16 @@ String locString = Statistics.arrayToString(genLocations); //device type queries Statistics[] genTypes = StatisticsQueries.getDeviceTypes(); String typeString = Statistics.arrayToString(genTypes); +// device manufacturer queries +Statistics[] genManu = StatisticsQueries.getDeviceManu(); +String manuString = Statistics.arrayToString(genManu); %> diff --git a/WebContent/html/webpages/statisticsPage.jsp b/WebContent/html/webpages/statisticsPage.jsp index 79645de..f6cdf5c 100644 --- a/WebContent/html/webpages/statisticsPage.jsp +++ b/WebContent/html/webpages/statisticsPage.jsp @@ -75,9 +75,13 @@


-
-
+
+


+
+
+

+
diff --git a/src/database/StatisticsQueries.java b/src/database/StatisticsQueries.java index 5ddd565..476a2d1 100644 --- a/src/database/StatisticsQueries.java +++ b/src/database/StatisticsQueries.java @@ -24,7 +24,7 @@ public static Statistics[] getStatistics() throws ClassNotFoundException, SQLExc Statistics[] statusDevice = new Statistics[rows]; //iterate result set while(resultSet.next()){ - statusDevice[counter] = new Statistics(resultSet.getString("Status"), null, resultSet.getInt("count(*)"), null, null); + statusDevice[counter] = new Statistics(resultSet.getString("Status"), null, null, resultSet.getInt("count(*)"), null, null); counter++; } stmt.close(); @@ -47,7 +47,7 @@ public static Statistics[] getLocations() throws ClassNotFoundException, SQLExce Statistics[] locations = new Statistics[rows]; //iterate result set while(resultSet.next()){ - locations[counter] = new Statistics(null, null, 0, resultSet.getString("Latitude"), resultSet.getString("Longitude")); + locations[counter] = new Statistics(null, null, null, 0, resultSet.getString("Latitude"), resultSet.getString("Longitude")); counter++; } stmt.close(); @@ -71,7 +71,7 @@ public static Statistics[] getDeviceTypes() throws ClassNotFoundException, SQLEx Statistics[] typeDevice = new Statistics[rows]; //iterate result set while(resultSet.next()){ - typeDevice[counter] = new Statistics(null, resultSet.getString("Hardware"), resultSet.getInt("count(*)"), null, null); + typeDevice[counter] = new Statistics(null, resultSet.getString("Hardware"), null, resultSet.getInt("count(*)"), null, null); counter++; } stmt.close(); @@ -79,4 +79,29 @@ public static Statistics[] getDeviceTypes() throws ClassNotFoundException, SQLEx return typeDevice; } + + public static Statistics[] getDeviceManu() throws ClassNotFoundException, SQLException { + //database connect + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection = DriverManager.getConnection(database, user, password); + Statement stmt = connection.createStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT Manufacturer, count(*) FROM devices GROUP BY Manufacturer"); + int counter = 0; + + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + + Statistics[] manuType = new Statistics[rows]; + //iterate result set + while(resultSet.next()){ + manuType[counter] = new Statistics(null, null, resultSet.getString("Manufacturer"), resultSet.getInt("count(*)"), null, null); + counter++; + } + stmt.close(); + connection.close(); + return manuType; + + } } diff --git a/src/entities/Statistics.java b/src/entities/Statistics.java index 6c0e99a..0666042 100644 --- a/src/entities/Statistics.java +++ b/src/entities/Statistics.java @@ -3,13 +3,15 @@ public class Statistics { private String _status; private String _type; + private String _manu; private int _count; private String _latitude; private String _longitude; - public Statistics(String status,String type, int count, String latitude, String longitude) { + public Statistics(String status,String type, String manu, int count, String latitude, String longitude) { _status = status; _type = type; + _manu = manu; _count = count; _latitude = latitude; _longitude = longitude; @@ -24,6 +26,7 @@ public String toString(){ String comma = ", "; sb.append("{\"status\": \"").append(_status).append("\"").append(comma); sb.append("\"type\": \"").append(_type).append("\"").append(comma); + sb.append("\"manu\": \"").append(_manu).append("\"").append(comma); sb.append("\"count\": ").append(_count).append(comma); sb.append("\"lat\": \"").append(_latitude).append("\"").append(comma); sb.append("\"lng\": \"").append(_longitude).append("\"");