Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview #1

Merged
merged 29 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b46fb91
this might work, this might not
snaapsh0t12 Jan 8, 2023
5d5fefc
Merge branch 'jmelancon:main' into preview
TooneyTurkey Jan 8, 2023
25c35f0
index.html
TooneyTurkey Jan 8, 2023
cca22d7
adapted to new season
TooneyTurkey Jan 8, 2023
c35cfed
vocabulary updates
TooneyTurkey Jan 8, 2023
5cfbc28
made more phone-freindly and generally apeasing in the robot specs area
TooneyTurkey Jan 8, 2023
90c56d5
Create CNAME
TooneyTurkey Jan 8, 2023
946c23c
added a work in progress new line function to be used for formating
TooneyTurkey Jan 9, 2023
f4d8f70
stratagy 💀
snaapsh0t12 Jan 10, 2023
6533e3b
sucsessfull 💀
snaapsh0t12 Jan 10, 2023
c1617c4
Capitalized some metrics
snaapsh0t12 Jan 10, 2023
7013913
Update LICENSE
snaapsh0t12 Jan 10, 2023
5374f31
why is this adding apostrophes
snaapsh0t12 Jan 12, 2023
0aacbfa
Fixed some questions, changed length to 15, and changed serverurl
snaapsh0t12 Jan 12, 2023
3b60961
added a tip to endgame ability/startegy
TooneyTurkey Jan 12, 2023
7729eb2
changed abilitys to rating
TooneyTurkey Jan 12, 2023
6867f2e
updated drive train type
TooneyTurkey Jan 13, 2023
f5b0587
removed "Limelight Capabilities:" as i feel this question does not ap…
TooneyTurkey Jan 13, 2023
f032738
removed "endgame traction rating" as oren no likey
TooneyTurkey Jan 13, 2023
eb719dc
updated "endgame ability/strategy sumary" to be in other instead of o…
TooneyTurkey Jan 13, 2023
5d1908a
index.js
TooneyTurkey Jan 17, 2023
7d282aa
Update index.js
snaapsh0t12 Feb 1, 2023
2fcd025
Update index.js
snaapsh0t12 Feb 1, 2023
0004dee
Update index.js
snaapsh0t12 Feb 1, 2023
f5c56fe
index.js
TooneyTurkey Feb 3, 2023
4c2db57
Fixed the empty not submitting
snaapsh0t12 Mar 16, 2023
b2ee64d
no more placeholder
snaapsh0t12 Mar 28, 2023
7582d33
Fixed number value not sending when manual input
snaapsh0t12 Mar 30, 2023
0134baf
Merge branch 'main' into preview
snaapsh0t12 Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pits.team4198.org
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2022 Joseph Melancon
Copyright (c) 2023 Aiden Lee
Copyright (c) 2020 Aidan Linerud

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<div class="flex hide" id="menu">
<span class="group">Options</span>
<div class="flex spaced">
<div class="flex">Event Passcode
<input id="auth-passwd">
</div>
<div>Crew
<select id="crew-select">
<option class="red">Crew 1</option>
Expand Down
202 changes: 152 additions & 50 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ if ("serviceWorker" in navigator) {
const menuToggleButton = document.querySelector("#menu-toggle-btn");
const locationText = document.querySelector("#crew-text");
const menuDiv = document.querySelector("#menu");
const authPasswd = document.querySelector("#auth-passwd");
const scoutName = document.querySelector("#scout-name");
const locationSelect = document.querySelector("#crew-select");
const templateCopyButton = document.querySelector("#template-copy-btn");
const templateEditButton = document.querySelector("#template-edit-btn");
Expand Down Expand Up @@ -33,6 +35,8 @@ let scoutLocation = "Crew 1";
let isAbsent = false;
let gameMetrics = [];

let serverURL = "https://data.team4198.org:8000";

// If you make a new type, be sure to add it here
const metricTypes = {
"toggle": ToggleMetric,
Expand All @@ -42,6 +46,7 @@ const metricTypes = {
"rating": RatingMetric,
"timer": TimerMetric,
"float": FloatMetric,
"new_line": new_line,
};

// The example template showcases each metric type
Expand All @@ -62,56 +67,68 @@ const infiniteRechargeSurvey = {
{ "name": "Team Location", "type": "text", "tip": "Enter town here..." },
{ "name": "Robot Name", "type": "text", "tip": "Enter name here..." },

{ "name": "Drive Train Type", "type": "text", "tip": "Enter type here...", "group": "Robot Specs" },
{ "name": "Drive Train Type", "type": "select", "values": ["Mechanum","Tank(traction)","Tank(omni)","Tank(mixed)","Swerve"], "group": "Robot Specs" },
{ "name": "Motor Type", "type": "text", "tip": "Enter type here..." },
{ "name": "Number of Wheels Used", "type": "number" },
{ "name": "Ball Capacity", "type": "select", "values": ["0", "1", "2"] },
{ "name": "Goal Height", "type": "select", "values": ["High and Low", "High", "Low", "None"] },
{ "name": "Average Cycle Time (s)", "type": "float"},
{ "name": "Ball Bounce Out Rate (%)", "type": "float"},
{ "name": "Ability to move Cones", "type": "rating"},
{ "name": "Ability to move Cubes", "type": "rating"},
{ "name": "Average Cone cycle Time (s)", "type": "float"},
{ "name": "Average Cube cycle Time (s)", "type": "float"},
{ "name": "Successfull grab rate (%)", "type": "float"},
{ "name": "Robot Weight (lbs)", "type": "float"},
{ "name": "Max Height Capabilities", "type": "select", "values": ["High","Middle", "Low", "Non-scoring bot"] },
{ "name": "Total Wheels Used", "type": "number" },

{ "name": "Can it Climb?", "type": "toggle", "group": "Engineered Capabilities" },
{ "name": "Climb Level", "type": "select", "values": ["0", "1", "2", "3", "4"] },
{ "name": "Total Climb Time (s)", "type": "float" },
{ "name": "Where are Pneumatics Used?", "type": "text", "tip": "Type here. Leave blank for none." },
{ "name": "Where are Pneumatics Used?", "type": "text", "tip": "Type here. Leave blank for none.","group": "Engineered Capabilities" },
{ "name": "Where are 3D-Printed Parts Used?", "type": "text", "tip": "Type here. Leave blank for none." },

{ "name": "Programmed Auto Capabilities?", "type": "text", "tip": "Type here. Leave blank for none.", "group": "Programmed Capabilities" },
{ "name": "Limelight Capabilities:", "type": "select", "values": ["Auto Targeting & Auto Shooting", "Auto Targeting", "Auto Shooting", "None / No Limelight"] },
{ "name": "April tags used?", "type":"toggle"},
{ "name": "Reflective tape used?", "type":"toggle"},
{ "name": "Extra Cameras Used?", "type": "toggle" },
{ "name": "Automation Via Sensors?", "type": "toggle" },

{ "name": "What is your favorite or least favorite part of this year's game?", "type": "text", "tip": "Type here...", "group": "Other" },
{ "name": "Endgame Ability/Strategy Summary", "type": "text","tip":"Type here...", "group":"Other"},
{ "name": "What is your favorite or least favorite part of this year's game?", "type": "text", "tip": "Type here..." },
{ "name": "Drive station summary", "type": "text", "tip": "Summarize the battle station"},
{ "name": "Are there any other unique abilities or quirks that your robot has that you’d like to talk about?", "type": "text", "tip": "Type here..." },
]
};

// const matchMetric = [];
const matchListings = [];

const exampleTemplate = infiniteRechargeSurvey;

let currentTemplate = JSON.parse(localStorage.template ?? JSON.stringify(exampleTemplate));
loadTemplate(currentTemplate);
setLocation(localStorage.location ?? "Crew 1");

if (localStorage.backup) {
const backup = JSON.parse(localStorage.backup);
teamMetric.value = backup.find(metric => metric.name == "Team").value;
isAbsent = backup.find(metric => metric.name == "Absent").value;
if (isAbsent) {
absentMetric.innerHTML = "<i class='square-checked text-icon'></i>Absent";
customMetricsDiv.classList.toggle("hide");
refreshIcons(absentMetric);
const backup = JSON.parse(localStorage.backup);
authPasswd.value = backup.find(metric => metric.name == "Auth").value;
// matchMetric.value = matchCount;
scoutName.value = backup.find(metric => metric.name == "tName").value;
isAbsent = backup.find(metric => metric.name == "Absent").value;
if (isAbsent) {
absentMetric.innerHTML = "<i class='square-checked text-icon'></i>Absent";
customMetricsDiv.classList.toggle("hide");
refreshIcons(absentMetric);
}
gameMetrics.forEach(metric => {
metric.update(backup.find(m => m.name == metric.name).value);
});
if (matchListings.length != 0) {
teamDisp.value = determineTeam(matchMetric.value, scoutLocation);
}
}
gameMetrics.forEach(metric => {
metric.update(backup.find(m => m.name == metric.name).value);
});
}

/** Stores the current unsaved survey to `localStorage` */
function backupSurvey() {
localStorage.backup = JSON.stringify([
{ name: "Team", value: teamMetric.value },
{ name: "Absent", value: isAbsent },
{ name: "Auth", value: authPasswd.value },
{ name: "Name", value: scoutName.value},
...gameMetrics.map(metric => { return { name: metric.name, value: metric.value } })
]);
}
Expand Down Expand Up @@ -223,35 +240,120 @@ function setLocation(newLocation = "Crew 1") {

/** Validates and saves the current survey to `localStorage` */
function saveSurvey() {
// Matches a 1-4 long sequence of numbers and an optional character
if (!/^\d{1,4}[A-Z]?$/.test(teamMetric.value)) {
alert("Invalid team value");
teamMetric.focus();
return;
}
if (currentTemplate.teams) {
if (!currentTemplate.teams.some(team => team == teamMetric.value)) {
alert("Invalid team value");
teamMetric.focus();
return;
if (matchListings.length == 0) {
// Matches a 1-4 long sequence of numbers and an optional character
if (!/^\d{1,4}[A-Z]?$/.test(teamMetric.value)) {
alert("Invalid team value! Please enter a 1-9999 digit team number.");
teamMetric.focus();
return;
}
if (currentTemplate.teams) {
if (!currentTemplate.teams.some(team => team == teamMetric.value)) {
alert("Invalid team value! Please enter a 1-9999 digit team number.");
teamMetric.focus();
return;
}
}

if (scoutName.value == "") {
alert("Invalid name value! Please enter your name where it goes.");
teamMetric.focus();
return;
}

}
// Matches a 1-3 long sequence of numbers
// if (!/\d{1,3}/.test(matchMetric.value)) {
// alert("Invalid match value! Make sure the match value is an integer.");
// matchMetric.focus();
// return;
// }
if (matchListings.length != 0) {
if (1 > matchMetric.value || matchMetric.value > matchListings.length) {
alert("Invalid match value! Make sure the match value is a valid qualifier match.");
matchMetric.focus();
return;
}
}
if (authPasswd.value == ""){
if (!confirm("Save match data OFFLINE?")) return;
let surveys = JSON.parse(localStorage.surveys ?? "[]");
surveys.push([
{ name: "Team", value: teamMetric.value },
{ name: "Absent", value: isAbsent },
{ name: "Location", value: locationSelect.value },
{ name: "Name", value: scoutName.value},
...gameMetrics.map(metric => { return { name: metric.name, value: metric.value } })
]);
localStorage.surveys = JSON.stringify(surveys);
resetSurvey(false);
}
else {
if (!confirm("Save match data online?")) return;
let surveys = JSON.parse(localStorage.surveys ?? "[]");
surveys.push([
{ name: "Team", value: teamMetric.value },
{ name: "Absent", value: isAbsent },
{ name: "Location", value: locationSelect.value },
{ name: "Name", value: scoutName.value},
...gameMetrics.map(metric => { return { name: metric.name, value: metric.value } })
]);
postSurvey([
{ name: "Team", value: teamMetric.value },
{ name: "Absent", value: isAbsent },
{ name: "Location", value: locationSelect.value },
{ name: "Name", value: scoutName.value},
...gameMetrics.map(metric => { return { name: metric.name, value: metric.value } })
]);
}
}
/* // Matches a 1-3 long sequence of numbers
if (!/\d{1,3}/.test(matchMetric.value)) {
alert("Invalid match value");
matchMetric.focus();
return;
}*/
if (!confirm("Confirm save?")) return;
let surveys = JSON.parse(localStorage.surveys ?? "[]");
surveys.push([
{ name: "Team", value: teamMetric.value },
{ name: "Absent", value: isAbsent },
...gameMetrics.map(metric => { return { name: metric.name, value: metric.value } })
]);
localStorage.surveys = JSON.stringify(surveys);
resetSurvey(false);
}

function postSurvey(surveyJson){
newJson = "{\n";
surveyJson.forEach(metric => {
prettyName = metric.name.toLowerCase().split(/\(|\)|\ |\?|\\|\/|\-/).join("").slice(0, 15);
if (typeof metric.value == "string") newJson += (' "' + prettyName + '": "' + metric.value + '",\n');
else newJson += (' "' + prettyName + '": ' + metric.value + ',\n');
});
newJson += ' "password": "' + authPasswd.value + '"\n}';
let xhr = new XMLHttpRequest();
xhr.open("POST", serverURL + "/pits");

xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.onload = function () {
console.log(xhr.status);

if (xhr.status == 401){
console.log("Password Failed")
alert("Authentication failure. Please check password.");
authPasswd.focus();
return;
}

// Process our return data
if (xhr.status >= 200 && xhr.status < 300) {
// Runs when the request is successful
console.log(xhr.responseText);
if (xhr.status == 202){
resetSurvey(false);
}
else if (xhr.status == 200) {
resetSurvey(false)
}
else{
alert("Unknown error occured. Please check your Internet connection.");
return;
}
} else {
// Runs when it's not
console.log(xhr.responseText);
}
};
xhr.send(newJson);

}

/**
* Resets the current survey
Expand Down
16 changes: 13 additions & 3 deletions metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class NumberMetric {
}

update(newValue = this.number.value) {
this.value = newValue;
this.number.value = newValue;
this.value = parseInt(newValue);
if (this.value == NaN) {this.value = parseInt(0)}
this.number.value = parseInt(newValue);
}

reset() {
Expand All @@ -86,7 +87,8 @@ class FloatMetric {
}

update(newValue = this.input.value.replace('"', "'")) {
this.value = newValue;
this.value = parseFloat(newValue);
if (this.value == NaN) {this.value = parseFloat(0)}
this.input.value = newValue;
}

Expand Down Expand Up @@ -260,3 +262,11 @@ class TimerMetric {
this.stop();
}
}

//intention is to make this force a new line in order for formating among all devices similar ill make it actually work soon
class new_line {
constructor(metric={name:"new_line"}){
this.name = metric.name;
this.element.innerHTML = "<br>"
}
}