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