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