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