Score is now recorded in database
Saving this so I can move forward.
This commit is contained in:
96
index.php
96
index.php
@ -104,17 +104,33 @@ switch ($mode) {
|
|||||||
// as values as well. Table should have a field list of: uid, datetime, host, userid, phase, xcoordinate, ycoordinate, responsetime.
|
// as values as well. Table should have a field list of: uid, datetime, host, userid, phase, xcoordinate, ycoordinate, responsetime.
|
||||||
// SELECT query should then return one row per userid per phase/scene.
|
// SELECT query should then return one row per userid per phase/scene.
|
||||||
foreach ($_SESSION['results'] as $phasename => $phasevalue) {
|
foreach ($_SESSION['results'] as $phasename => $phasevalue) {
|
||||||
|
//Initialize arrays
|
||||||
$ready = array();
|
$ready = array();
|
||||||
|
//First piece of $ready is the phase/scene name
|
||||||
$ready[] = $phasename;
|
$ready[] = $phasename;
|
||||||
|
//Loop through xccordinate, ycoordinate, responsetime
|
||||||
foreach ($phasevalue as $measure => $measurevalue) {
|
foreach ($phasevalue as $measure => $measurevalue) {
|
||||||
//Put results in the right order for database
|
//Put results in the right order for database
|
||||||
array_push($ready, $measurevalue);
|
array_push($ready, $measurevalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Calculate the score. Compare results with targets in settings.json.
|
||||||
|
if (($phasevalue['xcoordinate'] >= $settings->elementLocations->{$phasename }->topleft->x)
|
||||||
|
&& ($phasevalue['xcoordinate'] < $settings->elementLocations->{$phasename}->bottomright->x)
|
||||||
|
&& ($phasevalue['ycoordinate'] >= $settings->elementLocations->{$phasename}->topleft->y)
|
||||||
|
&& ($phasevalue['ycoordinate'] < $settings->elementLocations->{$phasename}->bottomright->y)) {
|
||||||
|
//Put the correct score in the ready array
|
||||||
|
array_push($ready, '1');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//Put the incorrect score in the ready array
|
||||||
|
array_push($ready, '0');
|
||||||
|
}
|
||||||
|
|
||||||
//Building an INSERT query:
|
//Building an INSERT query:
|
||||||
//Include userid (once collection form is added into the start page)
|
//Include userid (once collection form is added into the start page)
|
||||||
// DB fields: uid, date, host, phase, measure, value
|
// DB fields are listed here:
|
||||||
// http://php.net/manual/en/function.implode.php
|
$columnstoimplode = array("uid", "datetime", "host", "phase", "xcoordinate", "ycoordinate","responsetime","score");
|
||||||
$columnstoimplode = array("uid", "datetime", "host", "phase", "xcoordinate", "ycoordinate","responsetime");
|
|
||||||
// Note that backticks (`) go around field names...
|
// Note that backticks (`) go around field names...
|
||||||
$columns = "`".implode("`, `", $columnstoimplode)."`";
|
$columns = "`".implode("`, `", $columnstoimplode)."`";
|
||||||
// Set up timestamp so you can tell participants apart. http://alvinalexander.com/php/php-date-formatted-sql-timestamp-insert
|
// Set up timestamp so you can tell participants apart. http://alvinalexander.com/php/php-date-formatted-sql-timestamp-insert
|
||||||
@ -122,7 +138,7 @@ switch ($mode) {
|
|||||||
$valuestoimplode = array("", $timestamp, $_SERVER['REMOTE_ADDR']);
|
$valuestoimplode = array("", $timestamp, $_SERVER['REMOTE_ADDR']);
|
||||||
$valuestoimplode = array_merge($valuestoimplode,$ready);
|
$valuestoimplode = array_merge($valuestoimplode,$ready);
|
||||||
$values = "'".implode("', '", $valuestoimplode)."'";
|
$values = "'".implode("', '", $valuestoimplode)."'";
|
||||||
print_r($values);
|
//print_r($values);
|
||||||
// Build and execute query
|
// Build and execute query
|
||||||
$sql = "INSERT INTO results (";
|
$sql = "INSERT INTO results (";
|
||||||
$sql .= $columns;
|
$sql .= $columns;
|
||||||
@ -131,13 +147,13 @@ switch ($mode) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Debugging
|
|
||||||
$variables['debug'] = $_SESSION['results'];
|
$variables['debug'] = $_SESSION['results'];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'results':
|
case 'results':
|
||||||
$download = isset($_GET['download']);
|
$download = isset($_GET['download']);
|
||||||
|
|
||||||
|
// Check if filtering by local IP should be enabled.
|
||||||
if ($settings->debug) {
|
if ($settings->debug) {
|
||||||
$variables['allow_filtering'] = true;
|
$variables['allow_filtering'] = true;
|
||||||
$filtered = isset($_GET['filtered']) || $download;
|
$filtered = isset($_GET['filtered']) || $download;
|
||||||
@ -155,25 +171,25 @@ switch ($mode) {
|
|||||||
$template = 'results.html.twig';
|
$template = 'results.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only shows up when debug=true in settings.json.
|
|
||||||
if ($filtered) {
|
if ($filtered) {
|
||||||
$variables['filtered'] = true;
|
$variables['filtered'] = true;
|
||||||
$results = $db->query("select * from vcd_results where result_host != '192.168.0.1' order by result_date asc");
|
// $results = $db->query("select * from vcd_results where result_host != '192.168.0.1' order by result_date asc");
|
||||||
|
$results = $db->query("select * from results where host != '192.168.0.1' order by datetime asc");
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
//This query needs to be rewritten to use the results table (EAV version),
|
//This query needs to be rewritten to use the results table (EAV version),
|
||||||
// but hopefully format the data in the same way (in the query itself, if possible?)
|
// but hopefully format the data in the same way (in the query itself, if possible?)
|
||||||
$results = $db->query("select * from vcd_results order by result_date asc");
|
//$results = $db->query("select * from vcd_results order by result_date asc");
|
||||||
|
$results = $db->query("select * from results order by datetime asc");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($results === false) {
|
if ($results === false) {
|
||||||
header('HTTP/1.0 500 Internal Server Error');
|
header('HTTP/1.0 500 Internal Server Error');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$variables['records'] = $results->num_rows;
|
$variables['records'] = $results->num_rows;
|
||||||
|
|
||||||
$variables['data'] = array();
|
$variables['data'] = array();
|
||||||
$variables['stats'] = array();
|
$variables['stats'] = array();
|
||||||
|
|
||||||
@ -181,29 +197,47 @@ switch ($mode) {
|
|||||||
$data = array();
|
$data = array();
|
||||||
$stats = array();
|
$stats = array();
|
||||||
|
|
||||||
// Prepare data
|
//Skip empty results (created during debugging)
|
||||||
foreach ($record as $name => $value) {
|
if ($record['responsetime'] > 0) {
|
||||||
list($cat, $key) = explode('_', $name);
|
//Put your results in one array
|
||||||
$data[$cat][$key] = $value;
|
$variables['data'][] = $record;
|
||||||
}
|
}
|
||||||
$variables['data'][] = $data;
|
//here
|
||||||
|
|
||||||
// Build statistics
|
|
||||||
foreach ($settings->phases as $phase) {
|
|
||||||
$stats[$phase] = array(
|
//Skip empty results (created during debugging)
|
||||||
'correct' => (($data[$phase]['xcoordinate'] >= $settings->elementLocations->{$phase}->topleft->x)
|
if ($record['responsetime'] > 0) {
|
||||||
&& ($data[$phase]['xcoordinate'] <= $settings->elementLocations->{$phase}->bottomright->x)
|
foreach ($record as $name => $value) {
|
||||||
&& ($data[$phase]['ycoordinate'] >= $settings->elementLocations->{$phase}->topleft->y)
|
|
||||||
&& ($data[$phase]['ycoordinate'] <= $settings->elementLocations->{$phase}->bottomright->y)),
|
}
|
||||||
'time' => $data[$phase]['responsetime']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$variables['stats'][] = $stats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$results->free();
|
|
||||||
break;
|
} //End while to loop through results from database.
|
||||||
}
|
|
||||||
|
echo "<pre>";
|
||||||
|
print_r($variables['data']);
|
||||||
|
echo "</pre>";
|
||||||
|
|
||||||
|
// Build statistics
|
||||||
|
//Stats are calculated before results are put into the database
|
||||||
|
// foreach ($variables['data'] as $key=>$value) {
|
||||||
|
// //print_r($value['phase']);
|
||||||
|
// $stats[] = array(
|
||||||
|
// 'correct' => (($value['xcoordinate'] >= $settings->elementLocations->{$value['phase'] }->topleft->x)
|
||||||
|
// && ($value['xcoordinate'] < $settings->elementLocations->{$value['phase']}->bottomright->x)
|
||||||
|
// && ($value['ycoordinate'] >= $settings->elementLocations->{$value['phase']}->topleft->y)
|
||||||
|
// && ($value['ycoordinate'] < $settings->elementLocations->{$value['phase']}->bottomright->y)),
|
||||||
|
// 'time' => $value['responsetime']
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// $variables['stats'] = $stats;
|
||||||
|
|
||||||
|
$results->free();
|
||||||
|
break;
|
||||||
|
} //End case to select page.
|
||||||
|
|
||||||
|
|
||||||
if (!empty ($template)) {
|
if (!empty ($template)) {
|
||||||
echo $twig->render($template, $variables);
|
echo $twig->render($template, $variables);
|
||||||
|
Reference in New Issue
Block a user