tagging release
[dasher.git] / Src / DasherCore / UserLogTrial.h
blob2fe859393afe86bc9da733a854786e26453f40cb
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 "UserButton.h"
17 #include "UserLocation.h"
18 #include "Alphabet/Alphabet.h"
19 #include "DasherTypes.h"
20 #include "UserLogParam.h"
21 #include <algorithm>
22 #include "XMLUtil.h"
24 // Types used to return two dimensional grid of double values
25 typedef double** DENSITY_GRID;
26 typedef vector<DENSITY_GRID> VECTOR_DENSITY_GRIDS;
27 typedef vector<DENSITY_GRID>::iterator VECTOR_DENSITY_GRIDS_ITER;
28 typedef vector<VECTOR_DENSITY_GRIDS> VECTOR_VECTOR_DENSITY_GRIDS;
29 typedef vector<VECTOR_DENSITY_GRIDS>::iterator VECTOR_VECTOR_DENSITY_GRIDS_ITER;
30 typedef vector<VECTOR_VECTOR_DENSITY_GRIDS> VECTOR_VECTOR_VECTOR_DENSITY_GRIDS;
31 typedef vector<VECTOR_VECTOR_DENSITY_GRIDS>::iterator VECTOR_VECTOR_VECTOR_DENSITY_GRIDS_ITER;
33 extern CFileLogger* g_pLogger;
35 class CUserLogTrial;
37 typedef vector<CUserLogTrial> VECTOR_USER_LOG_TRIAL;
38 typedef vector<CUserLogTrial>::iterator VECTOR_USER_LOG_TRIAL_ITER;
39 typedef vector<CUserLogTrial*> VECTOR_USER_LOG_TRIAL_PTR;
40 typedef vector<CUserLogTrial*>::iterator VECTOR_USER_LOG_TRIAL_PTR_ITER;
42 // Used to indicate what type of event caused symbols to
43 // be added or deleted by Dasher. This could for example
44 // be used to log which button was pressed in button
45 // Dasher.
46 enum eUserLogEventType
48 userLogEventMouse = 0 // Normal mouse navigation
51 // Keeps track of a single instance of AddSymbols() or
52 // DeleteSymbols() being called.
53 struct NavLocation
55 string strHistory; // Display symbol history after the adds or deletes are carried out
56 CTimeSpan* span; // Track the time between this update and the one that comes next
57 eUserLogEventType event; // What triggered the adding or deleting of symbols
58 int numDeleted; // How many symbols deleted (0 if it is an AddSymbols() call)
59 Dasher::VECTOR_SYMBOL_PROB_DISPLAY* pVectorAdded; // Info on all added symbols
60 double avgBits; // Average bits required to write this history (assuming no errors)
63 typedef vector<NavLocation*> VECTOR_NAV_LOCATION_PTR;
65 struct WindowSize
67 int top;
68 int left;
69 int bottom;
70 int right;
73 // Stores the time span and all the locations and mouse locations
74 // that occur during a start/stop cycle of navigation.
75 struct NavCycle
77 CTimeSpan* pSpan; // Tracks time span of this navgiation cycle
78 VECTOR_NAV_LOCATION_PTR vectorNavLocations; // Locations when text was added or deleted
79 VECTOR_USER_LOCATION_PTR vectorMouseLocations; // Stores mouse locations and time stamps
80 VECTOR_USER_BUTTON_PTR vectorButtons; // Stores button presses and time stamps
81 double dBits; // Number of bits entered during the cycle, only updated at the end
84 typedef vector<NavCycle*> VECTOR_NAV_CYCLE_PTR;
85 typedef vector<NavCycle*>::iterator VECTOR_NAV_CYCLE_PTR_ITER;
87 using namespace std;
88 /// \ingroup Logging
89 /// @{
90 class CUserLogTrial
92 public:
93 CUserLogTrial(const string& strCurrentTrialFilename);
94 ~CUserLogTrial();
96 bool HasWritingOccured();
97 void StartWriting();
98 void StopWriting(double dBits);
99 void AddSymbols(Dasher::VECTOR_SYMBOL_PROB* vpNewSymbolProbs, eUserLogEventType iEvent, Dasher::CAlphabet* pCurrentAlphabet);
100 void DeleteSymbols(int iNumToDelete, eUserLogEventType iEvent);
101 string GetXML(const string& strPrefix = "");
102 void Done();
103 void AddWindowSize(int iTop, int iLeft, int iBottom, int iRight);
104 void AddCanvasSize(int iTop, int iLeft, int iBottom, int iRight);
105 void AddMouseLocation(int iX, int iY, float dNats);
106 void AddMouseLocationNormalized(int iX, int iY, bool bStoreIntegerRep, float dNats);
107 void AddKeyDown(int iId, int iType, int iEffect);
108 bool IsWriting();
109 void AddParam(const string& strName, const string& strValue, int iOptionMask = 0);
110 static string GetParamXML(CUserLogParam* pParam, const string& strPrefix = "");
112 int GetButtonCount();
113 double GetTotalBits();
115 // Methods used by utility that can post-process the log files:
116 CUserLogTrial(const string& strXML, int iIgnored);
117 static VECTOR_USER_LOG_PARAM_PTR ParseParamsXML(const string& strXML);
118 static WindowSize ParseWindowXML(const string& strXML);
119 VECTOR_STRING GetTabMouseXY(bool bReturnNormalized);
120 VECTOR_DENSITY_GRIDS GetMouseDensity(int iGridSize);
121 static DENSITY_GRID MergeGrids(int iGridSize, DENSITY_GRID pGridA, DENSITY_GRID pGridB);
123 protected:
124 CTimeSpan* m_pSpan;
125 bool m_bWritingStart;
126 string m_strCurrentTrial; // Stores information passed to us from the UserTrial app
127 WindowSize m_sWindowCoordinates; // Records the window coordinates at the start of navigation
128 WindowSize m_sCanvasCoordinates; // The size of our canvas during navigation
129 Dasher::VECTOR_SYMBOL_PROB_DISPLAY m_vHistory; // Tracks all the symbols, probs, display text entererd during this trial
130 VECTOR_USER_LOG_PARAM_PTR m_vpParams; // Stores general parameters we want stored in each trial tag in the XML
131 VECTOR_NAV_CYCLE_PTR m_vpNavCycles;
132 string m_strCurrentTrialFilename; // Where to look for info on the current subject's trial
134 // Used whenever we need a temporary char* buffer
135 static const int TEMP_BUFFER_SIZE = 4096;
136 char m_szTempBuffer[TEMP_BUFFER_SIZE];
138 void GetUserTrialInfo();
139 string GetHistoryDisplay();
140 double GetHistoryAvgBits();
141 void StopPreviousTimer();
142 void InitMemberVars();
144 NavCycle* GetCurrentNavCycle();
145 NavCycle* AddNavCycle();
146 NavLocation* GetCurrentNavLocation();
148 // Various helpers for outputting the XML, this allows subclasses to
149 // add there own GetXML() method but reuse code for shared parts.
150 string GetLocationXML(NavLocation* pLocation, const string& strPrefix);
151 string GetSummaryXML(const string& strPrefix);
152 string GetStatsXML(const string& strPrefix, const string& strText, CTimeSpan* pSpan, double dAvgBits, int iButtonCount, double dTotalBits);
153 string GetWindowCanvasXML(const string& strPrefix);
154 string GetParamsXML(const string& strPrefix);
155 string GetNavCyclesXML(const string& strPrefix);
158 /// @}
160 #endif