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="StandardCalculatorViewModel.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="TraceLoggerEnums.h" />
<ClInclude Include="UnitConverterViewModel.h" />
<ClInclude Include="ViewState.h" />
</ItemGroup>

View file

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

View file

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

View file

@ -599,7 +599,27 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
NumbersAndOperatorsEnum numOpEnum = CalculatorButtonPressedEventArgs::GetOperationFromCommandParameter(parameter);
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)
{
@ -884,7 +904,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
// Handle exponent and exponent sign (...e+... or ...e-... or ...e...)
if (mappedNumOp == NumbersAndOperatorsEnum::Exp)
{
//Check the following item
// Check the following item
switch (MapCharacterToButtonId(*(it + 1), canSendNegate))
{
case NumbersAndOperatorsEnum::Subtract:
@ -896,7 +916,7 @@ void StandardCalculatorViewModel::OnPaste(String ^ pastedString, ViewMode mode)
break;
case NumbersAndOperatorsEnum::Add:
{
//Nothing to do, skip to the next item
// Nothing to do, skip to the next item
++it;
}
break;
@ -1223,7 +1243,7 @@ void StandardCalculatorViewModel::SetCalculatorType(ViewMode targetState)
}
}
String^ StandardCalculatorViewModel::GetRawDisplayValue()
String ^ StandardCalculatorViewModel::GetRawDisplayValue()
{
if (IsInError)
{