#include "GestureDef.h"
#include <fstream>

using namespace std;

namespace GestureDef{	
	// Global function to get the gesture name
	string getGestureName(int gestureIdx)
	{
		string str = "NOT_DEF";
		switch (gestureIdx)
		{
		// swipe eight directions
		case SWIPE_RIGHT:		str = "swipe_right"; break;
		case SWIPE_LEFT:		str = "swipe_left"; break;
		case SWIPE_UP:			str = "swipe_up"; break;
		case SWIPE_DOWN:		str = "swipe_down"; break;
		case SWIPE_UPRIGHT:		str = "swipe_upright"; break;
		case SWIPE_UPLEFT:		str = "swipe_upleft"; break;	
		case SWIPE_DOWNRIGHT:	str = "swipe_downright"; break;	
		case SWIPE_DOWNLEFT:	str = "swipe_downleft"; break;
	
		// back & forth
		case POKE_RIGHT:		str = "poke_right"; break;
		case POKE_LEFT:			str = "poke_left"; break;
		case POKE_UP:			str = "poke_up"; break;
		case POKE_DOWN:			str = "poke_down"; break;

		// others
		case V_SHAPE:			str = "v_shape"; break;
		case X_SHAPE:			str = "x_shape"; break;
		case CIR_HOR_CLK:		str = "cir_hor_clk"; break;
		case CIR_HOR_CCLK:		str = "cir_hor_cclk"; break;
		case CIR_VER_CLK:		str = "cir_ver_clk"; break;
		case CIR_VER_CCLK:		str = "cir_ver_cclk"; break;
		case TWIST_CLK:			str = "twist_clk"; break;
		case TWITS_CCLK:		str = "twist_cclk"; break;		
		}		
		return str;
	}

	vector<TesterInfo> loadTestersInfo(string path)
	{
		vector<TesterInfo> testersInfo;		
		fstream f;
		f.open(path.c_str());
		if (!f.fail()){
			while(!f.eof()){
				TesterInfo info;
				char name[256];
				char hand[256];
				f.getline(name, 256, ',');
				f.getline(hand, 256);
				info.name.assign(name);
				
				int rightHand = 1;
				for (int i=0; i<256; i++){
					if (hand[i]==' ' || hand[i]=='\t')
						continue;
					else if (hand[i]=='R' || hand[i]=='#') // ignore the comment if any
						break;
					else if (hand[i]=='L'){
						rightHand = 0;
						break;
					}				
				}			
				info.rightHand = rightHand;
				testersInfo.push_back(info);
			}
		}
		f.close();
		return testersInfo;
	}
}