diff --git a/src/CalcViewModel/CalcViewModel.vcxproj b/src/CalcViewModel/CalcViewModel.vcxproj index e2e98ab9..1735d2d3 100644 --- a/src/CalcViewModel/CalcViewModel.vcxproj +++ b/src/CalcViewModel/CalcViewModel.vcxproj @@ -356,6 +356,7 @@ + diff --git a/src/CalcViewModel/CalcViewModel.vcxproj.filters b/src/CalcViewModel/CalcViewModel.vcxproj.filters index d05aca0b..ca114731 100644 --- a/src/CalcViewModel/CalcViewModel.vcxproj.filters +++ b/src/CalcViewModel/CalcViewModel.vcxproj.filters @@ -213,6 +213,9 @@ Common + + Common + diff --git a/src/CalcViewModel/Common/TraceLogger.cpp b/src/CalcViewModel/Common/TraceLogger.cpp index 998c9965..c441944e 100644 --- a/src/CalcViewModel/Common/TraceLogger.cpp +++ b/src/CalcViewModel/Common/TraceLogger.cpp @@ -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::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(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(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(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++) + for (vector::iterator i; i < funcLog.end(); i++) { - // log only those functions which are used - if (funcLog[i].count > 0) - { - LoggingFields fields{}; - fields.AddString(L"FunctionName", funcLog[i].funcName.data()); - fields.AddUInt32(L"UsageCount", funcLog[i].count); - fields.AddUInt32(L"WindowId", windowId); - LogLevel3Event(EVENT_NAME_FUNCTION_USAGE, fields); - } + LoggingFields fields{}; + 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); + LogLevel2Event(EVENT_NAME_FUNCTION_USAGE, fields); } } diff --git a/src/CalcViewModel/Common/TraceLogger.h b/src/CalcViewModel/Common/TraceLogger.h index c68441d6..d3b3310e 100644 --- a/src/CalcViewModel/Common/TraceLogger.h +++ b/src/CalcViewModel/Common/TraceLogger.h @@ -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; - 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; diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp index dd0283da..afdbaf0d 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.cpp +++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp @@ -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) {