-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
241 lines (197 loc) · 6.89 KB
/
index.php
File metadata and controls
241 lines (197 loc) · 6.89 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script src="https://static.fusioncharts.com/code/latest/fusioncharts.charts.js"></script>
<script src="https://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css" title="css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
<title>Cerulean Connect</title>
</head>
<body>
<header>
<img src="Cascade_Badge.png" width="200" height ="150" alt="Badge of Cerulean City" class="animated infinite pulse faster delay-2s" />
<h2 class="animated infinite heartBeat slow delay-2s">Cerulean Connect</h2>
<h2 class="animated infinite heartBeat slow delay-2s">LIMITED TIME FREE POWER USER FOR ALL</h2>
<h4> And when everyone is super, no one will be</h4>
</header>
<ul>
<li><a class="active" href="index.php">Home</a></li>
<li><a href="workoutRepository.html">Workout Repository</a></li>
<li><a href="newWorkout.html">New Workout</a></li>
</ul>
<h2 align="center">Workout Statistics</h2>
<?php // Connect to the database
$conn = pg_connect("host=localhost port=5432 dbname=CeruleanConnect user=student password=CompSci364")
or die("Could not connect");
$status = pg_connection_status($conn);
if ($status !== PGSQL_CONNECTION_OK)
{
echo pg_last_error($dbconn);
exit;
}
$avgDist = "?";
$avgHR = "?";
$daysActive = "?";
$result = pg_query($conn, "SELECT AVG(distance) FROM workouts");
if (!$result) {
echo "An error occurred.\n";
exit;
}
$avgDist = number_format(pg_fetch_result($result, 0, 0), 2, '.', '');
$result = pg_query($conn, "SELECT AVG(avghr) FROM workouts");
if (!$result) {
echo "An error occurred.\n";
exit;
}
$avgHR = number_format(pg_fetch_result($result, 0, 0), 2, '.', '');
//start at today
$temp = date("Y-m-d");
$curDate = strval($temp);
$exists = 1;
$daysActive = 0;
$result = pg_prepare($conn, "dateC", 'SELECT DISTINCT CAST(dateperformed AS date) FROM workouts WHERE CAST(dateperformed AS date) = $1 ORDER BY dateperformed');
while($exists > 0){
$exists = 0;
$result = pg_execute($conn, "dateC", array($curDate));
//echo pg_query($conn, "SELECT COUNT(dateperformed) FROM workouts WHERE dateperformed = .$curDate.");
if (!$result) {
echo "An error occurred.\n";
exit;
}
$row = NULL;
while($row = pg_fetch_array($result)){
$daysActive = $daysActive + 1;
$temp = date_sub(DateTime::createFromFormat('Y-m-d', $curDate), date_interval_create_from_date_string('1 day'));
$curDate = date_format($temp, "Y-m-d");
$exists = 1;
}
}
pg_close($conn);
echo '<table style="width:100%">
<tr>
<th style ="text-align: left">Statistics</th>
<th style ="text-align: left">Results</th>
</tr>
<tr>
<td style ="text-align: left">Average Distance YTD</td>
<td style ="text-align: left">'.$avgDist.' Miles</td>
</tr>
<tr>
<td style ="text-align: left">Average HR YTD</td>
<td style ="text-align: left">'.$avgHR.' bpm</td>
</tr>
<tr>
<td style ="text-align: left">Days Active in a Row</a></td>
<td style ="text-align: left">'.$daysActive.' days</td>
</tr>
</table>';
?>
<hr/>
<?php
// including FusionCharts PHP wrapper
include("./fusioncharts.php");
// establishing DB connection
$host= "host=localhost";
// add values for below variables according to your system
$port= "port=5432";
$dbname="dbname=CeruleanConnect";
$dbuser="user=student";
$dbpwd="password=CompSci364";
// connection string (pg_connect() is native PHP method for Postgres)
$dbconn=pg_connect("$host $port $dbname $dbuser $dbpwd");
// validating DB connection
if(!$dbconn) {
echo "An error occurred.\n";
exit("There was an error establishing database connection");
}
?>
<?php
$result = pg_query($dbconn, "SELECT
users.firstname,
SUM(workouts.distance) as \"quotes\"
FROM
public.users,
public.workouts
WHERE
users.userid = workouts.userid
GROUP BY users.firstname
ORDER BY quotes;");
if (!$result) {
echo "An error occurred.\n";
exit;
}
if ($result) {
// creating an associative array to store the chart attributes
$arrData = array(
"chart" => array(
// caption and sub-caption customization
"caption"=> "Total Milage per User",
"captionFontSize"=> "24",
"xAxisName"=> "User ID",
"yAxisName"=> "Distance (In Miles)",
"captionFontColor"=> "#4D394B",
"captionPadding"=> "20",
// font and text size customization
"baseFont"=> "Merriweather, sans-serif",
"baseFontColor"=> "#000000",
"outCnvBaseColor"=> "#FFFFFF",
"baseFontSize"=> "15",
"outCnvBaseFontSize"=> "15",
// div line customization
"divLineColor"=> "#ABA39D",
"divLineAlpha"=> "22",
"numDivLines"=> "5",
// y-axis scale customization
"yAxisMinValue"=> "0",
"yAxisMaxValue"=> "600",
// tool-tip customization
"toolTipBorderColor"=> "#ABA8B7",
"toolTipBgColor"=> "#FFFFFF",
"toolTipPadding"=> "13",
"toolTipAlpha"=> "50",
"toolTipBorderThickness"=> "2",
"toolTipBorderAlpha"=> "30",
"toolTipColor"=> "#4D394B",
"plotToolText"=> "<div style='text-align: center; line-height: 1.5;'>\$label<br>\$value COUNT(activityType)<div>",
// other customizations
"theme"=> "fint",
"paletteColors"=> "#666666",
"showBorder"=> "0",
"bgColor"=> "#FFFFFF",
"canvasBgColor"=> "#FFFFFF",
"bgAlpha"=> "100",
"showValues"=> "0",
"formatNumberScale"=> "0",
"plotSpacePercent"=> "33",
"showcanvasborder"=> "0",
"showPlotBorder"=> "0"
)
);
$arrData["data"] = array();
// iterating over each data and pushing it into $arrData array
while($row = pg_fetch_array($result)) {
array_push($arrData["data"], array(
"label" => $row["0"],
"value" => $row["1"]
)
);
}
$jsonEncodedData = json_encode($arrData);
// creating FusionCharts instance
$postgresChart = new FusionCharts("column3d", "ActivityGraphChart" , '100%', '450', "postgres-chart", "json", $jsonEncodedData);
// FusionCharts render method
$postgresChart->render();
// closing database connection
pg_close($dbconn);
}
?>
<!-- creating chart container -->
<center><div id="postgres-chart">A beautiful chart is on its way!</div></center>
</body>
<footer>
<a href="https://usafa-compsci364.github.io/Spring2020/assignments/project/website.html">Project Webpage Assignment</a>
</footer>
</body>
</html>