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