Commit f607303d by Daniel Bawag

WG-32 - Saved the kph on server

parent 32df519f
......@@ -24,3 +24,5 @@ const SCHEMA_FILE = "./src/sample_schema/10_field_schema.json"
const INPUT_FILES = ["./input/Ong, Mae Janica - Application Form.TIFF","./input/Magalona, Rowell James - Application Form.TIFF","./input/Felizardo, Brylle Theodure - Application Form.TIFF","./input/Laxamana, Conrad John - Application Form.TIFF"] // list of URLs
const OUTPUT_FILES = "../../output/"
const METRIC_FILES = "../../metrics/"
......@@ -69,7 +69,6 @@
<div id="TiffViewerModal">
<div id="counter"></div>
<!-- Modal content -->
<div class="TiffModalContent">
......
......@@ -11,6 +11,8 @@ const ctrl_shift_shortcuts = ['v', 'h', 'V', 'H']
const shortcut_triggers = ['Shift', 'Control']
let shortcut_flag = false
const csv_header = ['filename', 'speed', 'avg_speed'];
const startMetricCapture = () => {
// reset key strokes
key_strokes = 0
......@@ -86,6 +88,47 @@ const showMetricCapture = () => {
setTimeout(showMetricCapture, 1000);
}
const saveMetrics = (metrics) => {
try
{
let rows = new Array();
if (sessionStorage.getItem('csv') === null) {
rows.push(csv_header);
rows.push([escapeCSV(File_Path.replace(/^.*[\\\/]/, '')), metrics.rate, metrics.rate]);
} else {
rows = JSON.parse(sessionStorage.getItem('csv'));
let size = rows.length - 1;
let last = rows[size];
let avg = last[last.length - 1];
let newAvg = (avg + metrics.rate) / (size + 1);
rows.push([escapeCSV(File_Path.replace(/^.*[\\\/]/, '')), metrics.rate, newAvg]);
}
var myFile = new File(
[(rows.map(e => e.join(",")).join("\n"))],
'UserID' + '_Metrics_' + (new Date()).toISOString().slice(0,10).replace(/-/g,"") + ".csv",
{type: "text/plain;charset=utf-8"}
);
let formData = new FormData();
formData.append("file", myFile);
formData.append("data", JSON.stringify({"metrics_dir": METRIC_FILES}));
fetch('./src/captureMetrics/saveMetrics.php', {
method: "POST",
body: formData
});
sessionStorage.setItem('csv', JSON.stringify(rows));
} catch(Err){
alert("Error: " + Err.description);
}
}
const escapeCSV = (filename) => {
return filename.includes(",") ? '"' + filename + '"' : filename;
}
const pauseMetricCapture = () => {
time_pause = Date.now();
alert("PAUSED");
......
<?php
$dir = json_decode($_POST['data'], true)['metrics_dir'];
/* Get the name of the uploaded file */
$filename = $_FILES['file']['name'];
/* Choose where to save the uploaded file */
$location = $dir.$filename;
/* Save the uploaded file to the local filesystem */
if ( move_uploaded_file($_FILES['file']['tmp_name'], $location) ) {
echo 'Success';
} else {
echo 'Failure';
}
?>
\ No newline at end of file
......@@ -36,8 +36,9 @@ const submitForm = (e) => {
return false
}
else {
const metrics = stopMetricCapture()
WriteForm(e, metrics)
const metrics = stopMetricCapture();
WriteForm(e, metrics);
saveMetrics(metrics);
return true
}
} catch(err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment