Skip to content

Commit

Permalink
Recovering Files
Browse files Browse the repository at this point in the history
  • Loading branch information
clj13001 committed Apr 7, 2017
1 parent 8c4f20b commit 0963edf
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 1 deletion.
1 change: 0 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Users/conno/opt/pivotal/pivotal-tc-server-standard-3.2.1.RELEASE/tomcat-7.0.72.A.RELEASE/lib/servlet-api.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
67 changes: 67 additions & 0 deletions WebContent/html/javascript/statistics.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<%@ page import = "database.*,entities.Statistics" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Statistics[] genStatistics = StatisticsQueries.getStatistics();
String statString = Statistics.arrayToString(genStatistics);
%>
<script type=text/javascript src="https://www.gstatic.com/charts/loader.js">
var stats = makeStatistics();
displayData();
function displayData() {
var html = "";
var totalDevices;
var availableDevices;
var loanDevices;
var lostDevices;
if (statistics.status != "" && statistics.count != ""){
for (var i = 0; i<statistics.length; i++){
totalDevices = totalDevices + statistics.count;
}
availableDevices = statistics[1].count;
loanDevices = statistics[5].count;
lostDevices = statistics[4].count;
html += '<div class = "info-container">Total Devices: '+ totalDevices +
'<br>Loaned Devices: ' + loanDevices +
'<br>Available Devices: ' + availableDevices +
'<br>Lost Devices: ' + lostDevices +
'</div>'
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Status');
data.addColumn('number', 'Count');
data.addRows(9);
for (var i = 0; i<statistics.length; i++){
data.setCell(i, 0, statistics[i].status);
data.setCell(i, 1, statistics[i].count);
}
// Set chart options
var options = {'title':'Devices in terms of Status',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
document.getElementById('map').innerHTML = html;
}
}
function makeStatistics(){
window.json = '<%=statString%>';
return JSON.parse(window.json);
}
</script>
</body>
</html>
46 changes: 46 additions & 0 deletions WebContent/html/webpages/statisticsPage.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">

<title>Synchrony Financial</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<link rel = "stylesheet" type = "text/css" href = "../css/stylesheet.css">
<link rel = "shortcut icon" href = "../imgs/synchrony-financial-logo-dlpx_1.ico">
<style>
div.infoContainer{
border: solid;
border-width: thin;
padding: 15px;
background-color: #E9EAEB;
display: inline-block;
}
div.imgContainer{
display: inline-block;
text-align: center;
}
div.statDescription{
display: inline-block;
width: 200px;
text-align: center;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="navbar.html"%>
</nav>
<div id="map"></div>
<%@ include file="../javascript/statistics.jsp" %>
</body>
</html>
36 changes: 36 additions & 0 deletions src/database/StatisticsQueries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package database;
import java.sql.*;
import entities.Statistics;

public class StatisticsQueries {

private static String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317";
private static String user = "b372dfe7409692";
private static String password = "74f6e317";

public static Statistics[] getStatistics() 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 Status, count(*) FROM devices GROUP BY Status");
int counter = 0;

resultSet.last();
int rows = resultSet.getRow();
resultSet.beforeFirst();

Statistics[] statusDevice = new Statistics[rows];
//iterate result set
while(resultSet.next()){
statusDevice[counter] = new Statistics(resultSet.getString("Status"), resultSet.getInt("count(*)"));
counter++;
}
stmt.close();
connection.close();
return statusDevice;

}

}
42 changes: 42 additions & 0 deletions src/entities/Statistics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package entities;

public class Statistics {
private String _status;
private int _count;
public Statistics(String status,int count) {
_status = status;
_count = count;
}

/**
* Formatting the statistics to fit a JSON object.
* @author - Connor
*/
public String toString(){
StringBuilder sb = new StringBuilder();
String comma = ", ";
sb.append("{\"status\": \"").append(_status).append("\"").append(comma);
sb.append("\"count\": \"").append(_count).append("\"");
sb.append("}");
return sb.toString();
}

/**
* This is a static function which will turn a Listed Statistics array into its proper string. (modification)
* @author - Connor
* @param array
* @return
*/
public static String arrayToString(Statistics[] array){
StringBuilder sb = new StringBuilder();
sb.append("[");
for(int i = 0; i < array.length; i++){
sb.append(array[i].toString());
if(i+1 != array.length){
sb.append(",");
}
}
sb.append("]");
return sb.toString();
}
}

0 comments on commit 0963edf

Please sign in to comment.