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 "UserButton.h"
17 #include "UserLocation.h"
18 #include "Alphabet/Alphabet.h"
19 #include "DasherTypes.h"
20 #include "UserLogParam.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
;
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
46 enum eUserLogEventType
48 userLogEventMouse
= 0 // Normal mouse navigation
51 // Keeps track of a single instance of AddSymbols() or
52 // DeleteSymbols() being called.
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
;
73 // Stores the time span and all the locations and mouse locations
74 // that occur during a start/stop cycle of navigation.
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
;
93 CUserLogTrial(const string
& strCurrentTrialFilename
);
96 bool HasWritingOccured();
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
= "");
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
);
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
);
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
);