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@31
|
14 //#include "SequenceController.h"
|
rt300@22
|
15 #include "algorithms.h"
|
rt300@22
|
16 #include "globalVariables.h"
|
rt300@32
|
17 #include "eventLogger.h"
|
rt300@32
|
18
|
rt300@32
|
19 extern EventLogger eventLogger;
|
rt300@22
|
20 //-------------------------------------------------------------
|
rt300@22
|
21
|
rt300@22
|
22 struct TrainingTestResult{
|
rt300@22
|
23 float realDistanceToTarget;
|
rt300@22
|
24 int targetBandHit; // eg bullseye = 0 edge = 7
|
rt300@22
|
25 float timeAllowed;
|
rt300@22
|
26 int score;
|
rt300@22
|
27 ofColor colorBand;
|
rt300@22
|
28 string displayText;
|
rt300@29
|
29 float bits;
|
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@22
|
36
|
rt300@32
|
37
|
rt300@32
|
38 TrainingTestResult getScoreForAnswer(vector<int> targetParams, vector<int> startPosition, vector<int> answer, int timeAllowed) {
|
rt300@22
|
39 TrainingTestResult result;
|
rt300@22
|
40 stringstream msg;
|
rt300@22
|
41 int score = 0;
|
rt300@22
|
42 // work out euc distance from actual point
|
rt300@22
|
43 //for_each(answer.begin(),answer.end(),printThing<int>());
|
rt300@22
|
44 //for_each(targetParams.begin(),targetParams.end(),printThing<int>());
|
rt300@29
|
45 float initDist = euclideanDistance(startPosition, answer);
|
rt300@22
|
46 float dist = euclideanDistance(targetParams, answer);
|
rt300@29
|
47
|
rt300@29
|
48 float TP = calculateThroughput(TOTAL_NUM_PARAMS, dist, initDist, timeAllowed/1000.);
|
rt300@29
|
49
|
rt300@29
|
50 auto dimComp = sqrt(TOTAL_NUM_PARAMS);
|
rt300@22
|
51 int band = -1;
|
rt300@22
|
52 if (dist < TARGET_SCORE_CC_BAND*dimComp){
|
rt300@22
|
53 score = 50;
|
rt300@22
|
54 band = 1;
|
rt300@22
|
55
|
rt300@22
|
56 msg << "DOUBLE BULLSEYE!" << endl;
|
rt300@22
|
57
|
rt300@22
|
58
|
rt300@22
|
59 }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){
|
rt300@22
|
60
|
rt300@22
|
61 score = 25;
|
rt300@22
|
62 band = 2;
|
rt300@22
|
63
|
rt300@22
|
64 msg << "SINGLE BULLSEYE!" << endl;
|
rt300@22
|
65
|
rt300@22
|
66 }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){
|
rt300@22
|
67
|
rt300@22
|
68 score = 15;
|
rt300@22
|
69 band = 3;
|
rt300@22
|
70 msg << "CLOSE..." << endl;
|
rt300@22
|
71
|
rt300@22
|
72 }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){
|
rt300@22
|
73 score = 5;
|
rt300@22
|
74 band = 4;
|
rt300@22
|
75 msg << "OK...ISH" << endl;
|
rt300@22
|
76
|
rt300@22
|
77 }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30
|
rt300@22
|
78 score = 2;
|
rt300@22
|
79 band = 5;
|
rt300@22
|
80 msg << "MEDIOCRE" << endl;
|
rt300@22
|
81
|
rt300@22
|
82 }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45
|
rt300@22
|
83 score = 1;
|
rt300@22
|
84 band = 6;
|
rt300@22
|
85 msg << "POOR..." << endl;
|
rt300@22
|
86
|
rt300@22
|
87 }else{
|
rt300@22
|
88 score = 0;
|
rt300@22
|
89 band = 7;
|
rt300@22
|
90 msg << "MISSED COMPLETELY!" << endl;
|
rt300@22
|
91
|
rt300@22
|
92
|
rt300@22
|
93 }
|
rt300@22
|
94 msg << "Distance from target: " << dist << endl;
|
rt300@32
|
95 msg << "Score: " << round(TP*10) << endl;
|
rt300@22
|
96 msg << "-----" << endl;
|
rt300@22
|
97 msg << "Time allowed: " << timeAllowed/1000.0 << endl;
|
rt300@22
|
98
|
rt300@22
|
99 msg << "-----" << endl;
|
rt300@22
|
100
|
rt300@22
|
101 result.realDistanceToTarget = dist;
|
rt300@22
|
102 result.targetBandHit = band; // eg bullseye = 0 edge = 7
|
rt300@22
|
103 result.timeAllowed = timeAllowed;
|
rt300@30
|
104 result.score = round(TP*10);
|
rt300@22
|
105 result.displayText = msg.str();
|
rt300@22
|
106
|
rt300@22
|
107 ofColor c;
|
rt300@22
|
108 if(result.targetBandHit == 1){
|
rt300@22
|
109 // yellow red blue
|
rt300@22
|
110 c = ofColor(255,255,0,255);
|
rt300@22
|
111 }else if(result.targetBandHit == 2){
|
rt300@22
|
112 c = ofColor(255,0,0,255);
|
rt300@22
|
113 }else if(result.targetBandHit == 3){
|
rt300@22
|
114 c = ofColor(45,45,255,255);
|
rt300@22
|
115 }else if(result.targetBandHit == 4){
|
rt300@22
|
116 c = ofColor(0,255,0,255);
|
rt300@22
|
117 }else{
|
rt300@22
|
118 c = ofColor(150,235,200,255);
|
rt300@22
|
119 }
|
rt300@22
|
120 result.colorBand = c;
|
rt300@22
|
121
|
rt300@32
|
122 totalScored += score;
|
rt300@32
|
123
|
rt300@32
|
124 vector<int> details;
|
rt300@32
|
125 details.push_back(result.realDistanceToTarget);
|
rt300@32
|
126 details.push_back(result.targetBandHit);
|
rt300@32
|
127 details.push_back(result.timeAllowed);
|
rt300@32
|
128 details.push_back(result.score); // 10 x throughput
|
rt300@32
|
129
|
rt300@32
|
130 eventLogger.logEvent(TRAINING_RESULT, details);
|
rt300@32
|
131
|
rt300@22
|
132
|
rt300@22
|
133 return result;
|
rt300@22
|
134 }
|
rt300@32
|
135
|
rt300@32
|
136 int getScore(){return totalScored;};
|
rt300@32
|
137
|
rt300@22
|
138 private:
|
rt300@32
|
139
|
rt300@32
|
140
|
rt300@29
|
141 float calculateThroughput(int numDims, float endDistance, float startDistance, float time) const{
|
rt300@29
|
142
|
rt300@29
|
143 float ISSR = numDims * log2( startDistance / endDistance);
|
rt300@32
|
144 cout << "==========Result======= " << endl;
|
rt300@29
|
145 cout << "start: " << startDistance << endl;
|
rt300@29
|
146 cout << "end: " << endDistance << endl;
|
rt300@29
|
147 cout << "ISSR: " << ISSR << endl;
|
rt300@32
|
148 cout << "time: " << time << endl;
|
rt300@29
|
149 float TP = ISSR / time;
|
rt300@32
|
150 cout << "TP: " << TP << endl;
|
rt300@29
|
151 return TP;
|
rt300@29
|
152 }
|
rt300@22
|
153 float euclideanDistance(vector<int> v1, vector<int> v2) const{
|
rt300@22
|
154 if (v1.size() != v2.size()){
|
rt300@22
|
155 cout << "ERROR ERROR: vectors must be same length for Mr Euclid";
|
rt300@22
|
156 return 0.;
|
rt300@22
|
157 }
|
rt300@22
|
158 vector<float> diff;
|
rt300@22
|
159
|
rt300@22
|
160 std::transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), difference<float>());
|
rt300@22
|
161 // sqr diff
|
rt300@22
|
162
|
rt300@22
|
163 std::transform(v1.begin(), v1.end(), v1.begin(),squared<float>());
|
rt300@22
|
164 float ans = std::accumulate(v1.begin(),v1.end(),0.0);
|
rt300@22
|
165
|
rt300@22
|
166 return sqrt(ans);
|
rt300@22
|
167
|
rt300@22
|
168 };
|
rt300@32
|
169 int totalScored;
|
rt300@22
|
170
|
rt300@22
|
171 };
|
rt300@22
|
172 #endif /* defined(__riftathon__TrainingScoreManager__) */
|