Various small changes
[dasher.git] / Src / DasherCore / UserLogTrial.h
blob4f9b0fb2c7e7322165df7e85117bc1315cf1e300
2 // Represent all the data about one trial by a user (ie one
3 // input sequence using speech or normal Dasher).
4 //
5 // Copyright 2005 by Keith Vertanen
7 #ifndef __USER_LOG_TRIAL_H__
8 #define __USER_LOG_TRIAL_H__
10 #include "FileLogger.h"
11 #include <fstream>
12 #include <string>
13 #include <vector>
14 #include "SimpleTimer.h"
15 #include "TimeSpan.h"
16 #include "UserLocation.h"
17 #include "Alphabet/Alphabet.h"
18 #include "DasherTypes.h"
19 #include "UserLogParam.h"
20 #include <algorithm>
21 #include "XMLUtil.h"
23 // Types used to return two dimensional grid of double values
24 typedef double** DENSITY_GRID;
25 typedef vector<DENSITY_GRID> VECTOR_DENSITY_GRIDS;
26 typedef vector<DENSITY_GRID>::iterator VECTOR_DENSITY_GRIDS_ITER;
27 typedef vector<VECTOR_DENSITY_GRIDS> VECTOR_VECTOR_DENSITY_GRIDS;
28 typedef vector<VECTOR_DENSITY_GRIDS>::iterator VECTOR_VECTOR_DENSITY_GRIDS_ITER;
29 typedef vector<VECTOR_VECTOR_DENSITY_GRIDS> VECTOR_VECTOR_VECTOR_DENSITY_GRIDS;
30 typedef vector<VECTOR_VECTOR_DENSITY_GRIDS>::iterator VECTOR_VECTOR_VECTOR_DENSITY_GRIDS_ITER;
32 extern CFileLogger* g_pLogger;
34 class CUserLogTrial;
36 typedef vector<CUserLogTrial> VECTOR_USER_LOG_TRIAL;
37 typedef vector<CUserLogTrial>::iterator VECTOR_USER_LOG_TRIAL_ITER;
38 typedef vector<CUserLogTrial*> VECTOR_USER_LOG_TRIAL_PTR;
39 typedef vector<CUserLogTrial*>::iterator VECTOR_USER_LOG_TRIAL_PTR_ITER;
41 // Used to indicate what type of event caused symbols to
42 // be added or deleted by Dasher. This could for example
43 // be used to log which button was pressed in button
44 // Dasher.
45 enum eUserLogEventType
47 userLogEventMouse = 0 // Normal mouse navigation
50 // Keeps track of a single instance of AddSymbols() or
51 // DeleteSymbols() being called.
52 struct NavLocation
54 string strHistory; // Display symbol history after the adds or deletes are carried out
55 CTimeSpan* span; // Track the time between this update and the one that comes next
56 eUserLogEventType event; // What triggered the adding or deleting of symbols
57 int numDeleted; // How many symbols deleted (0 if it is an AddSymbols() call)
58 Dasher::VECTOR_SYMBOL_PROB_DISPLAY* pVectorAdded; // Info on all added symbols
59 double avgBits; // Average bits required to write this history (assuming no errors)
62 typedef vector<NavLocation*> VECTOR_NAV_LOCATION_PTR;
64 struct WindowSize
66 int top;
67 int left;
68 int bottom;
69 int right;
72 // Stores the time span and all the locations and mouse locations
73 // that occur during a start/stop cycle of navigation.
74 struct NavCycle
76 CTimeSpan* pSpan; // Tracks time span of this navgiation cycle
77 VECTOR_NAV_LOCATION_PTR vectorNavLocations; // Locations when text was added or deleted
78 VECTOR_USER_LOCATION_PTR vectorMouseLocations; // Stores mouse locations and time stamps
81 typedef vector<NavCycle*> VECTOR_NAV_CYCLE_PTR;
82 typedef vector<NavCycle*>::iterator VECTOR_NAV_CYCLE_PTR_ITER;
84 using namespace std;
86 class CUserLogTrial
88 public:
89 CUserLogTrial(const string& strCurrentTrialFilename);
90 ~CUserLogTrial();
92 bool HasWritingOccured();
93 void StartWriting();
94 void StopWriting();
95 void AddSymbols(Dasher::VECTOR_SYMBOL_PROB* vpNewSymbolProbs, eUserLogEventType iEvent, Dasher::CAlphabet* pCurrentAlphabet);
96 void DeleteSymbols(int iNumToDelete, eUserLogEventType iEvent);
97 string GetXML(const string& strPrefix = "");
98 void Done();
99 void AddWindowSize(int iTop, int iLeft, int iBottom, int iRight);
100 void AddCanvasSize(int iTop, int iLeft, int iBottom, int iRight);
101 void AddMouseLocation(int iX, int iY, float dNats);
102 void AddMouseLocationNormalized(int iX, int iY, bool bStoreIntegerRep, float dNats);
103 bool IsWriting();
104 void AddParam(const string& strName, const string& strValue, int iOptionMask = 0);
105 static string GetParamXML(CUserLogParam* pParam, const string& strPrefix = "");
107 // Methods used by utility that can post-process the log files:
108 CUserLogTrial(const string& strXML, int iIgnored);
109 static VECTOR_USER_LOG_PARAM_PTR ParseParamsXML(const string& strXML);
110 static WindowSize ParseWindowXML(const string& strXML);
111 VECTOR_STRING GetTabMouseXY(bool bReturnNormalized);
112 VECTOR_DENSITY_GRIDS GetMouseDensity(int iGridSize);
113 static DENSITY_GRID MergeGrids(int iGridSize, DENSITY_GRID pGridA, DENSITY_GRID pGridB);
115 protected:
116 CTimeSpan* m_pSpan;
117 bool m_bWritingStart;
118 string m_strCurrentTrial; // Stores information passed to us from the UserTrial app
119 WindowSize m_sWindowCoordinates; // Records the window coordinates at the start of navigation
120 WindowSize m_sCanvasCoordinates; // The size of our canvas during navigation
121 Dasher::VECTOR_SYMBOL_PROB_DISPLAY m_vHistory; // Tracks all the symbols, probs, display text entererd during this trial
122 VECTOR_USER_LOG_PARAM_PTR m_vpParams; // Stores general parameters we want stored in each trial tag in the XML
123 VECTOR_NAV_CYCLE_PTR m_vpNavCycles;
124 string m_strCurrentTrialFilename; // Where to look for info on the current subject's trial
126 // Used whenever we need a temporary char* buffer
127 static const int TEMP_BUFFER_SIZE = 4096;
128 char m_szTempBuffer[TEMP_BUFFER_SIZE];
130 void GetUserTrialInfo();
131 string GetHistoryDisplay();
132 double GetHistoryAvgBits();
133 void StopPreviousTimer();
134 void InitMemberVars();
136 NavCycle* GetCurrentNavCycle();
137 NavCycle* AddNavCycle();
138 NavLocation* GetCurrentNavLocation();
140 // Various helpers for outputting the XML, this allows subclasses to
141 // add there own GetXML() method but reuse code for shared parts.
142 string GetLocationXML(NavLocation* pLocation, const string& strPrefix);
143 string GetSummaryXML(const string& strPrefix);
144 string GetStatsXML(const string& strPrefix, const string& strText, CTimeSpan* pSpan, double dAvgBits);
145 string GetWindowCanvasXML(const string& strPrefix);
146 string GetParamsXML(const string& strPrefix);
147 string GetNavCyclesXML(const string& strPrefix);
151 #endif