Merge remote-tracking branch 'origin/master'

This commit is contained in:
mattbk
2015-11-01 10:10:17 -06:00
3 changed files with 118 additions and 64 deletions

114
index.php
View File

@ -78,6 +78,7 @@ switch ($mode) {
case 'finish': case 'finish':
$template = 'finish.html.twig'; $template = 'finish.html.twig';
// Store the result. // Store the result.
// This section will be removed
$query = $db->prepare('insert into vcd_results values (null, unix_timestamp(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); $query = $db->prepare('insert into vcd_results values (null, unix_timestamp(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$query->bind_param( $query->bind_param(
'siiiiiiiii', 'siiiiiiiii',
@ -94,10 +95,65 @@ switch ($mode) {
) or die('Could not prepare query'); ) or die('Could not prepare query');
$query->execute() or die('Could not execute query:<br>'.mysqli_error($db)); $query->execute() or die('Could not execute query:<br>'.mysqli_error($db));
$query->close(); $query->close();
// End remove section
//Store the result.
//Loop through $results better
//This will allow running only one query rather than several: http://stackoverflow.com/a/10054657/2152245
//Because I have `phase` as a field, I can also have `xcoordinate`, `ycoordinate`, and `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.
foreach ($_SESSION['results'] as $phasename => $phasevalue) {
//Initialize arrays
$ready = array();
//First piece of $ready is the phase/scene name
$ready[] = $phasename;
//Loop through xccordinate, ycoordinate, responsetime
foreach ($phasevalue as $measure => $measurevalue) {
//Put results in the right order for database
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:
//Include userid (once collection form is added into the start page)
// DB fields are listed here:
$columnstoimplode = array("uid", "datetime", "host", "phase", "xcoordinate", "ycoordinate","responsetime","score");
// Note that backticks (`) go around field names...
$columns = "`".implode("`, `", $columnstoimplode)."`";
// Set up timestamp so you can tell participants apart. http://alvinalexander.com/php/php-date-formatted-sql-timestamp-insert
$timestamp = date('Y-m-d G:i:s');
$valuestoimplode = array("", $timestamp, $_SERVER['REMOTE_ADDR']);
$valuestoimplode = array_merge($valuestoimplode,$ready);
$values = "'".implode("', '", $valuestoimplode)."'";
//print_r($values);
// Build and execute query
$sql = "INSERT INTO results (";
$sql .= $columns;
$sql .= ") VALUES ($values)";
$db->query($sql) or die('Could not execute query:<br>'.mysqli_error($db));
}
$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;
@ -108,7 +164,7 @@ switch ($mode) {
if ($download) { if ($download) {
header('Content-Type: text/tab-separated-values'); header('Content-Type: text/tab-separated-values');
header('Content-Disposition: attachment; filename=vcd-results.txt'); header('Content-Disposition: attachment; filename="results.txt"');
$template = 'results.txt.twig'; $template = 'results.txt.twig';
} }
else { else {
@ -117,19 +173,18 @@ switch ($mode) {
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 results where host != '192.168.0.1' order by datetime asc");
} }
else { else {
$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();
@ -137,33 +192,34 @@ 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.
}
$results->free();
break;
} //End case to select page.
if (!empty ($template)) { if (!empty ($template)) {
echo $twig->render($template, $variables); echo $twig->render($template, $variables);
} }
else { else {
//header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
} }

View File

@ -4,7 +4,9 @@
<header class="page-header"> <header class="page-header">
<h1>Change blindness results</h1> <h1>Change blindness results</h1>
</header> </header>
<!--
<div class="alert alert-info">{% if records == 1 %}Retrieved 1 result.{% else %}Retrieved {{ records }} results.{% endif %}</div> <div class="alert alert-info">{% if records == 1 %}Retrieved 1 result.{% else %}Retrieved {{ records }} results.{% endif %}</div>
-->
{% if allow_filtering %} {% if allow_filtering %}
<div class="btn-group"> <div class="btn-group">
<a class="btn{% if filtered %} active{% endif %}" href="index.php?mode=results&filtered=1">Filtered results</a> <a class="btn{% if filtered %} active{% endif %}" href="index.php?mode=results&filtered=1">Filtered results</a>
@ -12,6 +14,7 @@
</div> </div>
{% endif %} {% endif %}
<!--
<h2 id="statistics">Statistics</h2> <h2 id="statistics">Statistics</h2>
<table class="table"> <table class="table">
<thead> <thead>
@ -26,56 +29,52 @@
{% for record in stats %} {% for record in stats %}
<tr> <tr>
<td>{{ loop.index }}.</td> <td>{{ loop.index }}.</td>
{% if record.scene1.correct %}<td class="alert-success"><i class="icon-ok"></i>{% else %}<td class="alert-danger"><i class="icon-remove"></i>{% endif %}&nbsp;{{ record.scene1.time / 1000 }} seconds</td> {% if record.scene1.correct %}<td class="alert-success"><i class="icon-ok"></i>{% else %}<td class="alert-danger"><i class="icon-remove"></i>{% endif %}&nbsp;{{ record.scene1.time }} ms</td>
{% if record.scene2.correct %}<td class="alert-success"><i class="icon-ok"></i>{% else %}<td class="alert-danger"><i class="icon-remove"></i>{% endif %}&nbsp;{{ record.scene2.time / 1000 }} seconds</td> {% if record.scene2.correct %}<td class="alert-success"><i class="icon-ok"></i>{% else %}<td class="alert-danger"><i class="icon-remove"></i>{% endif %}&nbsp;{{ record.scene2.time }} ms</td>
{% if record.scene3.correct %}<td class="alert-success"><i class="icon-ok"></i>{% else %}<td class="alert-danger"><i class="icon-remove"></i>{% endif %}&nbsp;{{ record.scene3.time / 1000 }} seconds</td> {% if record.scene3.correct %}<td class="alert-success"><i class="icon-ok"></i>{% else %}<td class="alert-danger"><i class="icon-remove"></i>{% endif %}&nbsp;{{ record.scene3.time }} ms</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
-->
<!--Doing some debugging.
<pre>{{ dump(stats) }}</pre>
<pre>{{ dump(data) }}</pre> -->
<h2 id="raw-results">Raw results</h2> <h2 id="raw-results">Raw results</h2>
<p><a class="btn" href="index.php?mode=result&download=1"><i class="icon-download-alt"></i> Download results</a></p> <p><a class="btn" href="index.php?mode=results&download=1"><i class="icon-download-alt"></i> Download results</a></p>
<!--
{% for record in data %}
<pre>{{dump(record.uid)}}</pre>
<pre>{{record.uid}}</pre>
{% endfor %}
-->
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>#</th> <th>uid</th>
<th colspan="3">Notable</th> <th>date</th>
<th colspan="3">Unnoted</th> <th>host</th>
<th colspan="3">Renoted</th> <th>phase</th>
</tr>
<tr>
<th></th>
<th>x</th>
<th>y</th>
<th>time</th>
<th>x</th>
<th>y</th>
<th>time</th>
<th>x</th> <th>x</th>
<th>y</th> <th>y</th>
<th>time</th> <th>time</th>
<th>score</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for record in data %} {% for record in data %}
<tr class="{% if record.result.host == '192.168.0.1' %}muted{% endif %}"> <tr class="{% if record.result.host == '192.168.0.1' %}muted{% endif %}">
<td>{{ loop.index }}.</td> <td>{{record.uid}}.</td>
<td>{{ record.notable.xcoordinate }}</td> <td>{{ record.datetime }}</td>
<td>{{ record.notable.ycoordinate }}</td> <td>{{ record.host }}</td>
<td>{{ record.notable.responsetime }}</td> <td>{{ record.phase }}</td>
<td>{{ record.unnoted.xcoordinate }}</td> <td>{{ record.xcoordinate }}</td>
<td>{{ record.unnoted.ycoordinate }}</td> <td>{{ record.ycoordinate }}</td>
<td>{{ record.unnoted.responsetime }}</td> <td>{{ record.responsetime }}</td>
<td>{{ record.renoted.xcoordinate }}</td> <td>{{ record.score }}</td>
<td>{{ record.renoted.ycoordinate }}</td>
<td>{{ record.renoted.responsetime }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% endblock %} {% endblock %}

View File

@ -1,5 +1,4 @@
notable unnoted renoted uid datetime host phase xcoordinate ycoordinate responsetime score
x y time x y time x y time {% for record in data %}
{% for result in data %} {{record.uid}} {{record.datetime}} {{record.host}} {{record.phase}} {{record.xcoordinate}} {{record.ycoordinate}} {{record.responsetime}} {{record.score}}
{{result.notable.xcoordinate}} {{result.notable.ycoordinate}} {{result.notable.responsetime}} {{result.unnoted.xcoordinate}} {{result.unnoted.ycoordinate}} {{result.unnoted.responsetime}} {{result.renoted.xcoordinate}} {{result.renoted.ycoordinate}} {{result.renoted.responsetime}}
{% endfor %} {% endfor %}