Mercurial > hg > tweakathon2ios
view TrainingScoreManager.h @ 38:fea11c3d1d94
tweaking endlessly
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Thu, 04 Dec 2014 17:03:01 +0000 |
parents | 52dbd5b4cfa9 |
children | 96ff7b41923a |
line wrap: on
line source
// // TrainingScoreManager.h // riftathon // // Created by Robert Tubb on 23/10/2014. // // #ifndef __riftathon__TrainingScoreManager__ #define __riftathon__TrainingScoreManager__ #include <iostream> #include "ofMain.h" #include "algorithms.h" #include "globalVariables.h" #include "eventLogger.h" extern EventLogger eventLogger; //------------------------------------------------------------- struct TrainingTestResult{ float realDistanceToTarget; int targetBandHit; // eg bullseye = 0 edge = 7 float timeAllowed; int score; ofColor colorBand; string displayText; float bits; int difficultyLevel; }; class TrainingScoreManager{ // equiv of score bit of testController public: TrainingScoreManager(){ totalScored = 0; }; int getBandForDistance(float dist) const{ int band = -1; auto dimComp = sqrt(TOTAL_NUM_PARAMS); if (dist < TARGET_SCORE_CC_BAND*dimComp){ band = 1; }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){ band = 2; }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){ band = 3; }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){ band = 4; }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30 band = 5; }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45 band = 6; }else{ band = 7; } return band; }; string getMessageForBand(int band) const{ stringstream msg; if (band == 1){ msg << "DOUBLE BULLSEYE!" << endl; }else if (band == 2){ msg << "SINGLE BULLSEYE!" << endl; }else if (band == 3){ msg << "CLOSE..." << endl; }else if (band == 4){ msg << "OK...ISH" << endl; }else if (band == 5){ // 30 msg << "MEDIOCRE" << endl; }else if (band == 6){ // 45 msg << "POOR..." << endl; }else{ msg << "MISSED COMPLETELY!" << endl; } return msg.str(); } ofColor getColorForBand(int band) const { ofColor c; if(band == 1){ c = ofColor(255,255,0,255); // yellow 1 }else if(band == 2){ c = ofColor(255,0,0,255); // red 2 }else if(band == 3){ c = ofColor(45,45,255,255); // blue 3 }else if(band == 4){ c = ofColor(0,255,0,255); // green 4 }else{ c = ofColor(123,123,123,255); // grey worst } return c; }; TrainingTestResult getScoreForAnswer(vector<int> targetParams, vector<int> startPosition, vector<int> answer, int timeAllowed, int difficulty, int whichInSequence, int presetIndex, int tempoLevel, int runNumber) { TrainingTestResult result; stringstream msg; int score = 0; // work out euc distance from actual point float initDist = euclideanDistance(targetParams, startPosition); float dist = euclideanDistance(targetParams, answer); if (initDist <= 0) { initDist = 0.001; } if (dist <= 0) dist = 0.001; float TP = calculateThroughput(TOTAL_NUM_PARAMS, dist, initDist, timeAllowed/1000.); cout << "Preset index " << presetIndex << endl; cout << "whichInSequence " << whichInSequence << endl; int band = getBandForDistance(dist); msg << getMessageForBand(band) << endl; msg << "Distance: " << dist << endl; msg << "Score: " << round(TP*10) << endl; msg << "-----" << endl; msg << "Time allowed: " << timeAllowed/1000.0 << endl; msg << "-----" << endl; result.realDistanceToTarget = dist; result.targetBandHit = band; // eg bullseye = 0 edge = 7 result.timeAllowed = timeAllowed; result.score = int(round(TP*10.0)); result.displayText = msg.str(); result.difficultyLevel = difficulty; result.colorBand = getColorForBand(band); if(result.score > 0) totalScored += result.score; vector<int> details; details.push_back(result.realDistanceToTarget*1000); details.push_back(result.targetBandHit); details.push_back(result.timeAllowed); details.push_back(result.score); // 10 x throughput details.push_back(difficulty); details.push_back(whichInSequence); details.push_back(initDist*1000); details.push_back(presetIndex); details.push_back(tempoLevel); details.push_back(runNumber); eventLogger.logEvent(TRAINING_RESULT, details); details.clear(); details.insert(details.begin(), targetParams.begin(), targetParams.end()); details.insert(details.end(), answer.begin(), answer.end()); eventLogger.logEvent(TARGET_AND_MATCH, details); return result; } int getScore(){ cout << "RUNNING SCORE: " << totalScored << endl; return totalScored; }; private: float calculateThroughput(int numDims, float endDistance, float startDistance, float time) const{ float ISSR = numDims * log2( startDistance / endDistance); cout << "==========Result======= " << endl; cout << "start: " << startDistance << endl; cout << "end: " << endDistance << endl; cout << "ISSR: " << ISSR << endl; cout << "time: " << time << endl; float TP = ISSR / time; cout << "TP: " << TP << endl; return TP; } int totalScored; }; #endif /* defined(__riftathon__TrainingScoreManager__) */