Mercurial > hg > tweakathon2ios
view TrainingScoreManager.h @ 37:52dbd5b4cfa9
slider feedback and textures
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 03 Dec 2014 11:38:26 +0000 |
parents | 146033869165 |
children | fea11c3d1d94 |
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; } 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; auto dimComp = sqrt(TOTAL_NUM_PARAMS); int band = -1; if (dist < TARGET_SCORE_CC_BAND*dimComp){ band = 1; msg << "DOUBLE BULLSEYE!" << endl; }else if (dist < TARGET_SCORE_CC_BAND*2*dimComp){ band = 2; msg << "SINGLE BULLSEYE!" << endl; }else if (dist < TARGET_SCORE_CC_BAND*3*dimComp){ band = 3; msg << "CLOSE..." << endl; }else if (dist < TARGET_SCORE_CC_BAND*4*dimComp){ band = 4; msg << "OK...ISH" << endl; }else if (dist < TARGET_SCORE_CC_BAND*6*dimComp){ // 30 band = 5; msg << "MEDIOCRE" << endl; }else if (dist < TARGET_SCORE_CC_BAND*9*dimComp){ // 45 band = 6; msg << "POOR..." << endl; }else{ band = 7; msg << "MISSED COMPLETELY!" << endl; } msg << "Distance from target: " << 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; ofColor c; if(result.targetBandHit == 1){ c = ofColor(255,255,0,255); // yellow 1 }else if(result.targetBandHit == 2){ c = ofColor(255,0,0,255); // red 2 }else if(result.targetBandHit == 3){ c = ofColor(45,45,255,255); // blue 3 }else if(result.targetBandHit == 4){ c = ofColor(0,255,0,255); // green 4 }else{ c = ofColor(123,123,123,255); // grey worst } result.colorBand = c; 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__) */