Updated Function Log to log all button presses and the mode they were used in

This commit is contained in:
Stephanie Anderl 2019-05-15 16:00:56 -07:00
commit 19c546aee5
5 changed files with 80 additions and 52 deletions

View file

@ -356,6 +356,7 @@
<ClInclude Include="pch.h" /> <ClInclude Include="pch.h" />
<ClInclude Include="StandardCalculatorViewModel.h" /> <ClInclude Include="StandardCalculatorViewModel.h" />
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
<ClInclude Include="TraceLoggerEnums.h" />
<ClInclude Include="UnitConverterViewModel.h" /> <ClInclude Include="UnitConverterViewModel.h" />
<ClInclude Include="ViewState.h" /> <ClInclude Include="ViewState.h" />
</ItemGroup> </ItemGroup>

View file

@ -213,6 +213,9 @@
<ClInclude Include="Common\TraceActivity.h"> <ClInclude Include="Common\TraceActivity.h">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="TraceLoggerEnums.h">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="DataLoaders\DefaultFromToCurrency.json"> <None Include="DataLoaders\DefaultFromToCurrency.json">

View file

@ -61,7 +61,7 @@ namespace CalculatorApp
constexpr auto EVENT_NAME_BITFLIP_BUTTONS_USED = L"BitFlipToggleButtonUsed"; constexpr auto EVENT_NAME_BITFLIP_BUTTONS_USED = L"BitFlipToggleButtonUsed";
constexpr auto EVENT_NAME_ANGLE_BUTTONS_USED = L"AngleButtonUsedInSession"; constexpr auto EVENT_NAME_ANGLE_BUTTONS_USED = L"AngleButtonUsedInSession";
constexpr auto EVENT_NAME_HYP_BUTTON_USED = L"HypButtonUsedInSession"; constexpr auto EVENT_NAME_HYP_BUTTON_USED = L"HypButtonUsedInSession";
constexpr auto EVENT_NAME_FUNCTION_USAGE = L"FunctionUsageInSession"; constexpr auto EVENT_NAME_FUNCTION_USAGE = L"KeyboardOperatorUsageInSession";
constexpr auto EVENT_NAME_BITLENGTH_BUTTON_USED = L"BitLengthButtonUsed"; constexpr auto EVENT_NAME_BITLENGTH_BUTTON_USED = L"BitLengthButtonUsed";
constexpr auto EVENT_NAME_RADIX_BUTTON_USED = L"RadixButtonUsed"; constexpr auto EVENT_NAME_RADIX_BUTTON_USED = L"RadixButtonUsed";
constexpr auto EVENT_NAME_MAX_WINDOW_COUNT = L"MaxWindowCountInSession"; constexpr auto EVENT_NAME_MAX_WINDOW_COUNT = L"MaxWindowCountInSession";
@ -104,7 +104,7 @@ namespace CalculatorApp
m_appLaunchActivity{ nullptr } m_appLaunchActivity{ nullptr }
{ {
// initialize the function array // initialize the function array
InitFunctionLogArray(); // InitFunctionLogArray();
} }
TraceLogger::~TraceLogger() TraceLogger::~TraceLogger()
@ -724,34 +724,40 @@ namespace CalculatorApp
LogLevel2Event(EVENT_NAME_EXCEPTION, fields); LogLevel2Event(EVENT_NAME_EXCEPTION, fields);
} }
void TraceLogger::UpdateFunctionUsage(int funcIndex) void TraceLogger::UpdateFunctionUsage(int functionId, int mode)
{ {
// Writer lock for the static resources // Writer lock for the static resources
reader_writer_lock::scoped_lock lock(s_traceLoggerLock); reader_writer_lock::scoped_lock lock(s_traceLoggerLock);
vector<FuncLog>::iterator it = std::find_if(funcLog.begin(), funcLog.end(), [functionId, mode](const FuncLog& f) -> bool {
if (GetIndex(funcIndex)) return f.functionId == functionId && f.mode == mode;
});
if (it != funcLog.end())
{ {
// funcIndex is passed by reference and will be having the returned index it->count++;
funcLog[funcIndex].count++; }
else
{
FunctionLogEnum func = safe_cast<FunctionLogEnum>(functionId);
funcLog.push_back(FuncLog(functionId, func.ToString()->Data(), mode));
} }
} }
void TraceLogger::InitFunctionLogArray() //void TraceLogger::InitFunctionLogArray()
{ //{
int i = -1; // int i = -1;
for (int funcIndex = 0; funcIndex != maxFunctionSize; funcIndex++) // for (int funcIndex = 0; funcIndex != maxFunctionSize; funcIndex++)
{ // {
FunctionLogEnum func = safe_cast<FunctionLogEnum>(funcIndex); // FunctionLogEnum func = safe_cast<FunctionLogEnum>(funcIndex);
wstring functionName = func.ToString()->Data(); // wstring functionName = func.ToString()->Data();
if (functionName.compare(L"CalculatorApp.FunctionLogEnum") != 0) // if (functionName.compare(L"CalculatorApp.FunctionLogEnum") != 0)
{ // {
findIndex[funcIndex] = ++i; // findIndex[funcIndex] = ++i;
funcLog.push_back(FuncLog(functionName)); // funcLog.push_back(FuncLog(functionName));
} // }
} // }
// update the functionCount with total function count which we are tracking through tracelog. // // update the functionCount with total function count which we are tracking through tracelog.
functionCount = i; // functionCount = i;
} //}
wstring TraceLogger::GetProgrammerType(int index) wstring TraceLogger::GetProgrammerType(int index)
{ {
@ -763,7 +769,7 @@ namespace CalculatorApp
return s_programmerType[0]; return s_programmerType[0];
} }
bool TraceLogger::GetIndex(int& index) /* bool TraceLogger::GetIndex(int& index)
{ {
if (findIndex[index] > 0) if (findIndex[index] > 0)
{ {
@ -771,7 +777,7 @@ namespace CalculatorApp
return true; return true;
} }
return false; return false;
} }*/
void TraceLogger::UpdateWindowCount(size_t windowCount) void TraceLogger::UpdateWindowCount(size_t windowCount)
{ {
@ -872,17 +878,15 @@ namespace CalculatorApp
if (!GetTraceLoggingProviderEnabled()) if (!GetTraceLoggingProviderEnabled())
return; return;
for (int i = 0; i < functionCount; i++) for (vector<FuncLog>::iterator i; i < funcLog.end(); i++)
{ {
// log only those functions which are used LoggingFields fields{};
if (funcLog[i].count > 0) fields.AddUInt32(L"FunctionId", i->functionId);
{ fields.AddString(L"FunctionName", i->functionName.data());
LoggingFields fields{}; fields.AddUInt32(L"ViewModeId", i->mode);
fields.AddString(L"FunctionName", funcLog[i].funcName.data()); fields.AddUInt32(L"UsageCount", i->count);
fields.AddUInt32(L"UsageCount", funcLog[i].count); fields.AddUInt32(L"WindowId", windowId);
fields.AddUInt32(L"WindowId", windowId); LogLevel2Event(EVENT_NAME_FUNCTION_USAGE, fields);
LogLevel3Event(EVENT_NAME_FUNCTION_USAGE, fields);
}
} }
} }

View file

@ -17,15 +17,15 @@ namespace CalculatorApp
{ {
public: public:
int count; int count;
std::wstring funcName; int functionId;
FuncLog() std::wstring functionName;
int mode;
FuncLog(int fId, std::wstring fName, int vMode)
{ {
count = 0; functionId = fId;
} functionName = fName;
FuncLog(std::wstring fName) mode = vMode;
{ count = 1;
funcName = fName;
count = 0;
} }
}; };
@ -69,9 +69,9 @@ namespace CalculatorApp
void LogMemoryFlyoutOpenEnd(unsigned int) const; void LogMemoryFlyoutOpenEnd(unsigned int) const;
void LogInvalidPastedInputOccurred(std::wstring_view reason, CalculatorApp::Common::ViewMode mode, int ProgrammerNumberBase, int bitLengthType); void LogInvalidPastedInputOccurred(std::wstring_view reason, CalculatorApp::Common::ViewMode mode, int ProgrammerNumberBase, int bitLengthType);
void LogValidInputPasted(CalculatorApp::Common::ViewMode mode) const; void LogValidInputPasted(CalculatorApp::Common::ViewMode mode) const;
void UpdateFunctionUsage(int func); void UpdateFunctionUsage(int functionId, int mode);
void LogFunctionUsage(int); void LogFunctionUsage(int);
void InitFunctionLogArray(); // void InitFunctionLogArray();
void LogBitLengthButtonUsed(int windowId); void LogBitLengthButtonUsed(int windowId);
void LogRadixButtonUsed(int windowId); void LogRadixButtonUsed(int windowId);
void LogAngleButtonUsed(int windowId); void LogAngleButtonUsed(int windowId);
@ -133,11 +133,11 @@ namespace CalculatorApp
GUID sessionGuid; GUID sessionGuid;
CalculatorApp::Common::ViewMode currentMode = CalculatorApp::Common::ViewMode::None; CalculatorApp::Common::ViewMode currentMode = CalculatorApp::Common::ViewMode::None;
std::vector<FuncLog> funcLog; std::vector<FuncLog> funcLog;
int functionCount = 0; //int functionCount = 0;
bool isHypButtonLogged = false; bool isHypButtonLogged = false;
bool isAngleButtonInitialized = false; bool isAngleButtonInitialized = false;
unsigned int findIndex[maxFunctionSize] = { 0 }; //unsigned int findIndex[maxFunctionSize] = { 0 };
bool GetIndex(int& index); //bool GetIndex(int& index);
std::wstring GetProgrammerType(int index); std::wstring GetProgrammerType(int index);
size_t maxWindowCount = 0; size_t maxWindowCount = 0;
bool isAppLaunchBeginLogged = false; bool isAppLaunchBeginLogged = false;

View file

@ -599,7 +599,27 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter); NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter);
Command cmdenum = ConvertToOperatorsEnum(numOpEnum); Command cmdenum = ConvertToOperatorsEnum(numOpEnum);
TraceLogger::GetInstance().UpdateFunctionUsage((int)numOpEnum); if (numOpEnum != NumbersAndOperatorsEnum::IsScientificMode && numOpEnum != NumbersAndOperatorsEnum::IsStandardMode
&& numOpEnum != NumbersAndOperatorsEnum::IsProgrammerMode && numOpEnum != NumbersAndOperatorsEnum::FToE
&& (numOpEnum != NumbersAndOperatorsEnum::Degree) && (numOpEnum != NumbersAndOperatorsEnum::Radians) && (numOpEnum != NumbersAndOperatorsEnum::Grads)
&& numOpEnum != NumbersAndOperatorsEnum::Memory)
{
ViewMode mode;
if (IsStandard)
{
mode = ViewMode::Standard;
}
else if (IsScientific)
{
mode = ViewMode::Scientific;
}
else if (IsProgrammer)
{
mode = ViewMode::Programmer;
}
TraceLogger::GetInstance().UpdateFunctionUsage((int)numOpEnum, (int)mode);
}
if (IsInError) if (IsInError)
{ {
@ -884,7 +904,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
// Handle exponent and exponent sign (...e+... or ...e-... or ...e...) // Handle exponent and exponent sign (...e+... or ...e-... or ...e...)
if (mappedNumOp == NumbersAndOperatorsEnum::Exp) if (mappedNumOp == NumbersAndOperatorsEnum::Exp)
{ {
//Check the following item // Check the following item
switch (MapCharacterToButtonId(*(it + 1), canSendNegate)) switch (MapCharacterToButtonId(*(it + 1), canSendNegate))
{ {
case NumbersAndOperatorsEnum::Subtract: case NumbersAndOperatorsEnum::Subtract:
@ -896,7 +916,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
break; break;
case NumbersAndOperatorsEnum::Add: case NumbersAndOperatorsEnum::Add:
{ {
//Nothing to do, skip to the next item // Nothing to do, skip to the next item
++it; ++it;
} }
break; break;
@ -1223,7 +1243,7 @@ void StandardCalculatorViewModel::SetCalculatorType(ViewMode targetState)
} }
} }
String^ StandardCalculatorViewModel::GetRawDisplayValue() String ^ StandardCalculatorViewModel::GetRawDisplayValue()
{ {
if (IsInError) if (IsInError)
{ {