rt300@22
|
1 //
|
rt300@22
|
2 // TrainingScoreManager.h
|
rt300@22
|
3 // riftathon
|
rt300@22
|
4 //
|
rt300@22
|
5 // Created by Robert Tubb on 23/10/2014.
|
rt300@22
|
6 //
|
rt300@22
|
7 //
|
rt300@22
|
8
|
rt300@22
|
9 #ifndef __riftathon__TrainingScoreManager__
|
rt300@22
|
10 #define __riftathon__TrainingScoreManager__
|
rt300@22
|
11
|
rt300@22
|
12 #include <iostream>
|
rt300@22
|
13 #include "ofMain.h"
|
rt300@22
|
14 #include "algorithms.h"
|
rt300@22
|
15 #include "globalVariables.h"
|
rt300@32
|
16 #include "eventLogger.h"
|
rt300@32
|
17
|
rt300@32
|
18 extern EventLogger eventLogger;
|
rt300@22
|
19 //-------------------------------------------------------------
|
rt300@22
|
20
|
rt300@22
|
21 struct TrainingTestResult{
|
rt300@22
|
22 float realDistanceToTarget;
|
rt300@22
|
23 int targetBandHit; // eg bullseye = 0 edge = 7
|
rt300@22
|
24 float timeAllowed;
|
rt300@22
|
25 int score;
|
rt300@22
|
26 ofColor colorBand;
|
rt300@22
|
27 string displayText;
|
rt300@29
|
28 float bits;
|
rt300@35
|
29 int difficultyLevel;
|
rt300@22
|
30 };
|
rt300@22
|
31
|
rt300@22
|
32 class TrainingScoreManager{
|
rt300@22
|
33
|
rt300@22
|
34 // equiv of score bit of testController
|
rt300@22
|
35 public:
|
rt300@35
|
36 TrainingScoreManager(){
|
rt300@35
|
37 totalScored = 0;
|
rt300@38
|
38 };
|
rt300@49
|
39 void reset(){
|
rt300@49
|
40 totalScored = 0;
|
rt300@49
|
41 };
|
rt300@38
|
42 int getBandForDistance(float dist) const{
|
rt300@38
|
43 int band = -1;
|
rt300@38
|
44 auto dimComp = sqrt(TOTAL_NUM_PARAMS);
|
rt300@38
|
45 if (dist < TARGET_SCORE_CC_BAND*dimComp){
|
rt300@38
|
46
|
rt300@38
|
47 band = 1;
|
rt300@38
|
48
|
rt300@38
|
49 }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){
|
rt300@38
|
50
|
rt300@38
|
51 band = 2;
|
rt300@38
|
52
|
rt300@38
|
53 }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){
|
rt300@38
|
54
|
rt300@38
|
55 band = 3;
|
rt300@38
|
56
|
rt300@38
|
57 }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){
|
rt300@38
|
58
|
rt300@38
|
59 band = 4;
|
rt300@38
|
60
|
rt300@38
|
61 }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30
|
rt300@38
|
62
|
rt300@38
|
63 band = 5;
|
rt300@38
|
64 }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45
|
rt300@38
|
65
|
rt300@43
|
66 band = 6;
|
rt300@38
|
67 }else{
|
rt300@38
|
68
|
rt300@38
|
69 band = 7;
|
rt300@38
|
70
|
rt300@38
|
71
|
rt300@38
|
72 }
|
rt300@38
|
73 return band;
|
rt300@38
|
74 };
|
rt300@38
|
75
|
rt300@38
|
76 string getMessageForBand(int band) const{
|
rt300@38
|
77 stringstream msg;
|
rt300@38
|
78 if (band == 1){
|
rt300@38
|
79
|
rt300@38
|
80 msg << "DOUBLE BULLSEYE!" << endl;
|
rt300@38
|
81
|
rt300@38
|
82
|
rt300@38
|
83 }else if (band == 2){
|
rt300@38
|
84
|
rt300@38
|
85
|
rt300@38
|
86 msg << "SINGLE BULLSEYE!" << endl;
|
rt300@38
|
87
|
rt300@38
|
88 }else if (band == 3){
|
rt300@38
|
89
|
rt300@38
|
90 msg << "CLOSE..." << endl;
|
rt300@38
|
91
|
rt300@38
|
92 }else if (band == 4){
|
rt300@38
|
93
|
rt300@38
|
94 msg << "OK...ISH" << endl;
|
rt300@38
|
95
|
rt300@38
|
96 }else if (band == 5){ // 30
|
rt300@38
|
97
|
rt300@38
|
98 msg << "MEDIOCRE" << endl;
|
rt300@38
|
99
|
rt300@38
|
100 }else if (band == 6){ // 45
|
rt300@38
|
101
|
rt300@38
|
102 msg << "POOR..." << endl;
|
rt300@38
|
103
|
rt300@38
|
104 }else{
|
rt300@38
|
105
|
rt300@38
|
106 msg << "MISSED COMPLETELY!" << endl;
|
rt300@38
|
107
|
rt300@38
|
108
|
rt300@38
|
109 }
|
rt300@38
|
110 return msg.str();
|
rt300@35
|
111 }
|
rt300@38
|
112 ofColor getColorForBand(int band) const {
|
rt300@38
|
113
|
rt300@38
|
114
|
rt300@38
|
115 ofColor c;
|
rt300@38
|
116 if(band == 1){
|
rt300@38
|
117
|
rt300@38
|
118 c = ofColor(255,255,0,255); // yellow 1
|
rt300@38
|
119 }else if(band == 2){
|
rt300@38
|
120 c = ofColor(255,0,0,255); // red 2
|
rt300@38
|
121 }else if(band == 3){
|
rt300@38
|
122 c = ofColor(45,45,255,255); // blue 3
|
rt300@38
|
123 }else if(band == 4){
|
rt300@38
|
124 c = ofColor(0,255,0,255); // green 4
|
rt300@38
|
125 }else{
|
rt300@38
|
126 c = ofColor(123,123,123,255); // grey worst
|
rt300@38
|
127 }
|
rt300@38
|
128 return c;
|
rt300@38
|
129 };
|
rt300@35
|
130 TrainingTestResult getScoreForAnswer(vector<int> targetParams,
|
rt300@35
|
131 vector<int> startPosition,
|
rt300@35
|
132 vector<int> answer,
|
rt300@35
|
133 int timeAllowed,
|
rt300@35
|
134 int difficulty,
|
rt300@35
|
135 int whichInSequence,
|
rt300@36
|
136 int presetIndex,
|
rt300@36
|
137 int tempoLevel,
|
rt300@43
|
138 int seqLength) {
|
rt300@22
|
139 TrainingTestResult result;
|
rt300@22
|
140 stringstream msg;
|
rt300@22
|
141 int score = 0;
|
rt300@22
|
142 // work out euc distance from actual point
|
rt300@36
|
143
|
rt300@36
|
144 float initDist = euclideanDistance(targetParams, startPosition);
|
rt300@22
|
145 float dist = euclideanDistance(targetParams, answer);
|
rt300@36
|
146 if (initDist <= 0) {
|
rt300@36
|
147 initDist = 0.001;
|
rt300@36
|
148 }
|
rt300@36
|
149 if (dist <= 0) dist = 0.001;
|
rt300@29
|
150 float TP = calculateThroughput(TOTAL_NUM_PARAMS, dist, initDist, timeAllowed/1000.);
|
rt300@36
|
151 cout << "Preset index " << presetIndex << endl;
|
rt300@36
|
152 cout << "whichInSequence " << whichInSequence << endl;
|
rt300@29
|
153
|
rt300@38
|
154 int band = getBandForDistance(dist);
|
rt300@38
|
155
|
rt300@38
|
156 msg << getMessageForBand(band) << endl;
|
rt300@38
|
157 msg << "Distance: " << dist << endl;
|
rt300@32
|
158 msg << "Score: " << round(TP*10) << endl;
|
rt300@39
|
159
|
rt300@22
|
160
|
rt300@22
|
161 result.realDistanceToTarget = dist;
|
rt300@22
|
162 result.targetBandHit = band; // eg bullseye = 0 edge = 7
|
rt300@22
|
163 result.timeAllowed = timeAllowed;
|
rt300@43
|
164 result.score = int(round(TP));
|
rt300@22
|
165 result.displayText = msg.str();
|
rt300@35
|
166 result.difficultyLevel = difficulty;
|
rt300@38
|
167 result.colorBand = getColorForBand(band);
|
rt300@22
|
168
|
rt300@37
|
169 if(result.score > 0) totalScored += result.score;
|
rt300@36
|
170
|
rt300@32
|
171
|
rt300@32
|
172 vector<int> details;
|
rt300@35
|
173
|
rt300@35
|
174 details.push_back(result.realDistanceToTarget*1000);
|
rt300@32
|
175 details.push_back(result.targetBandHit);
|
rt300@32
|
176 details.push_back(result.timeAllowed);
|
rt300@32
|
177 details.push_back(result.score); // 10 x throughput
|
rt300@35
|
178 details.push_back(difficulty);
|
rt300@35
|
179 details.push_back(whichInSequence);
|
rt300@35
|
180 details.push_back(initDist*1000);
|
rt300@35
|
181 details.push_back(presetIndex);
|
rt300@36
|
182 details.push_back(tempoLevel);
|
rt300@43
|
183 details.push_back(seqLength);
|
rt300@32
|
184 eventLogger.logEvent(TRAINING_RESULT, details);
|
rt300@34
|
185 details.clear();
|
rt300@34
|
186 details.insert(details.begin(), targetParams.begin(), targetParams.end());
|
rt300@34
|
187 details.insert(details.end(), answer.begin(), answer.end());
|
rt300@34
|
188 eventLogger.logEvent(TARGET_AND_MATCH, details);
|
rt300@22
|
189
|
rt300@22
|
190 return result;
|
rt300@22
|
191 }
|
rt300@32
|
192
|
rt300@36
|
193 int getScore(){
|
rt300@36
|
194 cout << "RUNNING SCORE: " << totalScored << endl;
|
rt300@36
|
195 return totalScored;
|
rt300@36
|
196 };
|
rt300@32
|
197
|
rt300@22
|
198 private:
|
rt300@32
|
199
|
rt300@32
|
200
|
rt300@29
|
201 float calculateThroughput(int numDims, float endDistance, float startDistance, float time) const{
|
rt300@36
|
202
|
rt300@29
|
203 float ISSR = numDims * log2( startDistance / endDistance);
|
rt300@32
|
204 cout << "==========Result======= " << endl;
|
rt300@29
|
205 cout << "start: " << startDistance << endl;
|
rt300@29
|
206 cout << "end: " << endDistance << endl;
|
rt300@29
|
207 cout << "ISSR: " << ISSR << endl;
|
rt300@32
|
208 cout << "time: " << time << endl;
|
rt300@29
|
209 float TP = ISSR / time;
|
rt300@32
|
210 cout << "TP: " << TP << endl;
|
rt300@29
|
211 return TP;
|
rt300@29
|
212 }
|
rt300@34
|
213
|
rt300@32
|
214 int totalScored;
|
rt300@22
|
215
|
rt300@22
|
216 };
|
rt300@22
|
217 #endif /* defined(__riftathon__TrainingScoreManager__) */
|