00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
#include <ptf/core/simplereactionhandler.hpp>
00019
#include <ptf/core/ptfcore.hpp>
00020
#include <iostream>
00021
00022
00023
using std::cout;
00024
using std::endl;
00025
00029 SimpleReactionHandler::SimpleReactionHandler() {
00030
lastRRec = 0;
00031 }
00032
00036 SimpleReactionHandler::~SimpleReactionHandler() {
00037
00038 }
00039
00043 void SimpleReactionHandler::handle() {
00044
00045
PtfCore& ptf =
PtfCore::getSingleton();
00046
00047
TaskRecord* taskRec = ptf.
getTaskRecords().back();
00048
00049
const vector<bool> buttonsSuccess = ptf.
getTasks()[taskRec->
getId()]->getSuccessfulReaction();
00050
00051 timespec executeStart, executeEnd, taskStart, taskEnd, dummy, reactionWindowStart, reactionWindowEnd;
00052 taskRec->
getTimestampE().
getInterval(executeStart, executeEnd);
00053 ptf.
getTasks()[taskRec->
getId()]->getReactionWindow().getInterval(reactionWindowStart, reactionWindowEnd);
00054 timespec windowStart =
TimeInterval::addTimespecs(executeEnd, reactionWindowStart);
00055 timespec windowEnd =
TimeInterval::addTimespecs(executeEnd, reactionWindowEnd);
00056
00057 taskRec->
getTimestampP().
getInterval(taskStart, dummy);
00058 taskRec->
getTimestampF().
getInterval(dummy, taskEnd);
00059
00060 ptf.
getReactionRecordsMutex().enterMutex();
00061
00062
if (
lastRRec == (
int)ptf.
getReactionRecords().size()) {
00063
00064
if ((
int)buttonsSuccess.size() == 0) {
00065
00066 ptf.
getHandlerLog() <<
"Reaction handler:\n"
00067 <<
"\tNo reactions. Correct.\n";
00068
00069 ptf.
getMachineLog() <<
lastRRec <<
" "
00070 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00071 << taskStart <<
" " << taskEnd <<
" "
00072 << windowStart <<
" "<< windowEnd
00073 <<
" 0 " <<
boolVectorToString(buttonsSuccess) <<
" 7 -1 -1 -1 -1\n";
00074 }
00075
else {
00076
00077 ptf.
getHandlerLog() <<
"Reaction handler:\n"
00078 <<
"\tNo reactions. Incorrect.\n";
00079
00080 ptf.
getMachineLog() <<
lastRRec <<
" "
00081 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00082 << taskStart <<
" " << taskEnd <<
" "
00083 << windowStart <<
" "<< windowEnd
00084 <<
" 0 " <<
boolVectorToString(buttonsSuccess) <<
" 8 -1 -1 -1 -1\n";
00085 }
00086 }
00087
else {
00088
00089
while (
lastRRec < (
int)ptf.
getReactionRecords().size()) {
00090
00091
ReactionRecord* reactRec = ptf.
getReactionRecords()[
lastRRec++];
00092
00093 ptf.
getReactionRecordsMutex().leaveMutex();
00094
00095
const vector<bool>& buttonsPressed = reactRec->
getButtonStates();
00096
00097 timespec reactionTime;
00098 reactRec->
getTimestamp().
getInterval(dummy, reactionTime);
00099
00100 timespec delta;
00101 delta =
TimeInterval::subTimespecs(reactionTime, windowStart);
00102
00103
if (
TimeInterval::compareTimespecs(reactionTime, taskStart) == -1) {
00104
00105 ptf.
getHandlerLog() <<
"Reaction handler:\n"
00106 <<
"\tReaction at " << reactRec->
getTimestamp().
toString() <<
"\n"
00107 <<
"\tTask at [" << taskStart <<
" | " << taskEnd <<
"]\n"
00108 <<
"\tWindow at [" << windowStart <<
" | " << windowEnd <<
"]\n"
00109 <<
"\tDelta to start of reaction window: " << delta <<
"\n"
00110 <<
"\tReaction was before start of task.\n";
00111
00112
if (buttonsPressed == buttonsSuccess) {
00113 ptf.
getHandlerLog() <<
"\tReaction was with right input.\n";
00114
00115 timespec a, b;
00116 reactRec->
getTimestamp().
getInterval(a, b);
00117 ptf.
getMachineLog() <<
lastRRec <<
" "
00118 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00119 << taskStart <<
" " << taskEnd <<
" "
00120 << windowStart <<
" " << windowEnd <<
" "
00121 <<
boolVectorToString(buttonsPressed) <<
" "
00122 <<
boolVectorToString(buttonsSuccess) <<
" 9 "
00123 << a <<
" " << b <<
"\n";
00124 }
00125
else {
00126 ptf.
getHandlerLog() <<
"\tReaction was with wrong input.\n";
00127
00128 timespec a, b;
00129 reactRec->
getTimestamp().
getInterval(a, b);
00130 ptf.
getMachineLog() <<
lastRRec <<
" "
00131 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00132 << taskStart <<
" " << taskEnd <<
" "
00133 << windowStart <<
" " << windowEnd <<
" "
00134 <<
boolVectorToString(buttonsPressed) <<
" "
00135 <<
boolVectorToString(buttonsSuccess) <<
" 10 "
00136 << a <<
" " << b <<
"\n";
00137 }
00138
00139 ptf.
getReactionRecordsMutex().enterMutex();
00140
continue;
00141 }
00142
if (
TimeInterval::compareTimespecs(reactionTime, taskEnd) == 1) {
00143
00144 ptf.
getHandlerLog() <<
"Reaction handler:\n"
00145 <<
"\tReaction at " << reactRec->
getTimestamp().
toString() <<
"\n"
00146 <<
"\tTask at [" << taskStart <<
" | " << taskEnd <<
"]\n"
00147 <<
"\tWindow at [" << windowStart <<
" | " << windowEnd <<
"]\n"
00148 <<
"\tDelta to start of reaction window: " << delta <<
"\n"
00149 <<
"\tReaction was after end of task.\n";
00150
00151
if (buttonsPressed == buttonsSuccess) {
00152 ptf.
getHandlerLog() <<
"\tReaction was with right input.\n";
00153
00154 timespec a, b;
00155 reactRec->
getTimestamp().
getInterval(a, b);
00156 ptf.
getMachineLog() <<
lastRRec <<
" "
00157 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00158 << taskStart <<
" " << taskEnd <<
" "
00159 << windowStart <<
" " << windowEnd <<
" "
00160 <<
boolVectorToString(buttonsPressed) <<
" "
00161 <<
boolVectorToString(buttonsSuccess) <<
" 11 "
00162 << a <<
" " << b <<
"\n";
00163 }
00164
else {
00165 ptf.
getHandlerLog() <<
"\tReaction was with wrong input.\n";
00166
00167 timespec a, b;
00168 reactRec->
getTimestamp().
getInterval(a, b);
00169 ptf.
getMachineLog() <<
lastRRec <<
" "
00170 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00171 << taskStart <<
" " << taskEnd <<
" "
00172 << windowStart <<
" " << windowEnd <<
" "
00173 <<
boolVectorToString(buttonsPressed) <<
" "
00174 <<
boolVectorToString(buttonsSuccess) <<
" 12 "
00175 << a <<
" " << b <<
"\n";
00176 }
00177
00178 ptf.
getReactionRecordsMutex().enterMutex();
00179
continue;
00180 }
00181
if (
TimeInterval::compareTimespecs(reactionTime, windowStart) == -1) {
00182
00183 ptf.
getHandlerLog() <<
"Reaction handler:\n"
00184 <<
"\tReaction at " << reactRec->
getTimestamp().
toString() <<
"\n"
00185 <<
"\tTask at [" << taskStart <<
" | " << taskEnd <<
"]\n"
00186 <<
"\tWindow at [" << windowStart <<
" | " << windowEnd <<
"]\n"
00187 <<
"\tDelta to start of reaction window: " << delta <<
"\n"
00188 <<
"\tReaction was before start of reaction window.\n";
00189
00190
if (buttonsPressed == buttonsSuccess) {
00191 ptf.
getHandlerLog() <<
"\tReaction was with right input.\n";
00192
00193 timespec a, b;
00194 reactRec->
getTimestamp().
getInterval(a, b);
00195 ptf.
getMachineLog() <<
lastRRec <<
" "
00196 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00197 << taskStart <<
" " << taskEnd <<
" "
00198 << windowStart <<
" " << windowEnd <<
" "
00199 <<
boolVectorToString(buttonsPressed) <<
" "
00200 <<
boolVectorToString(buttonsSuccess) <<
" 3 "
00201 << a <<
" " << b <<
"\n";
00202 }
00203
else {
00204 ptf.
getHandlerLog() <<
"\tReaction was with wrong input.\n";
00205
00206 timespec a, b;
00207 reactRec->
getTimestamp().
getInterval(a, b);
00208 ptf.
getMachineLog() <<
lastRRec <<
" "
00209 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00210 << taskStart <<
" " << taskEnd <<
" "
00211 << windowStart <<
" " << windowEnd <<
" "
00212 <<
boolVectorToString(buttonsPressed) <<
" "
00213 <<
boolVectorToString(buttonsSuccess) <<
" 4 "
00214 << a <<
" " << b <<
"\n";
00215 }
00216
00217 ptf.
getReactionRecordsMutex().enterMutex();
00218
continue;
00219 }
00220
if (
TimeInterval::compareTimespecs(reactionTime, windowEnd) == 1) {
00221
00222 ptf.
getHandlerLog() <<
"Reaction handler:\n"
00223 <<
"\tReaction at " << reactRec->
getTimestamp().
toString() <<
"\n"
00224 <<
"\tTask at [" << taskStart <<
" | " << taskEnd <<
"]\n"
00225 <<
"\tWindow at [" << windowStart <<
" | " << windowEnd <<
"]\n"
00226 <<
"\tDelta to start of reaction window: " << delta <<
"\n"
00227 <<
"\tReaction was after end of reaction window.\n";
00228
00229
if (buttonsPressed == buttonsSuccess) {
00230 ptf.
getHandlerLog() <<
"\tReaction was with right input.\n";
00231
00232 timespec a, b;
00233 reactRec->
getTimestamp().
getInterval(a, b);
00234 ptf.
getMachineLog() <<
lastRRec <<
" "
00235 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00236 << taskStart <<
" " << taskEnd <<
" "
00237 << windowStart <<
" " << windowEnd <<
" "
00238 <<
boolVectorToString(buttonsPressed) <<
" "
00239 <<
boolVectorToString(buttonsSuccess) <<
" 5 "
00240 << a <<
" " << b <<
"\n";
00241 }
00242
else {
00243 ptf.
getHandlerLog() <<
"\tReaction was with wrong input.\n";
00244
00245 timespec a, b;
00246 reactRec->
getTimestamp().
getInterval(a, b);
00247 ptf.
getMachineLog() <<
lastRRec <<
" "
00248 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00249 << taskStart <<
" " << taskEnd <<
" "
00250 << windowStart <<
" " << windowEnd <<
" "
00251 <<
boolVectorToString(buttonsPressed) <<
" "
00252 <<
boolVectorToString(buttonsSuccess) <<
" 6 "
00253 << a <<
" " << b <<
"\n";
00254 }
00255
00256 ptf.
getReactionRecordsMutex().enterMutex();
00257
continue;
00258 }
00259
00260 ptf.
getHandlerLog() <<
"Reaction handler:\n"
00261 <<
"\tReaction at " << reactRec->
getTimestamp().
toString() <<
"\n"
00262 <<
"\tTask at [" << taskStart <<
" | " << taskEnd <<
"]\n"
00263 <<
"\tWindow at [" << windowStart <<
" | " << windowEnd <<
"]\n"
00264 <<
"\tDelta to start of reaction window: " << delta <<
"\n"
00265 <<
"\tReaction was in reaction window.\n";
00266
00267
if (buttonsPressed == buttonsSuccess) {
00268 ptf.
getHandlerLog() <<
"\tReaction was with right input.\n";
00269
00270 timespec a, b;
00271 reactRec->
getTimestamp().
getInterval(a, b);
00272 ptf.
getMachineLog() <<
lastRRec <<
" "
00273 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00274 << taskStart <<
" " << taskEnd <<
" "
00275 << windowStart <<
" " << windowEnd <<
" "
00276 <<
boolVectorToString(buttonsPressed) <<
" "
00277 <<
boolVectorToString(buttonsSuccess) <<
" 1 "
00278 << a <<
" " << b <<
"\n";
00279 }
00280
else {
00281 ptf.
getHandlerLog() <<
"\tReaction was with wrong input.\n";
00282
00283 timespec a, b;
00284 reactRec->
getTimestamp().
getInterval(a, b);
00285 ptf.
getMachineLog() <<
lastRRec <<
" "
00286 << (
int)ptf.
getTaskRecords().size() <<
" " << taskRec->
getId() <<
" "
00287 << taskStart <<
" " << taskEnd <<
" "
00288 << windowStart <<
" " << windowEnd <<
" "
00289 <<
boolVectorToString(buttonsPressed) <<
" "
00290 <<
boolVectorToString(buttonsSuccess) <<
" 2 "
00291 << a <<
" " << b <<
"\n";
00292 }
00293
00294 ptf.
getReactionRecordsMutex().enterMutex();
00295 }
00296 }
00297
00298 ptf.
getReactionRecordsMutex().leaveMutex();
00299 }
00300
00305 string
SimpleReactionHandler::boolVectorToString(
const vector<bool>& in) {
00306 string result =
"";
00307
if ((
int)in.size() == 0) {
00308 result =
"0";
00309
return result;
00310 }
00311
for (
int i = 0; i < (
int)in.size(); i++) {
00312 in[i] ? result +=
"1" : result +=
"0";
00313 }
00314
return result;
00315 }
00316