Mercurial > hg > tweakathon2ios
comparison TrainingScoreManager.h @ 35:3b10a26da293
refactoring and log
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 26 Nov 2014 18:18:20 +0000 |
parents | 3af380769779 |
children | 146033869165 |
comparison
equal
deleted
inserted
replaced
34:3af380769779 | 35:3b10a26da293 |
---|---|
9 #ifndef __riftathon__TrainingScoreManager__ | 9 #ifndef __riftathon__TrainingScoreManager__ |
10 #define __riftathon__TrainingScoreManager__ | 10 #define __riftathon__TrainingScoreManager__ |
11 | 11 |
12 #include <iostream> | 12 #include <iostream> |
13 #include "ofMain.h" | 13 #include "ofMain.h" |
14 //#include "SequenceController.h" | |
15 #include "algorithms.h" | 14 #include "algorithms.h" |
16 #include "globalVariables.h" | 15 #include "globalVariables.h" |
17 #include "eventLogger.h" | 16 #include "eventLogger.h" |
18 | 17 |
19 extern EventLogger eventLogger; | 18 extern EventLogger eventLogger; |
25 float timeAllowed; | 24 float timeAllowed; |
26 int score; | 25 int score; |
27 ofColor colorBand; | 26 ofColor colorBand; |
28 string displayText; | 27 string displayText; |
29 float bits; | 28 float bits; |
29 int difficultyLevel; | |
30 }; | 30 }; |
31 | 31 |
32 class TrainingScoreManager{ | 32 class TrainingScoreManager{ |
33 | 33 |
34 // equiv of score bit of testController | 34 // equiv of score bit of testController |
35 public: | 35 public: |
36 TrainingScoreManager(){ | |
37 totalScored = 0; | |
38 } | |
36 | 39 |
37 | 40 TrainingTestResult getScoreForAnswer(vector<int> targetParams, |
38 TrainingTestResult getScoreForAnswer(vector<int> targetParams, vector<int> startPosition, vector<int> answer, int timeAllowed) { | 41 vector<int> startPosition, |
42 vector<int> answer, | |
43 int timeAllowed, | |
44 int difficulty, | |
45 int whichInSequence, | |
46 int presetIndex) { | |
39 TrainingTestResult result; | 47 TrainingTestResult result; |
40 stringstream msg; | 48 stringstream msg; |
41 int score = 0; | 49 int score = 0; |
42 // work out euc distance from actual point | 50 // work out euc distance from actual point |
43 //for_each(answer.begin(),answer.end(),printThing<int>()); | 51 //for_each(answer.begin(),answer.end(),printThing<int>()); |
44 //for_each(targetParams.begin(),targetParams.end(),printThing<int>()); | 52 //for_each(targetParams.begin(),targetParams.end(),printThing<int>()); |
45 float initDist = euclideanDistance(startPosition, answer); | 53 float initDist = euclideanDistance(startPosition, answer); |
46 float dist = euclideanDistance(targetParams, answer); | 54 float dist = euclideanDistance(targetParams, answer); |
47 | |
48 float TP = calculateThroughput(TOTAL_NUM_PARAMS, dist, initDist, timeAllowed/1000.); | 55 float TP = calculateThroughput(TOTAL_NUM_PARAMS, dist, initDist, timeAllowed/1000.); |
49 | 56 |
50 auto dimComp = sqrt(TOTAL_NUM_PARAMS); | 57 auto dimComp = sqrt(TOTAL_NUM_PARAMS); |
51 int band = -1; | 58 int band = -1; |
52 if (dist < TARGET_SCORE_CC_BAND*dimComp){ | 59 if (dist < TARGET_SCORE_CC_BAND*dimComp){ |
53 score = 50; | 60 |
54 band = 1; | 61 band = 1; |
55 | 62 |
56 msg << "DOUBLE BULLSEYE!" << endl; | 63 msg << "DOUBLE BULLSEYE!" << endl; |
57 | 64 |
58 | 65 |
59 }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){ | 66 }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){ |
60 | 67 |
61 score = 25; | |
62 band = 2; | 68 band = 2; |
63 | 69 |
64 msg << "SINGLE BULLSEYE!" << endl; | 70 msg << "SINGLE BULLSEYE!" << endl; |
65 | 71 |
66 }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){ | 72 }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){ |
67 | 73 |
68 score = 15; | |
69 band = 3; | 74 band = 3; |
70 msg << "CLOSE..." << endl; | 75 msg << "CLOSE..." << endl; |
71 | 76 |
72 }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){ | 77 }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){ |
73 score = 5; | 78 |
74 band = 4; | 79 band = 4; |
75 msg << "OK...ISH" << endl; | 80 msg << "OK...ISH" << endl; |
76 | 81 |
77 }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30 | 82 }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30 |
78 score = 2; | 83 |
79 band = 5; | 84 band = 5; |
80 msg << "MEDIOCRE" << endl; | 85 msg << "MEDIOCRE" << endl; |
81 | 86 |
82 }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45 | 87 }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45 |
83 score = 1; | 88 |
84 band = 6; | 89 band = 6; |
85 msg << "POOR..." << endl; | 90 msg << "POOR..." << endl; |
86 | 91 |
87 }else{ | 92 }else{ |
88 score = 0; | 93 |
89 band = 7; | 94 band = 7; |
90 msg << "MISSED COMPLETELY!" << endl; | 95 msg << "MISSED COMPLETELY!" << endl; |
91 | 96 |
92 | 97 |
93 } | 98 } |
101 result.realDistanceToTarget = dist; | 106 result.realDistanceToTarget = dist; |
102 result.targetBandHit = band; // eg bullseye = 0 edge = 7 | 107 result.targetBandHit = band; // eg bullseye = 0 edge = 7 |
103 result.timeAllowed = timeAllowed; | 108 result.timeAllowed = timeAllowed; |
104 result.score = round(TP*10); | 109 result.score = round(TP*10); |
105 result.displayText = msg.str(); | 110 result.displayText = msg.str(); |
111 result.difficultyLevel = difficulty; | |
112 | |
106 | 113 |
107 ofColor c; | 114 ofColor c; |
108 if(result.targetBandHit == 1){ | 115 if(result.targetBandHit == 1){ |
109 // yellow red blue | 116 |
110 c = ofColor(255,255,0,255); | 117 c = ofColor(255,255,0,255); // yellow 1 |
111 }else if(result.targetBandHit == 2){ | 118 }else if(result.targetBandHit == 2){ |
112 c = ofColor(255,0,0,255); | 119 c = ofColor(255,0,0,255); // red 2 |
113 }else if(result.targetBandHit == 3){ | 120 }else if(result.targetBandHit == 3){ |
114 c = ofColor(45,45,255,255); | 121 c = ofColor(45,45,255,255); // blue 3 |
115 }else if(result.targetBandHit == 4){ | 122 }else if(result.targetBandHit == 4){ |
116 c = ofColor(0,255,0,255); | 123 c = ofColor(0,255,0,255); // green 4 |
117 }else{ | 124 }else{ |
118 c = ofColor(150,235,200,255); | 125 c = ofColor(0,0,0,255); // black worst |
119 } | 126 } |
120 result.colorBand = c; | 127 result.colorBand = c; |
121 | 128 |
122 totalScored += score; | 129 totalScored += score; |
123 | 130 |
124 vector<int> details; | 131 vector<int> details; |
125 details.push_back(result.realDistanceToTarget); | 132 |
133 details.push_back(result.realDistanceToTarget*1000); | |
126 details.push_back(result.targetBandHit); | 134 details.push_back(result.targetBandHit); |
127 details.push_back(result.timeAllowed); | 135 details.push_back(result.timeAllowed); |
128 details.push_back(result.score); // 10 x throughput | 136 details.push_back(result.score); // 10 x throughput |
137 details.push_back(difficulty); | |
138 details.push_back(whichInSequence); | |
139 details.push_back(initDist*1000); | |
140 details.push_back(presetIndex); | |
129 | 141 |
130 eventLogger.logEvent(TRAINING_RESULT, details); | 142 eventLogger.logEvent(TRAINING_RESULT, details); |
131 details.clear(); | 143 details.clear(); |
132 details.insert(details.begin(), targetParams.begin(), targetParams.end()); | 144 details.insert(details.begin(), targetParams.begin(), targetParams.end()); |
133 details.insert(details.end(), answer.begin(), answer.end()); | 145 details.insert(details.end(), answer.begin(), answer.end()); |
140 | 152 |
141 private: | 153 private: |
142 | 154 |
143 | 155 |
144 float calculateThroughput(int numDims, float endDistance, float startDistance, float time) const{ | 156 float calculateThroughput(int numDims, float endDistance, float startDistance, float time) const{ |
145 | 157 if (startDistance == 0) startDistance = 1; |
158 if (endDistance == 0) endDistance = 1; | |
146 float ISSR = numDims * log2( startDistance / endDistance); | 159 float ISSR = numDims * log2( startDistance / endDistance); |
147 cout << "==========Result======= " << endl; | 160 cout << "==========Result======= " << endl; |
148 cout << "start: " << startDistance << endl; | 161 cout << "start: " << startDistance << endl; |
149 cout << "end: " << endDistance << endl; | 162 cout << "end: " << endDistance << endl; |
150 cout << "ISSR: " << ISSR << endl; | 163 cout << "ISSR: " << ISSR << endl; |