2 // Represent all the data about one trial by a user (ie one
3 // input sequence using speech or normal Dasher).
5 // Copyright 2005 by Keith Vertanen
7 #ifndef __USER_LOG_TRIAL_H__
8 #define __USER_LOG_TRIAL_H__
10 #include "FileLogger.h"
14 #include "SimpleTimer.h"
16 #include "UserLocation.h"
17 #include "Alphabet/Alphabet.h"
18 #include "DasherTypes.h"
19 #include "UserLogParam.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
;
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
45 enum eUserLogEventType
47 userLogEventMouse
= 0 // Normal mouse navigation
50 // Keeps track of a single instance of AddSymbols() or
51 // DeleteSymbols() being called.
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
;
72 // Stores the time span and all the locations and mouse locations
73 // that occur during a start/stop cycle of navigation.
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
;
89 CUserLogTrial(const string
& strCurrentTrialFilename
);
92 bool HasWritingOccured();
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
= "");
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
);
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
);
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
);