Updated UpdateFunctionUsage telemetry methods to UpdateButtonUsage. Fixed issue where button click telemetry is sent per window close

This commit is contained in:
Stephanie Anderl 2019-05-23 16:07:49 -07:00
commit acc4d806a8
8 changed files with 31 additions and 223 deletions

View file

@ -356,7 +356,6 @@
<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,9 +213,6 @@
<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

@ -163,53 +163,4 @@ public
BINEND = (int)CM::Command::CommandBINEDITEND, BINEND = (int)CM::Command::CommandBINEDITEND,
Hyp = (int)CM::Command::CommandHYP Hyp = (int)CM::Command::CommandHYP
}; };
// This contains list of functions whose usage we are tracelogging
public
enum class FunctionLogEnum
{
Invert = (int)CM::Command::CommandREC,
Sqrt = (int)CM::Command::CommandSQRT,
Percent = (int)CM::Command::CommandPERCENT,
Negate = (int)CM::Command::CommandSIGN,
Degrees = (int)CM::Command::CommandDegrees,
Pi = (int)CM::Command::CommandPI,
Sin = (int)CM::Command::CommandSIN,
Cos = (int)CM::Command::CommandCOS,
Tan = (int)CM::Command::CommandTAN,
Factorial = (int)CM::Command::CommandFAC,
XPower2 = (int)CM::Command::CommandSQR,
Mod = (int)CM::Command::CommandMOD,
FToE = (int)CM::Command::CommandFE,
LogBaseE = (int)CM::Command::CommandLN,
InvSin = (int)CM::Command::CommandASIN,
InvCos = (int)CM::Command::CommandACOS,
InvTan = (int)CM::Command::CommandATAN,
LogBase10 = (int)CM::Command::CommandLOG,
XPowerY = (int)CM::Command::CommandPWR,
YRootX = (int)CM::Command::CommandROOT,
TenPowerX = (int)CM::Command::CommandPOW10,
EPowerX = (int)CM::Command::CommandPOWE,
Exp = (int)CM::Command::CommandEXP,
DecButton = (int)CM::Command::CommandDec,
OctButton = (int)CM::Command::CommandOct,
HexButton = (int)CM::Command::CommandHex,
BinButton = (int)CM::Command::CommandBin,
And = (int)CM::Command::CommandAnd,
Ror = (int)CM::Command::CommandROR,
Rol = (int)CM::Command::CommandROL,
Or = (int)CM::Command::CommandOR,
Lsh = (int)CM::Command::CommandLSHF,
Rsh = (int)CM::Command::CommandRSHF,
Xor = (int)CM::Command::CommandXor,
Not = (int)CM::Command::CommandNot,
Sinh = (int)CM::Command::CommandSINH,
Cosh = (int)CM::Command::CommandCOSH,
Tanh = (int)CM::Command::CommandTANH,
InvSinh = (int)CM::Command::CommandASINH,
InvCosh = (int)CM::Command::CommandACOSH,
InvTanh = (int)CM::Command::CommandATANH,
Cube = (int)CM::Command::CommandCUB,
DMS = (int)CM::Command::CommandDMS,
};
} }

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"KeyboardOperatorUsageInSession"; constexpr auto EVENT_NAME_BUTTON_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";
@ -109,8 +109,6 @@ namespace CalculatorApp
, // Unique providerID {0905CA09-610E-401E-B650-2F212980B9E0} , // Unique providerID {0905CA09-610E-401E-B650-2F212980B9E0}
m_appLaunchActivity{ nullptr } m_appLaunchActivity{ nullptr }
{ {
// initialize the function array
// InitFunctionLogArray();
} }
TraceLogger::~TraceLogger() TraceLogger::~TraceLogger()
@ -776,40 +774,23 @@ namespace CalculatorApp
LogLevel2Event(EVENT_NAME_EXCEPTION, fields); LogLevel2Event(EVENT_NAME_EXCEPTION, fields);
} }
void TraceLogger::UpdateFunctionUsage(int functionId, int mode) void TraceLogger::UpdateButtonUsage(int buttonId, 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 = vector<ButtonLog>::iterator it = std::find_if(
std::find_if(funcLog.begin(), funcLog.end(), [functionId, mode](const FuncLog& f) -> bool { return f.functionId == functionId && f.mode == mode; }); buttonLog.begin(), buttonLog.end(), [buttonId, mode](const ButtonLog& bLog) -> bool { return bLog.buttonId == buttonId && bLog.mode == mode; });
if (it != funcLog.end()) if (it != buttonLog.end())
{ {
it->count++; it->count++;
} }
else else
{ {
FunctionLogEnum func = safe_cast<FunctionLogEnum>(functionId); NumbersAndOperatorsEnum button = safe_cast<NumbersAndOperatorsEnum>(buttonId);
funcLog.push_back(FuncLog(functionId, func.ToString()->Data(), mode)); buttonLog.push_back(ButtonLog(buttonId, button.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;
//}
wstring TraceLogger::GetProgrammerType(int index) wstring TraceLogger::GetProgrammerType(int index)
{ {
if (index >= 0) if (index >= 0)
@ -820,20 +801,10 @@ namespace CalculatorApp
return s_programmerType[0]; return s_programmerType[0];
} }
/* bool TraceLogger::GetIndex(int& index)
{
if (findIndex[index] > 0)
{
index = findIndex[index];
return true;
}
return false;
}*/
void TraceLogger::UpdateWindowCount(size_t windowCount) void TraceLogger::UpdateWindowCount(size_t windowCount)
{ {
maxWindowCount = (maxWindowCount > windowCount) ? maxWindowCount : windowCount; maxWindowCount = (maxWindowCount > windowCount) ? maxWindowCount : windowCount;
windowLaunchCount++; currentWindowCount = windowCount;
} }
void TraceLogger::LogMaxWindowCount() void TraceLogger::LogMaxWindowCount()
@ -924,20 +895,19 @@ namespace CalculatorApp
} }
} }
void TraceLogger::LogFunctionUsage(int windowId) void TraceLogger::LogButtonUsage()
{ {
if (!GetTraceLoggingProviderEnabled()) if (!GetTraceLoggingProviderEnabled())
return; return;
for (auto i : funcLog) for (auto i : buttonLog)
{ {
LoggingFields fields{}; LoggingFields fields{};
fields.AddUInt32(L"FunctionId", i.functionId); fields.AddUInt32(L"ButtonId", i.buttonId);
fields.AddString(L"FunctionName", i.functionName.data()); fields.AddString(L"ButtonName", i.buttonName.data());
fields.AddUInt32(L"ViewModeId", i.mode); fields.AddUInt32(L"ViewModeId", i.mode);
fields.AddUInt32(L"UsageCount", i.count); fields.AddUInt32(L"UsageCount", i.count);
fields.AddUInt32(L"WindowId", windowId); LogLevel2Event(EVENT_NAME_BUTTON_USAGE, fields);
LogLevel2Event(EVENT_NAME_FUNCTION_USAGE, fields);
} }
} }
@ -1062,9 +1032,12 @@ namespace CalculatorApp
LogLevel3Event(L"CurrencyConverterInputReceived", fields); LogLevel3Event(L"CurrencyConverterInputReceived", fields);
} }
void TraceLogger::LogViewClosingTelemetry(int windowId) void TraceLogger::LogViewClosingTelemetry()
{ {
LogFunctionUsage(windowId); if (currentWindowCount == 1)
{
LogButtonUsage();
}
LogMaxWindowCount(); LogMaxWindowCount();
} }

View file

@ -13,17 +13,17 @@ static const int maxFunctionSize = (int)CalculationManager::Command::CommandBINE
// This class implements a singleton model ensure that only one instance is created. // This class implements a singleton model ensure that only one instance is created.
namespace CalculatorApp namespace CalculatorApp
{ {
struct FuncLog struct ButtonLog
{ {
public: public:
int count; int count;
int functionId; int buttonId;
std::wstring functionName; std::wstring buttonName;
int mode; int mode;
FuncLog(int fId, std::wstring fName, int vMode) ButtonLog(int bId, std::wstring bName, int vMode)
{ {
functionId = fId; buttonId = bId;
functionName = fName; buttonName = bName;
mode = vMode; mode = vMode;
count = 1; count = 1;
} }
@ -72,9 +72,8 @@ 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 functionId, int mode); void UpdateButtonUsage(int buttonId, int mode);
void LogFunctionUsage(int); void LogButtonUsage();
// 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);
@ -95,7 +94,7 @@ namespace CalculatorApp
void LogConversionResult(std::wstring_view fromValue, std::wstring_view fromUnit, std::wstring_view toValue, std::wstring_view toUnit) const; void LogConversionResult(std::wstring_view fromValue, std::wstring_view fromUnit, std::wstring_view toValue, std::wstring_view toUnit) const;
void LogAboutFlyoutOpened() const; void LogAboutFlyoutOpened() const;
void LogNavBarOpened() const; void LogNavBarOpened() const;
void LogViewClosingTelemetry(int); void LogViewClosingTelemetry();
void LogCoreWindowWasNull() const; void LogCoreWindowWasNull() const;
// Trace methods for Date Calculator usage // Trace methods for Date Calculator usage
@ -134,12 +133,9 @@ namespace CalculatorApp
bool bitLengthButtonLoggedInSession = false; bool bitLengthButtonLoggedInSession = false;
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<ButtonLog> buttonLog;
//int functionCount = 0;
bool isHypButtonLogged = false; bool isHypButtonLogged = false;
bool isAngleButtonInitialized = false; bool isAngleButtonInitialized = false;
//unsigned int findIndex[maxFunctionSize] = { 0 };
//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;
@ -156,7 +152,7 @@ namespace CalculatorApp
std::map<int, int> m_dateAddModeUsage; std::map<int, int> m_dateAddModeUsage;
std::map<int, int> m_dateSubtractModeUsage; std::map<int, int> m_dateSubtractModeUsage;
size_t windowLaunchCount = 0; size_t currentWindowCount = 0;
winrt::Windows::Foundation::Diagnostics::LoggingActivity m_appLaunchActivity; winrt::Windows::Foundation::Diagnostics::LoggingActivity m_appLaunchActivity;
}; };

View file

@ -618,7 +618,7 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
mode = ViewMode::Programmer; mode = ViewMode::Programmer;
} }
TraceLogger::GetInstance().UpdateFunctionUsage((int)numOpEnum, (int)mode); TraceLogger::GetInstance().UpdateButtonUsage((int)numOpEnum, (int)mode);
} }
if (IsInError) if (IsInError)

View file

@ -1,108 +0,0 @@
#pragma once
namespace CalculatorApp
{
public enum TraceLoggerCalculatorModeEnum
{
Standard,
Scientific,
Programmer,
DateCalculation,
CurrencyConverter,
VolumeConverter,
LengthConverter,
WeightMassConverter,
TemperatureConverter,
EnergyConverter,
AreaConverter,
SpeedConverter,
TimeConverter,
};
public enum TraceLoggerButtonIdEnum
{
// Numberpad
ZeroButton,
OneButton,
TwoButton,
ThreeButton,
FourButton,
FiveButton,
SixButton,
SevenButton,
EightButton,
NineButton,
DecimalButton,
// Standard Operators
NegateButton,
EqualsButton,
PlusButton,
MinusButton,
MultiplyButton,
DivideButton,
PercentButton,
SquareRootButton,
XPower2Button,
XPower3Button,
OpenParenthesisButton,
CloseParenthesisButton,
// Display Controls
BackspaceButton,
ClearButton,
ClearEntryButton,
// Scientific Operators
InvertButton,
SinButton,
CosButton,
TanButton,
InvsinButton,
InvcosButton,
InvtanButton,
SinhButton,
CoshButton,
TanhButton,
InvsinhButton,
InvcoshButton,
InvtanhButton,
LogBase10Button,
ExpButton,
ModButton,
LogBaseEButton,
DmsButton,
DegreesButton,
FactorialButton,
PowerOf10Button,
PowerOfEButton,
ShiftButton,
PiButton,
YSquareRootButton,
PowerButton,
// Programmer Operators
RolButton,
RorButton,
LshButton,
RshButton,
OrButton,
XorButton,
NotButton,
AndButton,
// Programmer Numberpad
AButton,
BButton,
CButton,
DButton,
EButton,
FButton
};
public enum TraceLoggerInputMethodEnum
{
PhysicalKeyboard,
OnScreenKeyboard
};
}

View file

@ -140,7 +140,7 @@ namespace CalculatorApp
{ {
if (coreWindow) if (coreWindow)
{ {
TraceLogger::GetInstance().LogViewClosingTelemetry(ApplicationView::GetApplicationViewIdForWindow(coreWindow)); TraceLogger::GetInstance().LogViewClosingTelemetry();
} }
else else
{ {