Mercurial > hg > tweakathon2ios
comparison TrainingScoreManager.h @ 32:75202498bee9
perform mode (no guides at all)
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Tue, 25 Nov 2014 17:03:33 +0000 |
parents | a677c027e3a0 |
children | 3af380769779 |
comparison
equal
deleted
inserted
replaced
31:a677c027e3a0 | 32:75202498bee9 |
---|---|
12 #include <iostream> | 12 #include <iostream> |
13 #include "ofMain.h" | 13 #include "ofMain.h" |
14 //#include "SequenceController.h" | 14 //#include "SequenceController.h" |
15 #include "algorithms.h" | 15 #include "algorithms.h" |
16 #include "globalVariables.h" | 16 #include "globalVariables.h" |
17 #include "eventLogger.h" | |
18 | |
19 extern EventLogger eventLogger; | |
17 //------------------------------------------------------------- | 20 //------------------------------------------------------------- |
18 | 21 |
19 struct TrainingTestResult{ | 22 struct TrainingTestResult{ |
20 float realDistanceToTarget; | 23 float realDistanceToTarget; |
21 int targetBandHit; // eg bullseye = 0 edge = 7 | 24 int targetBandHit; // eg bullseye = 0 edge = 7 |
29 class TrainingScoreManager{ | 32 class TrainingScoreManager{ |
30 | 33 |
31 // equiv of score bit of testController | 34 // equiv of score bit of testController |
32 public: | 35 public: |
33 | 36 |
34 TrainingTestResult getScoreForAnswer(vector<int> targetParams, vector<int> startPosition, vector<int> answer, int timeAllowed) const { | 37 |
38 TrainingTestResult getScoreForAnswer(vector<int> targetParams, vector<int> startPosition, vector<int> answer, int timeAllowed) { | |
35 TrainingTestResult result; | 39 TrainingTestResult result; |
36 stringstream msg; | 40 stringstream msg; |
37 int score = 0; | 41 int score = 0; |
38 // work out euc distance from actual point | 42 // work out euc distance from actual point |
39 //for_each(answer.begin(),answer.end(),printThing<int>()); | 43 //for_each(answer.begin(),answer.end(),printThing<int>()); |
40 //for_each(targetParams.begin(),targetParams.end(),printThing<int>()); | 44 //for_each(targetParams.begin(),targetParams.end(),printThing<int>()); |
41 float initDist = euclideanDistance(startPosition, answer); | 45 float initDist = euclideanDistance(startPosition, answer); |
42 float dist = euclideanDistance(targetParams, answer); | 46 float dist = euclideanDistance(targetParams, answer); |
43 | 47 |
44 float TP = calculateThroughput(TOTAL_NUM_PARAMS, dist, initDist, timeAllowed/1000.); | 48 float TP = calculateThroughput(TOTAL_NUM_PARAMS, dist, initDist, timeAllowed/1000.); |
45 | |
46 cout << TP << endl; | |
47 | 49 |
48 auto dimComp = sqrt(TOTAL_NUM_PARAMS); | 50 auto dimComp = sqrt(TOTAL_NUM_PARAMS); |
49 int band = -1; | 51 int band = -1; |
50 if (dist < TARGET_SCORE_CC_BAND*dimComp){ | 52 if (dist < TARGET_SCORE_CC_BAND*dimComp){ |
51 score = 50; | 53 score = 50; |
88 msg << "MISSED COMPLETELY!" << endl; | 90 msg << "MISSED COMPLETELY!" << endl; |
89 | 91 |
90 | 92 |
91 } | 93 } |
92 msg << "Distance from target: " << dist << endl; | 94 msg << "Distance from target: " << dist << endl; |
93 msg << "Basic Score: " << round(TP*10) << endl; | 95 msg << "Score: " << round(TP*10) << endl; |
94 msg << "-----" << endl; | 96 msg << "-----" << endl; |
95 msg << "Time allowed: " << timeAllowed/1000.0 << endl; | 97 msg << "Time allowed: " << timeAllowed/1000.0 << endl; |
96 | 98 |
97 msg << "-----" << endl; | 99 msg << "-----" << endl; |
98 | 100 |
115 }else{ | 117 }else{ |
116 c = ofColor(150,235,200,255); | 118 c = ofColor(150,235,200,255); |
117 } | 119 } |
118 result.colorBand = c; | 120 result.colorBand = c; |
119 | 121 |
122 totalScored += score; | |
123 | |
124 vector<int> details; | |
125 details.push_back(result.realDistanceToTarget); | |
126 details.push_back(result.targetBandHit); | |
127 details.push_back(result.timeAllowed); | |
128 details.push_back(result.score); // 10 x throughput | |
129 | |
130 eventLogger.logEvent(TRAINING_RESULT, details); | |
131 | |
120 | 132 |
121 return result; | 133 return result; |
122 } | 134 } |
135 | |
136 int getScore(){return totalScored;}; | |
137 | |
123 private: | 138 private: |
139 | |
140 | |
124 float calculateThroughput(int numDims, float endDistance, float startDistance, float time) const{ | 141 float calculateThroughput(int numDims, float endDistance, float startDistance, float time) const{ |
125 | 142 |
126 float ISSR = numDims * log2( startDistance / endDistance); | 143 float ISSR = numDims * log2( startDistance / endDistance); |
144 cout << "==========Result======= " << endl; | |
127 cout << "start: " << startDistance << endl; | 145 cout << "start: " << startDistance << endl; |
128 cout << "end: " << endDistance << endl; | 146 cout << "end: " << endDistance << endl; |
129 cout << "ISSR: " << ISSR << endl; | 147 cout << "ISSR: " << ISSR << endl; |
148 cout << "time: " << time << endl; | |
130 float TP = ISSR / time; | 149 float TP = ISSR / time; |
150 cout << "TP: " << TP << endl; | |
131 return TP; | 151 return TP; |
132 } | 152 } |
133 float euclideanDistance(vector<int> v1, vector<int> v2) const{ | 153 float euclideanDistance(vector<int> v1, vector<int> v2) const{ |
134 if (v1.size() != v2.size()){ | 154 if (v1.size() != v2.size()){ |
135 cout << "ERROR ERROR: vectors must be same length for Mr Euclid"; | 155 cout << "ERROR ERROR: vectors must be same length for Mr Euclid"; |
144 float ans = std::accumulate(v1.begin(),v1.end(),0.0); | 164 float ans = std::accumulate(v1.begin(),v1.end(),0.0); |
145 | 165 |
146 return sqrt(ans); | 166 return sqrt(ans); |
147 | 167 |
148 }; | 168 }; |
169 int totalScored; | |
149 | 170 |
150 }; | 171 }; |
151 #endif /* defined(__riftathon__TrainingScoreManager__) */ | 172 #endif /* defined(__riftathon__TrainingScoreManager__) */ |