This repository was archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.php
More file actions
284 lines (243 loc) · 8.16 KB
/
Copy pathclasses.php
File metadata and controls
284 lines (243 loc) · 8.16 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
#Shared Class File
#Basic database interaction class
class database
{
#initialize variables. These are later changed in settings.php
static protected $dbuser = 'scoutinguser';
static protected $dbpassword = 'hunter3';
#Do Not Set to localhost, does not work in all environments
static protected $dbhost = 'dbztech.com';
static protected $database = 'scouting2013';
static protected $prefix = '';
public static function setcredentials($user, $password, $host = '127.0.0.1', $db = 'scouting2013', $pre = '') {
// property declaration
$result = 'Credential(s) not set: ';
$error = 0;
if (is_string($user)) {
database::$dbuser = $user;
} else {
$error = 1;
$result .= '$dbuser ';
}
if (is_string($password)) {
database::$dbpassword = $password;
} else {
$error = 1;
$result .= '$dbpassword ';
}
if (!$error) {
database::$dbhost = $host;
database::$database = $db;
database::$prefix = $pre;
$result = 'Success!';
} else {
$result = 'Error!';
}
return $result;
}
public static function sqlconn() {
try {
$dbh = new PDO('mysql:host='.database::$dbhost.';dbname='.database::$database, database::$dbuser, database::$dbpassword);
}
catch (PDOException $e) {
print ("Could not connect to server.n");
die ("getMessage(): " . $e->getMessage () . "n");
}
return $dbh;
}
// method declaration
public static function info() {
echo "Database: ".database::$database."<br />";
echo "Database User: ".database::$dbuser."<br />";
echo "Database Host: ".database::$dbhost."<br />";
echo "Database Prefix: ".database::$prefix."<br />";
}
public static function test() {
$dbh = database::sqlconn();
if ($dbh) {
echo "Connection Successful!";
return true;
$dbh = NULL;
}
else {
return false;
}
}
public static function returndata($query) {
$dbh = database::sqlconn();
// Perform Query
$result = $dbh->query ($query);
if ($result) {
while ($row = $result->fetch()) {
return($row);
}
}
$dbh = NULL;
}
public static function returnmultiplerows($query) {
$dbh = database::sqlconn();
$result = $dbh->query ($query);
if ($result) {
return $result->fetchAll();
}
$dbh = NULL;
}
public static function countRows($query) {
$dbh = database::sqlconn();
$result = $dbh->query ($query);
if ($result) {
return count($result->fetchAll());
}
$dbh = NULL;
}
public static function writedata($query) {
$dbh = database::sqlconn();
// Perform Query
try {
$result = $dbh->exec ($query);
}
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
catch (PDOException $e) {
print ("Could not connect to server.n");
die ("getMessage(): " . $e->getMessage () . "n");
}
return("Query Successful");
$dbh = NULL;
}
}
class analytics
{
public static $event = "";
public static function countArray($array) {
}
public static function averageArray($array) {
}
public static function getEventList() {
$sql = "SELECT `Event` FROM `matchdata` WHERE 1";
$data = database::returnmultiplerows($sql);
$list = array();
foreach ($data as $nextlevel) {
foreach ($nextlevel as $event) {
#echo $event;
array_push($list, $event);
}
}
$output = array_unique($list);
$output = str_replace("#", "", $output);
sort($output);
return $output;
}
public static function formatEvents() {
$data = analytics::getEventList();
echo '<select id="eventSelector">';
echo '<option value="All">All</option>';
foreach ($data as $event) {
echo '<option value="'.$event.'">'.$event."</option>";
}
echo "</select>";
}
public static function getAlliance($alliance) {
$data = explode("_", $alliance);
analytics::display("team", $data[0]);
analytics::display("team", $data[1]);
analytics::display("team", $data[2]);
}
public static function getTeam($number) {
$matches = analytics::getTeamMatches($number);
$teamdata = analytics::getTeamData($number);
$flags = "None";
$won = 0;
$lost = 0;
$tied = 0;
foreach ($matches as $row) {
if ($row[3] == $row[4]) {
#Tie
$tied++;
} elseif ($row[3] > $row[4]) {
#Red win
if ($row[5] == $number) {
$won++;
} elseif ($row[6] == $number) {
$won++;
} elseif ($row[7] == $number) {
$won++;
} else {
$lost++;
}
} elseif ($row[3] < $row[4]) {
#Blue win
if ($row[5] == $number) {
$lost++;
} elseif ($row[6] == $number) {
$lost++;
} elseif ($row[7] == $number) {
$lost++;
} else {
$won++;
}
}
}
$pct = round((($won/($lost+$won+$tied))*100));
$data = Array($won, $lost, $tied, $pct, $matches, $teamdata, $flags);
//print_r($data);
return $data;
}
public static function getMatch($event, $type, $number) {
if ($event == 'All') {
analytics::$event = "";
} else {
analytics::$event = "`Event` = '#".$event."' AND ";
}
#SELECT * FROM `matchdata` WHERE `Event` = "#FRCCAMA" AND `MatchType` = "Q" AND `MatchNumber` = 6
$sql = "SELECT * FROM `matchdata` WHERE ".analytics::$event." `MatchType` = '".$type."' AND `MatchNumber` = ".$number." ORDER BY `MatchType` DESC , `MatchNumber` DESC";
#echo $sql;
$response = database::returnmultiplerows($sql);
return $response;
}
public static function getStat($db,$cond) {
}
public static function getTeamData($number) {
#SELECT * FROM `teamdata` WHERE `TeamNumber` = 1234
$sql = "SELECT * FROM `teamdata` WHERE ".analytics::$event." `TeamNumber` = ".$number." ORDER BY `Event` DESC , `MatchType` DESC , `MatchNumber` DESC";
//echo $sql;
$response = database::returnmultiplerows($sql);
return $response;
}
public static function getTeamMatches($number) {
#SELECT * FROM `matchdata` WHERE `Red1` = 701 OR `Red2` = 701 OR `Red3` = 701 OR `Blue1` = 701 OR `Blue2` = 701 OR `Blue3` = 701
$sql = "SELECT * FROM `matchdata` WHERE `MatchType` != '' AND ".analytics::$event." (`Red1` = ".$number." OR `Red2` = ".$number." OR `Red3` = ".$number." OR `Blue1` = ".$number." OR `Blue2` = ".$number." OR `Blue3` = ".$number.") ORDER BY `Event` DESC , `MatchType` DESC , `MatchNumber` DESC";
//echo $sql;
$response = database::returnmultiplerows($sql);
return $response;
}
public static function display($view, $detail) {
$filename = '../Views/'.$view.'.php';
//echo $filename.' ';
//echo "current working directory is -> ". getcwd().'<br /><br />';
//include('Views/'.$view.'.php');
if (file_exists($filename)) {
include($filename);
}
// if ($view == "event") {
// include '/Views/event.php';
// } elseif ($view == "team") {
// include 'Views/team.php';
// } elseif ($view == "match") {
// include 'Views/match.php';
// } elseif ($view == "stat") {
// include 'Views/stat.php';
// } elseif ($view == "trends") {
// include 'Views/trends.php'
// } elseif ($view == "leaderboards") {
// include 'Views/leaderboards.php';
// }
elseif ($view == "alliance") {
analytics::getAlliance($detail);
} else {
echo "Invalid";
}
}
}
?>