Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Hide our output data folder
data/
5 changes: 5 additions & 0 deletions datahandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// We know that all the data should exist in ./data/<team number>/<qual or playoff>/<match number>.txt
// Given a request for a team number, we should iterate through all files in ./data/<team number>/*, then make sure all required data points exist in each json,
// then we can output that data into a CSV format for viewing in Google Sheets or whatever

const fs = require('fs');
88 changes: 68 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down Expand Up @@ -30,7 +29,7 @@
let i = document.createElement('img');

// create plus sign
i.src = 'plus.png';
i.src = 'resources/plus.png';
i.style.position = 'absolute';
i.style.left = event.layerX - 16 + 'px';
i.style.top = event.layerY - 16 + 'px';
Expand All @@ -53,38 +52,87 @@
}
}

function err_msg_box(msg) {
document.getElementById("msg").innerHTML = msg;
}

function submitForm(e) {
e.stopImmediatePropagation();
e.preventDefault();
e.stopImmediatePropagation();
err_msg_box("");
var formData = new FormData(document.getElementById("mainForm"));
anadir(formData, "attempted_notes");
anadir(formData, "shot_locations");

var data = {};
formData.forEach((value, key) => data[key] = value);
// check data to make sure it makes sense
if(data["autoNotesAttempted"] < data["autoNotesScored"]) {
err_msg_box("BAD VALUES: Auto notes scored/attempted.");
return;
}
if(data["teleNotesAttempted"] < data["teleNotesScored"]) {
err_msg_box("BAD VALUES: Teleop notes scored/attempted.");
return;
}
var json = JSON.stringify(data);
console.log("attempting to post " + data);
var request = new XMLHttpRequest();
request.open('POST', 'https://example.com/sentir');
request.send(formData);
console.log("SENT!")
console.log(formData)
request.open('POST', document.URL);
request.send(json);
console.log("SENT!");
var has_err = false;
request.addEventListener("error", (event) => {
has_err = true;
err_msg_box("Error: unable to post data. Please report this issue ASAP!");
});
request.addEventListener("loadend", (event) => {
if(!has_err) {
location.reload();
}
});
}

</script>

</head>

<style>
.group label {
font-size: 100px;
}
</style>

<body>
<form onsubmit="submitForm(event)" id="mainForm">
<div class="group">
<label id="msg"></label>
</div>
<form onsubmit="submitForm(event);return false;" id="mainForm">
<h1>General</h1>
<div class="input-group mb-3">
<input type="number" class="form-control" placeholder="Team #" min="0" aria-label="Team #" name="team_number" required>
</div>
<div class="input-group mb-3">
<input type="number" class="form-control" placeholder="Match #" min="0" aria-label="Match #" name="match_number" required>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="Qual match?" name="is_qual" checked>
<label class="form-check-label" for="Qual match?">Qualification match?</label>
</div>
<h1>Autonomous</h1>

<div class="input-group mb-3">
<input type="number" class="form-control" placeholder="Notes Scored" aria-label="Notes Scored"
name="autoNotesScored">
<input type="number" class="form-control" placeholder="Notes Scored" min="0" aria-label="Notes Scored"
name="autoNotesScored" required>
<span class="input-group-text">/</span>
<input type="number" class="form-control" placeholder="Notes Attempted" aria-label="Notes Attempted"
name="autoNotesAttempted">
<input type="number" class="form-control" placeholder="Notes Attempted" min="0" aria-label="Notes Attempted"
name="autoNotesAttempted" required>
</div>

<h3>Select the Attempted Notes</h3>
<div id="attempted_notes"></div>
<div class="clickable_map">
<img src="map.png" alt="FRC Map" usemap="#note_map">
<img src="resources/map.png" alt="FRC Map" usemap="#note_map">
<map name="note_map">
<area alt="" title="" coords="501,537,19" shape="circle">
<area alt="" title="" coords="503,661,14" shape="circle">
Expand All @@ -103,23 +151,23 @@ <h3>Select the Attempted Notes</h3>
<h3>Select where notes are shot from.</h3>
<div id="attempted_notes"></div>
<div class="clickable_map">
<img src="map.png" alt="FRC Map" onclick="hijack(event, 'attempted_notes')">
</div>
<img src="resources/map.png" alt="FRC Map" onclick="hijack(event, 'attempted_notes')">
</div>>

<h1>Teleoperated</h1>

<div class="input-group mb-3">
<input type="number" class="form-control" placeholder="Notes Scored" aria-label="Notes Scored"
name="teleNotesScored">
<input type="number" class="form-control" placeholder="Notes Scored" min="0" aria-label="Notes Scored"
name="teleNotesScored" required>
<span class="input-group-text">/</span>
<input type="number" class="form-control" placeholder="Notes Attempted" aria-label="Notes Attempted"
name="teleNotesAttempted">
<input type="number" class="form-control" placeholder="Notes Attempted" min="0" aria-label="Notes Attempted"
name="teleNotesAttempted" required>
</div>

<h3>Select where they can shoot the notes.</h3>
<div id="shot_locations"></div>
<div class="clickable_map">
<img src="map.png" alt="FRC Map" onclick="hijack(event, 'shot_locations')">
<img src="resources/map.png" alt="FRC Map" onclick="hijack(event, 'shot_locations')">
</div>

<div class="mb-3 form-check">
Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "webserver_scouting",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
File renamed without changes
File renamed without changes
74 changes: 74 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const http = require('http');
const fs = require('fs');

const port = 80;
const page = fs.readFileSync("index.html").toString();

const mime = {
html: 'text/html',
txt: 'text/plain',
css: 'text/css',
gif: 'image/gif',
jpg: 'image/jpeg',
png: 'image/png',
svg: 'image/svg+xml',
js: 'application/javascript'
};

function make_folder_if_not_exists(folder) {
if(!fs.existsSync(folder)) {
fs.mkdirSync(folder + "/");
}
}

make_folder_if_not_exists("./data");

function qual_or_playoff_folder_name(is_qual) {
return is_qual ? "qual" : "playoff";
}

function log_data(data) {
console.log("writing: " + data);
make_folder_if_not_exists("./data/" + data["team_number"])
const iq = qual_or_playoff_folder_name(data["is_qual"]);
make_folder_if_not_exists("./data/" + data["team_number"] + "/" + iq);
fs.writeFile("./data/" + data["team_number"] + "/" + iq + "/" + data["match_number"] + ".txt", JSON.stringify(data), {flag: "w+"}, (err) => {
console.error(err);
});
}

const server = http.createServer((req, res) => {
if(req.method == "POST") {
var body = '';

req.on('data', function (data) {
body += data;

// Too much POST data, kill the connection!
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (body.length > 1e6)
request.connection.destroy();
});

req.on('end', () => {
var post = JSON.parse(body);
log_data(post);
res.end();
});
} else if(req.method == "GET") {
res.statusCode = 200;
if(req.url == "/") {
res.setHeader('Content-Type', 'text/html');
res.end(page);
} else if(req.url.startsWith("/resources/")) {
var tmp = req.url.split(".");
res.setHeader('Content-Type', mime[tmp[tmp.length - 1]]);
var s = fs.createReadStream("." + req.url);
s.on('open', () => {
s.pipe(res);
}); // this is probably inefficient? idk
}
}
});

server.listen(port);