Skip to content

Commit

Permalink
Added pitScout submission functionality. Made small change to dbHandl…
Browse files Browse the repository at this point in the history
…er for backward SQL compatibility.
  • Loading branch information
saikiranra committed Mar 8, 2022
1 parent 0dee505 commit 8fd336b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dbHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function createTBATable(){
$query = "CREATE TABLE " . $dbConfig["db"] . "." .$dbConfig["tbatable"] . " (
requestURI VARCHAR(100) NOT NULL PRIMARY KEY,
expiryTime BIGINT NOT NULL,
response JSON NOT NULL
response MEDIUMTEXT NOT NULL
)";
$statement = $conn->prepare($query);
if (!$statement->execute()) {
Expand Down
112 changes: 99 additions & 13 deletions pitScouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,39 @@
</div>
<div class="mb-3">
<label for="batteryChargers" class="form-label">Number of Battery Chargers</label>
<input type="number" class="form-control" id="batteries">
<input type="number" class="form-control" id="batteryChargers">
</div>
<div>
<label class="form-label">Pit Organization</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="pitScore1" value="option1">
<input class="form-check-input" type="radio" name="pitOrgGroup" id="pitScore1">
<label class="form-check-label" for="pitScore1">1</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="pitScore2" value="option2">
<input class="form-check-input" type="radio" name="pitOrgGroup" id="pitScore2">
<label class="form-check-label" for="pitScore2">2</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="pitScore3" value="option2">
<input class="form-check-input" type="radio" name="pitOrgGroup" id="pitScore3">
<label class="form-check-label" for="pitScore3">3</label>
</div>
<div>
<label class="form-label">Does the team have spare parts?</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="sparePartsYes" value="option1">
<input class="form-check-input" type="radio" name="sparePartsGroup" id="sparePartsYes">
<label class="form-check-label" for="sparePartsYes">Yes</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="sparePartsNo" value="option2">
<input class="form-check-input" type="radio" name="sparePartsGroup" id="sparePartsNo">
<label class="form-check-label" for="sparePartsNo">No</label>
</div>
<div class="mb-3">
<label for="driveType" class="form-label">Programming Language</label>
<div class="input-group mb-3">
<select class="form-select" id="programmingLanguage">
<option selected>Choose...</option>
<option selected value="0">Choose...</option>
<option id="java" value="1">Java</option>
<option id="labView" value="2">LabView</option>
<option id="C++" value="3">C++</option>
Expand All @@ -69,14 +69,14 @@
<div class="input-group mb-3">
<select class="form-select" id="driveMotors">
<option selected>Choose...</option>
<option id="falcons" value="1">Falcons</option>
<option id="neos" value="2">Neos</option>
<option id="cims" value="3">Cims</option>
<option value="1">Falcons</option>
<option value="2">Neos</option>
<option value="3">Cims</option>
</select>
</div>
</div>
<div class="d-grid gap-2 col-6 mx-auto">
<button class="btn btn-primary" type="button" id="submit">Submit</button>
<button class="btn btn-primary" type="button" id="submitButton">Submit</button>
</div>
</form>
</div>
Expand All @@ -87,7 +87,93 @@

<?php include("footer.php") ?>

<script>
</script>
<script>

function verifyData(){
var isError = false;
var errorMessage = "";

if ($("#teamNumber").val() == ""){
errorMessage += "Please Enter Team Number. ";
isError = true;
}

var driveMotors = $("#driveMotors").val();
if (driveMotors != 1 && driveMotors != 2 && driveMotors != 3){
errorMessage += "Please Select Drive Motor. ";
isError = true;
}

var progLanguage = $("#programmingLanguage").val();
if (progLanguage != 1 && progLanguage != 2 && progLanguage != 3){
errorMessage += "Please Select Programming Language. ";
isError = true;
}

if(isError){
alert(errorMessage);
}
return isError;
}

function clearForm(){
$("#teamNumber").val("");
$("#batteries").val("");
$("#batteryChargers").val("");
$("#programmingLanguage").val("0");
$("#driveMotors").val("0");
$("#pitScore1").prop("checked", false);
$("#pitScore2").prop("checked", false);
$("#pitScore3").prop("checked", false);
$("#sparePartsYes").prop("checked", false);
$("#sparePartsNo").prop("checked", false);
}

function writeDataToAPI(){
var writeData = {};
writeData["teamnumber"] = $("#teamNumber").val();
writeData["numbatteries"] = $("#batteries").val();
writeData["numchargers"] = $("#batteryChargers").val();

if ($("#pitScore1").is(':checked')){writeData["pitorg"] = 1;}
if ($("#pitScore2").is(':checked')){writeData["pitorg"] = 3;}
if ($("#pitScore3").is(':checked')){writeData["pitorg"] = 5;}

if ($("#sparePartsYes").is(':checked')){writeData["spareparts"] = 1;}
if ($("#sparePartsNo").is(':checked')){writeData["spareparts"] = 0;}

var progLang = $("#programmingLanguage").val();
if (progLang == 1){writeData["proglanguage"] = "Java";}
if (progLang == 2){writeData["proglanguage"] = "LabView";}
if (progLang == 3){writeData["proglanguage"] = "C++";}
if (progLang == 4){writeData["proglanguage"] = "Python";}
if (progLang == 5){writeData["proglanguage"] = "Other";}

var driveMotors = $("#driveMotors").val()
if (driveMotors == 1){writeData["drivemotors"] = "Falcons";}
if (driveMotors == 2){writeData["drivemotors"] = "NEOs";}
if (driveMotors == 3){writeData["drivemotors"] = "Cims";}


$.post( "writeAPI.php", {writePitData: JSON.stringify(writeData)}).done( function( data ) {
if (data == "success"){
alert("Success in submitting data!");
clearForm();
}
else {
alert("Failure in submitting data!");
}
});
}

$(document).ready(function() {

$("#submitButton").click(function(){
if (!verifyData()){
writeDataToAPI();
}
});

});

</script>
4 changes: 3 additions & 1 deletion writeAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
catch(Exception $e){
}
}
echo("success");
}
if (isset($_POST["writePitData"])){
/*
$_POST["writePitData"] = {teamnumber : x, numbatteries : x, numchargers : x, pitorg : x,
spareparts : x, proglanguage : x, drivemotors: x}
*/
$db->connectToDB();
$args = json_decode($_POST["writePitData"]);
$args = json_decode($_POST["writePitData"], true);
$args["entrykey"] = $eventCode . "_" . $args["teamnumber"];
$args["eventcode"] = $eventCode;
$db->writeRowToPitTable($args);
echo("success");
}
else if(isset($_POST["teamNum"]) and isset($_FILES["teamPic"])){
// Upload Picture API
Expand Down

0 comments on commit 8fd336b

Please sign in to comment.