function recordTrial($extraData = array(), $exitIfDone = true, $advancePosition = true) { global $_CONFIG, $_PATH; #### setting up aliases (for later use) $currentPos =& $_SESSION['Position']; $currentTrial =& $_SESSION['Trials'][$currentPos]; #### Calculating time difference from current to last trial $oldTime = $_SESSION['Timestamp']; $_SESSION['Timestamp'] = microtime(true); $timeDif = $_SESSION['Timestamp'] - $oldTime; #### Writing to data file $data = array('Username' => $_SESSION['Username'], 'ID' => $_SESSION['ID'], 'ExperimentName' => $_CONFIG->experiment_name, 'Session' => $_SESSION['Session'], 'Trial' => $_SESSION['Position'], 'Date' => date("c"), 'TimeDif' => $timeDif, 'Condition Number' => $_SESSION['Condition']['Number'], 'Stimuli File' => $_SESSION['Condition']['Stimuli'], 'Order File' => $_SESSION['Condition']['Procedure'], 'Condition Description' => $_SESSION['Condition']['Condition Description'], 'Condition Notes' => $_SESSION['Condition']['Condition Notes']); foreach ($currentTrial as $category => $array) { $data += AddPrefixToArray($category . '*', $array); } if (!is_array($extraData)) { $extraData = array($extraData); } foreach ($extraData as $header => $datum) { $data[$header] = $datum; } $writtenArray = arrayToLine($data, $_PATH->get('Experiment Output')); // write data line to the file ########################################### // progresses the trial counter if ($advancePosition) { $currentPos++; $_SESSION['PostNumber'] = 0; } // are we done with the experiment? if so, send to finalQuestions.php if ($exitIfDone) { $item = $_SESSION['Trials'][$currentPos]['Procedure']['Item']; if ($item == 'ExperimentFinished') { $_SESSION['finishedTrials'] = true; // stops people from skipping to the end header('Location: ' . $_PATH->get('Final Questions Page')); exit; } } return $writtenArray; }
?> </ol> <?php if ($_CONFIG->stop_for_errors == true) { echo '<br/> <h2>The program will not run until you have addressed the above errors</h2>'; exit; } ?> </div> <?php } #### Record info about the person starting the experiment to the status start file // information about the user loging in $userAgent = getUserAgentInfo(); $UserData = array('Username' => $_SESSION['Username'], 'ID' => $_SESSION['ID'], 'Date' => $_SESSION['Start Time'], 'Session' => $_SESSION['Session'], 'Condition_Number' => $_SESSION['Condition']['Number'], 'Condition_Description' => $_SESSION['Condition']['Condition Description'], 'Output_File' => $outputFile, 'Stimuli_File' => $_SESSION['Condition']['Stimuli'], 'Procedure_File' => $_SESSION['Condition']['Procedure'], 'Browser' => $userAgent->Parent, 'DeviceType' => $userAgent->Device_Type, 'OS' => $userAgent->Platform, 'IP' => $_SERVER["REMOTE_ADDR"]); arrayToLine($UserData, $_FILES->status_begin); ########################################################################### #### Send participant to next phase of experiment (demographics or instructions) if ($_CONFIG->run_demographics == true) { $link = 'BasicInfo.php'; } elseif ($_CONFIG->run_instructions) { $link = 'instructions.php'; } else { $link = 'experiment.php'; } if ($_CONFIG->stop_at_login == true) { // if things are going wrong this info will help you figure out when the program broke Readable($_SESSION['Condition'], 'Condition information'); Readable($stimuli, 'Stimuli file in use (' . $_FILES->stim_files . '/' . $_SESSION['Condition']['Stimuli'] . ')'); Readable($procedure, 'Procedure file in use (' . $_FILES->proc_files . '/' . $_SESSION['Condition']['Procedure'] . ')'); Readable($trialTypeColumns, 'Levels of trial types being used');
public function recordData($extraData = null, $filename = null, $position = null, $relPos = false) { if ($extraData === null) { $extraData = array(); } if ($filename === null) { $filename = $this->outputFile; } if ($position === null) { $position = $this->position; } if ($postTrial === null) { $postTrial = $this->postTrial; } $realPos = $this->getProcIndex($position, $relPos); $procRow = $this->procedure[$realPos]; $item = $procRow['Item']; $stim = getStimData($item); foreach ($stim as &$stimArray) { $stimArray = implode('|', $stimArray); } unset($stimArray); $output = addPrefixToArray('Resp*', $this->responses[$realPos]) + addPrefixToArray('Stim*', $stim) + addPrefixToArray('Proc*', $procRow) + $this->extraRecords; $output['Trial'] = $realPos + 1; // add 1 to be human-readable $output['Date'] = date('c'); $output['Timestamp_Diff'] = microtime(true) - $this->recordTimestamp; $this->recordTimestamp = microtime(true); if (!is_array($extraData)) { $extraData = array('ExtraData' => $extraData); } foreach ($extraData as $key => $value) { $output[$key] = $value; } arrayToLine($output, $filename); }
<?php /* Collector A program for running experiments on the web */ require 'initiateCollector.php'; $data = array('Username' => $_SESSION['Username'], 'ID' => $_SESSION['ID'], 'Date' => date('c')); $data += $_POST; arrayToLine($data, $_PATH->get('Instructions Data')); header('Location: ' . $_PATH->get('Experiment Page')); exit;
$hours = floor($durationFormatted / 3600); $minutes = floor(($durationFormatted - $hours * 3600) / 60); $seconds = $durationFormatted - $hours * 3600 - $minutes * 60; if ($hours < 10) { $hours = '0' . $hours; } if ($minutes < 10) { $minutes = '0' . $minutes; } if ($seconds < 10) { $seconds = '0' . $seconds; } $durationFormatted = $hours . ':' . $minutes . ':' . $seconds; #### Record info about the person ending the experiment to status finish file $data = array('Username' => $_SESSION['Username'], 'ID' => $_SESSION['ID'], 'Date' => date('c'), 'Duration' => $duration, 'Duration_Formatted' => $durationFormatted, 'Session' => $_SESSION['Session'], 'Condition_Number' => $_SESSION['Condition']['Number']); arrayToLine($data, $_PATH->get('Status End Data')); ######## Save the $_SESSION array as a JSON string $ExpOverFlag = $_SESSION['Trials'][$_SESSION['Position']]['Procedure']['Item']; // if you haven't finished all sessions yet if ($ExpOverFlag != 'ExperimentFinished') { $_SESSION['Position']++; // increment counter so next session will begin after the *NewSession* (if multisession) $_SESSION['Session']++; // increment session # so next login will be correctly labeled as the next session $_SESSION['ID'] = rand_string(); // generate a new ID (for next login) $_SESSION['finishedTrials'] = false; // will stop them from skipping to done.php during next session $_SESSION['LastFinish'] = time(); } $jsonSession = json_encode($_SESSION);
<?php $files = array('core/arrayToLine/benchmark.csv', 'core/arrayToLine/benchmark2.csv'); $args = array(array('Username' => 'Participant001', 'ID' => 'aaaaaaaa', 'Condition' => 'control', 'Stim*Cue' => 'A', 'Proc*Item' => '2', 'Resp*Resp' => 'hello world', 'Resp*RT' => 12.231231, 'Resp*RT1' => 2.435452, 'Resp*RT2' => 11.254728, 'Resp*Focu' => 0.9812340000000001, 'Resp*Acc' => 100, 'Resp*Len' => 1, 'Resp*Str' => 1, 'Resp*JOL' => '100'), $files[0]); echo 't1 is using the benchmark function, t2 is without<br><br>'; $iterations = 100; $time = benchmark('arrayToLine', $iterations, $args); echo 't1: ' . $time . '<br>'; $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { arrayToLine($args[0], $files[1]); } $time = microtime(true) - $start; echo 't2: ' . $time;
?> </ol> <?php if ($_CONFIG->stop_for_errors == true) { echo '<br/> <h2>The program will not run until you have addressed the above errors</h2>'; exit; } ?> </div> <?php } #### Record info about the person starting the experiment to the status start file // information about the user logging in $userAgent = getUserAgentInfo(); $UserData = array('Username' => $_SESSION['Username'], 'ID' => $_SESSION['ID'], 'Date' => $_SESSION['Start Time'], 'Session' => $_SESSION['Session'], 'Condition_Number' => $_SESSION['Condition']['Number'], 'Condition_Description' => $_SESSION['Condition']['Condition Description'], 'Output_File' => $_PATH->getDefault('Output'), 'Stimuli_File' => $_SESSION['Condition']['Stimuli'], 'Procedure_File' => $_SESSION['Condition']['Procedure'], 'Browser' => $userAgent->Parent, 'DeviceType' => $userAgent->Device_Type, 'OS' => $userAgent->Platform, 'IP' => $_SERVER["REMOTE_ADDR"]); arrayToLine($UserData, $_PATH->get('Status Begin Data')); ########################################################################### #### Send participant to next phase of experiment (demographics or instructions) if ($_CONFIG->run_demographics == true) { $link = $_PATH->get('Basic Info'); } elseif ($_CONFIG->run_instructions) { $link = $_PATH->get('Instructions Page'); } else { $link = $_PATH->get('Experiment Page'); } if ($_CONFIG->stop_at_login == true) { // if things are going wrong this info will help you figure out when the program broke Readable($_SESSION['Condition'], 'Condition information'); Readable($stimuli, 'Stimuli file in use (' . $_PATH->get('Stimuli', 'root') . ')'); Readable($procedure, 'Procedure file in use (' . $_PATH->get('Procedure', 'root') . ')'); Readable($trialTypeColumns, 'Levels of trial types being used');
// setting up aliases for later use $allFQs =& $_SESSION['FinalQs']; $pos =& $_SESSION['FQpos']; $FQ =& $allFQs[$pos]; // all info about current final question $readablePos = $pos - 1; // capture data $formData = isset($_POST['formData']) ? $_POST['formData'] : ''; // it wouldn't be set, if they left all checkboxes blank $data = array('Username' => $_SESSION['Username'], 'ID' => $_SESSION['ID'], 'Trial' => $readablePos, 'Question' => $FQ['Question'], 'Type' => $FQ['Type'], 'RT' => $_POST['RT']); if (is_array($formData)) { foreach ($formData as $resp) { $data['Response'] = $resp; arrayToLine($data, $_PATH->final_questions_data); } } else { $data['Response'] = $formData; arrayToLine($data, $_PATH->final_questions_data); } $pos++; // advance position counter if (!isset($allFQs[$pos])) { // if there isn't a question coming up header("Location: " . $_PATH->get('Done')); // send to done.php exit; // don't run the code below } header("Location: " . $_PATH->get('Final Questions Page')); // send back to FinalQuestions.php before any HTML is sent exit;
<?php /* Collector A program for running experiments on the web Copyright 2012-2015 Mikey Garcia & Nate Kornell */ require 'initiateCollector.php'; $data = array('Username' => $_SESSION['Username'], 'ID' => $_SESSION['ID']) + $_POST; // write user demographics data to demographics file arrayToLine($data, $_PATH->demographics_data); if ($_CONFIG->run_instructions) { $next = $_PATH->get('Instructions Page'); } else { $next = $_PATH->get('Experiment Page'); } header("Location: {$next}"); exit;