-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_scouting_output.js
56 lines (50 loc) · 1.44 KB
/
view_scouting_output.js
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
const db = require ('./scouting.js');
//displays the scouting output either for a specific event, if one is given, or across all events
async function handle_output (connection, event_code) {
await get_output(connection, event_code)
.then(output => print_output(output))
.then(() => connection.end());
}
async function get_output (connection, event_code) {
if (event_code) {
console.log("specific");
return new Promise(
(resolve, reject) =>
connection.query("SELECT * FROM specific_scouting_output sso " +
" WHERE sso.event_code = ? "+
"ORDER BY sso.team_number ",
[event_code],
(error, results) =>
(error)
? console.warn(error) || reject (error)
: resolve(results)
));
}
else {
console.log("all");
return new Promise(
(resolve, reject) =>
connection.query("SELECT * FROM all_scouting_output aso " +
" ORDER BY aso.team_number",
[],
(error, results) =>
(error)
? reject (error)
: resolve(results)
));
}
}
function print_output (output) {
for (let i = 0; i < output.length; i++) {
console.log(output[i]);
}
}
//if we're not running at the top level (ie. in the webapp) we might want to do something else with the output
if (require.main === module) {
var event_code =
(process.argv.length < 3)
? void 0
: process.argv[2];
console.log("running");
db.with_connection(connection => handle_output(connection, event_code));
}