view TrainingScoreManager.h @ 35:3b10a26da293

refactoring and log
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 26 Nov 2014 18:18:20 +0000
parents 3af380769779
children 146033869165
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) {
        TrainingTestResult result;
        stringstream msg;
        int score = 0;
        // work out euc distance from actual point
        //for_each(answer.begin(),answer.end(),printThing<int>());
        //for_each(targetParams.begin(),targetParams.end(),printThing<int>());
        float initDist = euclideanDistance(startPosition, answer);
        float dist = euclideanDistance(targetParams, answer);
        float TP = calculateThroughput(TOTAL_NUM_PARAMS, dist, initDist, timeAllowed/1000.);
        
        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 = round(TP*10);
        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(0,0,0,255);         // black worst
        }
        result.colorBand = c;

        totalScored += 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);
        
        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(){return totalScored;};
    
private:
    
    
    float calculateThroughput(int numDims, float endDistance, float startDistance, float time) const{
        if (startDistance == 0) startDistance = 1;
        if (endDistance == 0) endDistance = 1;
        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__) */