Merge pull request #30 from mattbk/targets=-from-csv

Targets are now read from CSV file on server
This commit is contained in:
mattbk
2015-11-02 15:51:50 -06:00
3 changed files with 23 additions and 38 deletions

View File

@ -30,6 +30,18 @@ $variables = array(
'baseURL' => $settings->baseURL 'baseURL' => $settings->baseURL
); );
//Pull targets from CSV file
if (($handle = fopen('targets.csv', 'r')) === false) {
die('Error opening file');
}
$headers = fgetcsv($handle, 1024, ',');
$targets = array();
while ($row = fgetcsv($handle, 1024, ',')) {
$targets[$row[0]] = array_combine($headers, $row);
}
fclose($handle);
$template = false; $template = false;
$mode = !empty($_GET['mode']) ? $_GET['mode'] : 'start'; $mode = !empty($_GET['mode']) ? $_GET['mode'] : 'start';
$phase = !empty($_GET['phase']) && in_array($_GET['phase'], $settings->phases) ? $_GET['phase'] : false; $phase = !empty($_GET['phase']) && in_array($_GET['phase'], $settings->phases) ? $_GET['phase'] : false;
@ -97,18 +109,17 @@ switch ($mode) {
} }
//Calculate the score. Compare results with targets in settings.json. //Calculate the score. Compare results with targets in settings.json.
if (($phasevalue['xcoordinate'] >= $settings->elementLocations->{$phasename }->topleft->x) if (($phasevalue['xcoordinate'] >= $targets[$phasename][topleftx])
&& ($phasevalue['xcoordinate'] < $settings->elementLocations->{$phasename}->bottomright->x) && ($phasevalue['xcoordinate'] < $targets[$phasename][bottomrightx])
&& ($phasevalue['ycoordinate'] >= $settings->elementLocations->{$phasename}->topleft->y) && ($phasevalue['ycoordinate'] >= $targets[$phasename][toplefty])
&& ($phasevalue['ycoordinate'] < $settings->elementLocations->{$phasename}->bottomright->y)) { && ($phasevalue['ycoordinate'] < $targets[$phasename][bottomrighty])) {
//Put the correct score in the ready array //Put the correct score in the ready array
array_push($ready, '1'); array_push($ready, '1');
} }
else { else {
//Put the incorrect score in the ready array //Put the incorrect score in the ready array
array_push($ready, '0'); 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 are listed here: // DB fields are listed here:

View File

@ -12,37 +12,5 @@
"renoted" "renoted"
], ],
"baseURL": "/", "baseURL": "/",
"elementLocations": {
"notable": {
"topleft": {
"x": 724,
"y": 340
},
"bottomright": {
"x": 884,
"y": 456
}
},
"unnoted": {
"topleft": {
"x": 48,
"y": 180
},
"bottomright": {
"x": 900,
"y": 200
}
},
"renoted": {
"topleft": {
"x": 48,
"y": 180
},
"bottomright": {
"x": 900,
"y": 204
}
}
},
"debug": false "debug": false
} }

6
targets.csv Normal file
View File

@ -0,0 +1,6 @@
phase,topleftx,toplefty,bottomrightx,bottomrighty
1,0,0,10,10
2,0,0,20,20
3,0,0,30,30
4,0,0,40,40
5,0,0,50,50
1 phase topleftx toplefty bottomrightx bottomrighty
2 1 0 0 10 10
3 2 0 0 20 20
4 3 0 0 30 30
5 4 0 0 40 40
6 5 0 0 50 50