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