Skip to content

Commit

Permalink
Calgames 2023 Changes (#8)
Browse files Browse the repository at this point in the history
new score weighting options
counts more details of the grid
verify contents of cycle time
  • Loading branch information
JayAgra authored Oct 11, 2023
1 parent 146f6c3 commit 8fe9f98
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 135 deletions.
297 changes: 217 additions & 80 deletions routes/2023.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion routes/api/casino/plinko/endGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function endGame(req, res, db, casinoToken) {
res.status(500).send("" + 0x1f41);
return;
} else {
if (crypto.createHash('sha1').update(casinoToken + req.user.id + dbQueryResult.score).digest('hex') == req.params.token && req.params.pts <= 75) {
if (crypto.createHash('sha1').update(casinoToken + req.user.id + dbQueryResult.score).digest('hex') == req.params.token && req.params.pts <= 10) {
let pointStmt = `UPDATE scouts SET score = score + ? WHERE discordID=?`;
let pointValues = [req.params.pts, req.user.id];
db.run(pointStmt, pointValues, (err) => {
Expand Down
2 changes: 1 addition & 1 deletion routes/api/events/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function teams(req, res, frcapi, season) {
}
});
} else {
res.status(200).send("8,100,115,199,253,581,670,766,840,841,846,852,1072,1700,1868,2473,2489,2643,2813,3045,3256,4186,4765,4904,4990,5026,5027,5419,5430,6036,6059,6418,6962,7245,7777,8033,8048,8404,9114,9143,9400");
res.status(200).send("8,100,115,199,253,581,670,766,840,841,846,852,1072,1700,1868,2473,2489,2643,2813,3045,3256,4186,4765,4904,4990,5026,5027,5419,5430,6036,6059,6418,6962,7245,7777,8033,8048,8404,9114,9143,9400,9900");
}
}

Expand Down
25 changes: 3 additions & 22 deletions routes/api/teams.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const sanitize = require("sanitize-filename");

function teams(req, res, db, season) {
if (req.params.event) {
const stmt = `SELECT team, AVG(weight) FROM main WHERE event=? AND season=? GROUP BY team ORDER BY AVG(weight) DESC`;
const requestedEvent = sanitize(req.params.event);
const values = [requestedEvent, season];
const stmt = `SELECT team, weight FROM main WHERE event=? AND season=?`;
const values = [req.params.event, season];
db.all(stmt, values, (err, dbQueryResult) => {
if (err) {
res.status(500).send("" + 0x1f41);
Expand All @@ -13,23 +10,7 @@ function teams(req, res, db, season) {
if (typeof dbQueryResult == "undefined") {
res.status(204).send("" + 0xcc1);
} else {
var htmltable = ``;
for (var i = 0; i < dbQueryResult.length; i++) {
htmltable =
htmltable +
`<tr><td>${i + 1}</td><td><a href="/browse?number=${
dbQueryResult[i]["team"]
}&type=team&event=${requestedEvent}" style="all: unset; color: #2997FF; text-decoration: none;">${
dbQueryResult[i]["team"]
}</a></td><td>${Math.round(
dbQueryResult[i]["AVG(weight)"]
)}%</td><td><progress id="scoreWt" max="100" value="${
dbQueryResult[i]["AVG(weight)"]
}"></progress></td>`;
}
res.status(200)
.setHeader("Content-type", "text/plain")
.send(htmltable);
res.status(200).json(dbQueryResult);
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,13 @@ app.get("/float.min.css", (req, res) => {
// font file
app.get("/fonts/Raleway-300.ttf", (req, res) => {
res.set("Cache-control", "public, max-age=7776000");
res.sendFile("./src/fonts/Raleway-300.ttf", { root: __dirname });
res.sendFile("./src/css/Raleway-300.ttf", { root: __dirname });
});

// font file
app.get("/fonts/Raleway-500.ttf", (req, res) => {
res.set("Cache-control", "public, max-age=7776000");
res.sendFile("./src/fonts/Raleway-500.ttf", { root: __dirname });
res.sendFile("./src/css/Raleway-500.ttf", { root: __dirname });
});

// JS for form (should be unused in favor of minified js)
Expand All @@ -398,7 +398,7 @@ app.get("/form.js", (req, res) => {
// minified JS for form
app.get("/form.min.js", (req, res) => {
res.set("Cache-control", "public, max-age=7776000");
res.sendFile("./src/form.min.js", { root: __dirname });
res.sendFile("./src/js/form.min.js", { root: __dirname });
});

// favicon
Expand Down
16 changes: 8 additions & 8 deletions src/assets/plinko.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ function result() {
"5",
"5",
"5",
"10",
"10",
"10",
"15",
"15",
"20",
"50",
"75",
"1",
"1",
"1",
"1",
"1",
"2",
"5",
"7",
])
.slice(0, 9)
.map((item, index) => {
Expand Down
30 changes: 23 additions & 7 deletions src/browse.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,36 @@
<div style="overflow-x: auto; width: 95vw;">
<table>
<tr>
<th>Match Number</th>
<th rowspan="2">Match Number</th>
<th>Auto Score</th>
<th>Auto Charge</th>
<th rowspan="2">Auto Charge</th>
<th>Teleop Score</th>
<th>Teleop Charge</th>
<th>Grid Points</th>
<th>Cycle Time</th>
<th>Match Performance Score</th>
<th rowspan="2">Teleop Charge</th>
<th rowspan="2">Grid Points</th>
<th colspan="3">Cubes</th>
<th colspan="3">Cones</th>
<th colspan="3">Total</th>
<th rowspan="2">Cycle Time</th>
<th rowspan="2">Match Performance Score</th>
</tr>
<tr>
<th>B/M/T</th>
<th>B/M/T</th>
<th>Low</th>
<th>Mid</th>
<th>High</th>
<th>Low</th>
<th>Mid</th>
<th>High</th>
<th>Low</th>
<th>Mid</th>
<th>High</th>
</tr>
<%- resultsBody %>
</table>
</div>
<!--buttons-->
<button type="button" style="color: #000; background-color: #FFB600; border-radius: 0.5rem; border-style: solid; border-color: #FFB600; border-width: 0.875rem; margin-top: 1rem;" onclick="removeURLParams()">New Search</button>&emsp;<button type="button" style="color: #000; background-color: #FFB600; border-radius: 0.5rem; border-style: solid; border-color: #FFB600; border-width: 0.875rem; margin-top: 1rem;" onclick="goToHome()">Back</button>
<button type="button" style="color: #000; background-color: #FFB600; border-radius: 0.5rem; border-style: solid; border-color: #FFB600; border-width: 0.875rem; margin-top: 1rem;" onclick="removeURLParams()">New Search</button>&emsp;<button type="button" style="color: #000; background-color: #FFB600; border-radius: 0.5rem; border-style: solid; border-color: #FFB600; border-width: 0.875rem; margin-top: 1rem;" onclick="goToHome()">Home</button>
<br><br>
<small style="text-align: center;">To see robot images from pit scouting, go <a href="pitimages" style="all: unset; color: #68C3E2;">here</a></small>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/js/main_form_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ document.getElementById('validateTeamInput').addEventListener('input', function(
}
});

document.getElementById('validateLength').addEventListener('input', function(event){
console.log("event!")
if ((document.getElementById('validateLength').value).length <= 4) {
document.getElementById('validateLength').addEventListener('input', () => {
let currentVal = document.getElementById("validateLength").value;
if (currentVal <= 120 && currentVal >= 0) {
document.getElementById('tooLong').style.display = "none";
document.getElementById('submitButton').removeAttribute("disabled");
submitButton.removeAttribute("disabled");
} else {
document.getElementById('tooLong').style.display = "inherit";
document.getElementById('submitButton').setAttribute("disabled", "disabled");
submitButton.setAttribute("disabled", "disabled");
}
});
//end data validation
Expand Down
2 changes: 1 addition & 1 deletion src/js/main_form_client.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 25 additions & 3 deletions src/js/teams_client.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
function addProperty(object, property, amount) {
if (object[property] !== undefined) {
object[property] += amount;
} else {
object[property] = 0;
addProperty(object, property, amount);
}
}
const waitMs = ms => new Promise(res => setTimeout(res, ms));
function goToHome() {
window.location.href = "/";
}
async function getTeamRanks() {
eventCode = document.getElementById("eventCode").value
const eventCode = document.getElementById("eventCode").value;
const weight = Number(document.getElementById("weightType").value);
document.getElementById("viewTeamsButton").innerText = "Requesting Data...";
const xhr = new XMLHttpRequest();
xhr.open("GET", `/api/teams/2023/${eventCode}`, true);
Expand All @@ -12,10 +21,23 @@ async function getTeamRanks() {
xhr.onreadystatechange = async () => {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
document.getElementById("viewTeamsButton").innerText = "Rendering View...";
document.getElementById("preInsert").insertAdjacentHTML("afterend", xhr.responseText)
var teams = {};
var teamsCount = {};
JSON.parse(xhr.responseText).forEach((e) => {
addProperty(teams, e.team, Number(e.weight.split(",")[Number(weight)]));
addProperty(teamsCount, e.team, 1);
});
for (let team in teams) {
teams[team] /= teamsCount[team];
}
var htmltable = ``;
Object.entries(teams).sort((a, b) => b[1] - a[1]).forEach((e, i, a) => {
htmltable += `<tr><td>${i + 1}</td><td><a href="/browse?number=${e[0]}&type=team&event=${eventCode}" style="all: unset; color: #2997FF; text-decoration: none;">${e[0]}</a></td><td>${Math.round(e[1])}%</td><td><progress id="scoreWt" max="${a[0][1]}" value="${Math.round(e[1])}"></progress></td>`;
});
document.getElementById("preInsert").insertAdjacentHTML("afterend", htmltable)
document.getElementById("search").style.display = "none";
document.getElementById("results").style.display = "flex";
document.getElementById("eventCodeDisplay").innerText = `Top teams at ${eventCode}`;
document.getElementById("eventCodeDisplay").innerText = `Top teams at ${eventCode}<br>${document.getElementById("weightType").selectedOptions[0].innerText}`;
document.getElementById("viewTeamsButton").innerText = "View";
} else if (xhr.status === 401 || xhr.status === 403) {
window.location.href = "/login";
Expand Down
Loading

0 comments on commit 8fe9f98

Please sign in to comment.