feat(DataCollection) Added opt-in data collection

This commit is contained in:
2022-04-25 12:43:23 -04:00
parent 5e9ed4c2f5
commit 43d7391df2
79 changed files with 798 additions and 283 deletions
@@ -1,16 +1,20 @@
@layout PageLayout
@inject IStringLocalizer<Localizations> locale
@inherits BasePage
@inject IKeyService keyService
@inject IImmortalSelectionService filterService
@inject IBuildOrderService buildOrderService
@inject IEconomyService economyService
@inject IToastService toastService
@inject ITimingService timingService
@inject IStringLocalizer<Localizations> Locale
@inject IKeyService KeyService
@inject IImmortalSelectionService FilterService
@inject IBuildOrderService BuildOrderService
@inject IEconomyService EconomyService
@inject IToastService ToastService
@inject ITimingService TimingService
@inject IDataCollectionService DataCollectionService
@page "/build-calculator"
@using Services.Website
@implements IDisposable
<LayoutLargeContentComponent>
@@ -29,18 +33,18 @@
<div class="gridItem" style="grid-area: timing;">
<ButtonComponent ButtonType="ButtonType.Secondary" OnClick="OnResetClicked">Clear Build Order</ButtonComponent>
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Timing Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Timing Info"]">
<TimingComponent></TimingComponent>
</InfoTooltipComponent>
</PanelComponent>
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Filter Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Filter Info"]">
<FilterComponent></FilterComponent>
</InfoTooltipComponent>
</PanelComponent>
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Options Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Options Info"]">
<OptionsComponent></OptionsComponent>
</InfoTooltipComponent>
</PanelComponent>
@@ -49,7 +53,7 @@
<div class="gridItem" style="grid-area: chart;">
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Chart Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Chart Info"]">
<BuildChartComponent></BuildChartComponent>
</InfoTooltipComponent>
</PanelComponent>
@@ -57,7 +61,7 @@
<div class="gridItem" style="grid-area: view;">
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Entity Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Entity Info"]">
<EntityClickViewComponent/>
</InfoTooltipComponent>
@@ -66,7 +70,7 @@
<div class="gridItem" style="grid-area: bank;">
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Bank Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Bank Info"]">
<BankComponent></BankComponent>
</InfoTooltipComponent>
</PanelComponent>
@@ -74,7 +78,7 @@
<div class="gridItem" style="grid-area: army;">
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Army Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Army Info"]">
<ArmyComponent></ArmyComponent>
</InfoTooltipComponent>
</PanelComponent>
@@ -82,7 +86,7 @@
<div class="gridItem gridKeys">
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Hotkey Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Hotkey Info"]">
<HotkeyViewerComponent Size="80"></HotkeyViewerComponent>
</InfoTooltipComponent>
</PanelComponent>
@@ -90,7 +94,7 @@
<div class="gridItem" style="grid-area: highlights;">
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip Highlights Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip Highlights Info"]">
<HighlightsComponent></HighlightsComponent>
</InfoTooltipComponent>
</PanelComponent>
@@ -98,7 +102,7 @@
<div class="gridItem" style="grid-area: buildorder;">
<PanelComponent>
<InfoTooltipComponent InfoText="@locale["Tooltip BuildOrder Info"]">
<InfoTooltipComponent InfoText="@Locale["Tooltip BuildOrder Info"]">
<BuildOrderComponent></BuildOrderComponent>
</InfoTooltipComponent>
</PanelComponent>
@@ -216,32 +220,39 @@
protected override void OnInitialized()
{
economyService.Calculate(buildOrderService, timingService, 0);
base.OnInitialized();
EconomyService.Calculate(BuildOrderService, TimingService, 0);
keyService.Subscribe(HandleClick);
KeyService.Subscribe(HandleClick);
DataCollectionService.SendEvent(
DataCollectionKeys.PageInitialized,
new Dictionary<string, string> {{"page", "build-calculator"}}
);
}
void IDisposable.Dispose()
{
keyService.Unsubscribe(HandleClick);
KeyService.Unsubscribe(HandleClick);
}
private void OnResetClicked()
{
toastService.AddToast(new ToastModel
ToastService.AddToast(new ToastModel
{
SeverityType = SeverityType.Success,
Message = "Build order has been cleared.",
Title = "Reset"
});
buildOrderService.Reset();
BuildOrderService.Reset();
}
private void HandleClick()
{
var hotkey = keyService.GetHotkey();
var hotkey = KeyService.GetHotkey();
if (hotkey == "")
{
@@ -250,15 +261,15 @@
if (hotkey == "`")
{
buildOrderService.RemoveLast();
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
BuildOrderService.RemoveLast();
EconomyService.Calculate(BuildOrderService, TimingService, BuildOrderService.GetLastRequestInterval());
return;
}
var hotkeyGroup = keyService.GetHotkeyGroup();
var isHoldSpace = keyService.IsHoldingSpace();
var faction = filterService.GetFaction();
var immortal = filterService.GetImmortal();
var hotkeyGroup = KeyService.GetHotkeyGroup();
var isHoldSpace = KeyService.IsHoldingSpace();
var faction = FilterService.GetFaction();
var immortal = FilterService.GetImmortal();
var entity = EntityModel.GetFrom(hotkey!, hotkeyGroup, isHoldSpace, faction, immortal);
@@ -267,9 +278,9 @@
return;
}
if (buildOrderService.Add(entity, economyService))
if (BuildOrderService.Add(entity, EconomyService))
{
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
EconomyService.Calculate(BuildOrderService, TimingService, BuildOrderService.GetLastRequestInterval());
}
}
@@ -67,6 +67,7 @@
protected override void OnInitialized()
{
base.OnInitialized();
buildOrder.Subscribe(OnBuildOrderChanged);
timingService.Subscribe(StateHasChanged);
}
@@ -75,6 +75,7 @@
protected override void OnInitialized()
{
base.OnInitialized();
BuildOrderService.Subscribe(OnBuildOrderChanged);
}
@@ -81,6 +81,7 @@ else
protected override void OnInitialized()
{
base.OnInitialized();
buildOrderService.Subscribe(OnBuilderOrderChanged);
timingService.Subscribe(OnBuilderOrderChanged);
@@ -15,6 +15,7 @@
protected override void OnInitialized()
{
base.OnInitialized();
buildOrderService.Subscribe(StateHasChanged);
}
@@ -29,6 +29,7 @@
protected override void OnInitialized()
{
base.OnInitialized();
KeyService.Subscribe(HandleClick);
StorageService.Subscribe(RefreshDefaults);
@@ -60,6 +60,7 @@
protected override void OnInitialized()
{
base.OnInitialized();
economyService.Subscribe(StateHasChanged);
buildOrderService.Subscribe(StateHasChanged);
}
@@ -1,12 +1,14 @@
@inject IJSRuntime jsRuntime;
@inject IJSRuntime JsRuntime;
@using Services.Website
@implements IDisposable
@inject IKeyService keyService
@inject IBuildOrderService buildOrderService
@inject IImmortalSelectionService filterService
@inject IKeyService KeyService
@inject IBuildOrderService BuildOrderService
@inject IImmortalSelectionService FilterService
@inject IEconomyService economyService
@inject ITimingService timingService
@inject IToastService toastService
@inject IEconomyService EconomyService
@inject ITimingService TimingService
@inject IToastService ToastService
@inject IDataCollectionService DataCollectionService
<InputPanelComponent>
@@ -18,7 +20,7 @@
continue;
}
var color = hotkey.KeyText.Equals("SPACE") && keyService.IsHoldingSpace() || keyService.GetAllPressedKeys().Contains(hotkey.KeyText)
var color = hotkey.KeyText.Equals("SPACE") && KeyService.IsHoldingSpace() || KeyService.GetAllPressedKeys().Contains(hotkey.KeyText)
? "#0a0f12" : hotkey.GetColor();
var x = hotkey.PositionX * Size;
@@ -34,7 +36,7 @@
border = "5px solid green";
}
if (hotkey.KeyText.Equals("SPACE") && keyService.IsHoldingSpace())
if (hotkey.KeyText.Equals("SPACE") && KeyService.IsHoldingSpace())
{
border = "5px solid green";
}
@@ -46,7 +48,7 @@
width: 0px;
height: 0px;">
<div @onclick="x => { if (hotkey.KeyText.Equals(HotKeyType.SPACE.ToString())) { if (keyService.IsHoldingSpace()) { keyService.RemovePressedKey(hotkey.KeyText); } else { keyService.AddPressedKey(hotkey.KeyText); } } else { keyService.AddPressedKey(hotkey.KeyText); keyService.RemovePressedKey(hotkey.KeyText); }}" style="background-color:@color;
<div @onclick="((e)=> ButtonClicked(e, hotkey))" style="background-color:@color;
border: @border;
width: @Size.ToString()px;
height: @Size.ToString()px;
@@ -73,7 +75,7 @@
var isVanguard = entity.VanguardAdded() != null;
var style = isVanguard ? "font-weight: bold;" : "";
if (buildOrderService.WillMeetRequirements(entity) == null)
if (BuildOrderService.WillMeetRequirements(entity) == null)
{
style += "color:gray; font-style: italic;";
}
@@ -122,25 +124,25 @@
{
base.OnInitialized();
keyService.Subscribe(OnKeyPressed);
filterService.Subscribe(StateHasChanged);
buildOrderService.Subscribe(OnBuilderOrderChanged);
KeyService.Subscribe(OnKeyPressed);
FilterService.Subscribe(StateHasChanged);
BuildOrderService.Subscribe(OnBuilderOrderChanged);
}
void IDisposable.Dispose()
{
keyService.Unsubscribe(OnKeyPressed);
filterService.Unsubscribe(StateHasChanged);
buildOrderService.Unsubscribe(OnBuilderOrderChanged);
KeyService.Unsubscribe(OnKeyPressed);
FilterService.Unsubscribe(StateHasChanged);
BuildOrderService.Unsubscribe(OnBuilderOrderChanged);
}
int completedTimeCount = 0;
void OnBuilderOrderChanged()
{
if (buildOrderService.UniqueCompletedTimes.Count != completedTimeCount)
if (BuildOrderService.UniqueCompletedTimes.Count != completedTimeCount)
{
completedTimeCount = buildOrderService.UniqueCompletedTimes.Count;
completedTimeCount = BuildOrderService.UniqueCompletedTimes.Count;
StateHasChanged();
}
}
@@ -148,7 +150,7 @@
protected override bool ShouldRender()
{
#if DEBUG
jsRuntime.InvokeVoidAsync("console.time", "HotKeyViewerComponent");
JsRuntime.InvokeVoidAsync("console.time", "HotKeyViewerComponent");
#endif
return true;
@@ -157,14 +159,14 @@
protected override void OnAfterRender(bool firstRender)
{
#if DEBUG
jsRuntime.InvokeVoidAsync("console.timeEnd", "HotKeyViewerComponent");
JsRuntime.InvokeVoidAsync("console.timeEnd", "HotKeyViewerComponent");
#endif
}
// Move to Filter Service
bool InvalidFaction(EntityModel entity)
{
if (entity.Faction() != null && entity.Faction()?.Faction != filterService.GetFaction() && filterService.GetFaction() != DataType.Any)
if (entity.Faction() != null && entity.Faction()?.Faction != FilterService.GetFaction() && FilterService.GetFaction() != DataType.Any)
{
return true;
}
@@ -176,8 +178,8 @@
bool InvalidVanguard(EntityModel entity)
{
if (entity.VanguardAdded() != null
&& entity.VanguardAdded()?.ImmortalId != filterService.GetImmortal()
&& filterService.GetImmortal() != DataType.Any)
&& entity.VanguardAdded()?.ImmortalId != FilterService.GetImmortal()
&& FilterService.GetImmortal() != DataType.Any)
{
return true;
}
@@ -192,7 +194,7 @@
{
foreach (var replaced in entity.Replaceds())
{
if (filterService.GetImmortal() == replaced.ImmortalId)
if (FilterService.GetImmortal() == replaced.ImmortalId)
{
return true;
}
@@ -241,7 +243,7 @@
bool InvalidHoldSpace(EntityModel entity)
{
if (entity.Hotkey()?.HoldSpace == keyService.IsHoldingSpace())
if (entity.Hotkey()?.HoldSpace == KeyService.IsHoldingSpace())
{
return false;
}
@@ -254,44 +256,44 @@
var keyWas = key;
if (keyService.GetAllPressedKeys().Contains("Z"))
if (KeyService.GetAllPressedKeys().Contains("Z"))
{
controlGroup = "Z";
}
if (keyService.GetAllPressedKeys().Contains("TAB"))
if (KeyService.GetAllPressedKeys().Contains("TAB"))
{
controlGroup = "TAB";
}
if (keyService.GetAllPressedKeys().Contains("C"))
if (KeyService.GetAllPressedKeys().Contains("C"))
{
controlGroup = "C";
}
if (keyService.GetAllPressedKeys().Contains("D"))
if (KeyService.GetAllPressedKeys().Contains("D"))
{
controlGroup = "D";
}
if (keyService.GetAllPressedKeys().Contains("1"))
if (KeyService.GetAllPressedKeys().Contains("1"))
{
controlGroup = "1";
}
//TODO This could be better. Duplicated code
if (keyService.GetAllPressedKeys().Contains("2"))
if (KeyService.GetAllPressedKeys().Contains("2"))
{
controlGroup = "2";
}
if (keyService.GetAllPressedKeys().Contains("SHIFT"))
if (KeyService.GetAllPressedKeys().Contains("SHIFT"))
{
controlGroup = "SHIFT";
}
if (keyService.GetAllPressedKeys().Contains("CONTROL"))
if (KeyService.GetAllPressedKeys().Contains("CONTROL"))
{
controlGroup = "CONTROL";
}
if (keyService.GetAllPressedKeys().Count > 0)
if (KeyService.GetAllPressedKeys().Count > 0)
{
key = keyService.GetAllPressedKeys().First();
key = KeyService.GetAllPressedKeys().First();
}
if (controlGroupWas != controlGroup || keyWas != key)
@@ -303,7 +305,7 @@
private void HandleClick()
{
var hotkey = keyService.GetHotkey();
var hotkey = KeyService.GetHotkey();
if (hotkey == "")
{
@@ -312,15 +314,15 @@
if (hotkey == "`")
{
buildOrderService.RemoveLast();
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
BuildOrderService.RemoveLast();
EconomyService.Calculate(BuildOrderService, TimingService, BuildOrderService.GetLastRequestInterval());
return;
}
var hotkeyGroup = keyService.GetHotkeyGroup();
var isHoldSpace = keyService.IsHoldingSpace();
var faction = filterService.GetFaction();
var immortal = filterService.GetImmortal();
var hotkeyGroup = KeyService.GetHotkeyGroup();
var isHoldSpace = KeyService.IsHoldingSpace();
var faction = FilterService.GetFaction();
var immortal = FilterService.GetImmortal();
var entity = EntityModel.GetFrom(hotkey!, hotkeyGroup, isHoldSpace, faction, immortal);
@@ -329,9 +331,35 @@
return;
}
if (buildOrderService.Add(entity, economyService))
if (BuildOrderService.Add(entity, EconomyService))
{
economyService.Calculate(buildOrderService, timingService, buildOrderService.GetLastRequestInterval());
EconomyService.Calculate(BuildOrderService, TimingService, BuildOrderService.GetLastRequestInterval());
}
}
private void ButtonClicked(MouseEventArgs mouseEventArgs, HotkeyModel hotkey)
{
DataCollectionService.SendEvent(
DataCollectionKeys.BuildCalcInput,
new Dictionary<string, string> {{"key", hotkey.KeyText.ToLower()}, {"input-source", "mouse"}}
);
if (hotkey.KeyText.Equals(HotKeyType.SPACE.ToString()))
{
if (KeyService.IsHoldingSpace())
{
KeyService.RemovePressedKey(hotkey.KeyText);
}
else
{
KeyService.AddPressedKey(hotkey.KeyText);
}
}
else
{
KeyService.AddPressedKey(hotkey.KeyText);
KeyService.RemovePressedKey(hotkey.KeyText);
}
}
@@ -1,6 +1,8 @@
@inject IKeyService keyService
@using Services.Website
@inject IKeyService KeyService
@inject IJSRuntime jsRuntime;
@inject IDataCollectionService DataCollectionService
@inject IJSRuntime JsRuntime
<div tabindex="0"
@@ -19,18 +21,23 @@
private void HandleKeyDown(KeyboardEventArgs e)
{
keyService.AddPressedKey(e.Key);
DataCollectionService.SendEvent(
DataCollectionKeys.BuildCalcInput,
new Dictionary<string, string> {{"key", e.Key.ToLower()}, {"input-source", "keyboard"}}
);
KeyService.AddPressedKey(e.Key);
}
private void HandleKeyUp(KeyboardEventArgs e)
{
keyService.RemovePressedKey(e.Key);
KeyService.RemovePressedKey(e.Key);
}
protected override bool ShouldRender()
{
#if DEBUG
jsRuntime.InvokeVoidAsync("console.time", "InputPanelComponent");
JsRuntime.InvokeVoidAsync("console.time", "InputPanelComponent");
#endif
return true;
@@ -39,7 +46,7 @@
protected override void OnAfterRender(bool firstRender)
{
#if DEBUG
jsRuntime.InvokeVoidAsync("console.timeEnd", "InputPanelComponent");
JsRuntime.InvokeVoidAsync("console.timeEnd", "InputPanelComponent");
#endif
}
@@ -52,6 +52,7 @@
protected override void OnInitialized()
{
base.OnInitialized();
TimingService.Subscribe(RefreshDefaults);
RefreshDefaults();
@@ -58,6 +58,7 @@
protected override void OnInitialized()
{
base.OnInitialized();
economyService.Subscribe(StateHasChanged);
buildOrderService.Subscribe(StateHasChanged);
}
@@ -33,6 +33,7 @@
protected override void OnInitialized()
{
base.OnInitialized();
timingService.Subscribe(StateHasChanged);
}