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
+17 -2
View File
@@ -10,6 +10,7 @@ using Model.Website;
using Model.Website.Enums;
using Model.Work.Tasks;
using Services.Immortal;
using Services.Website;
namespace Services;
@@ -25,6 +26,12 @@ public interface IToastService
void ClearAllToasts();
}
public interface IDataCollectionService
{
public void SendEvent<T>(string eventName, T eventData);
}
public interface IStorageService
{
public void Subscribe(Action action);
@@ -45,8 +52,6 @@ public interface IPermissionService
public void SetIsStorageEnabled(bool isEnabled);
public void SetIsDataCollectionEnabled(bool isEnabled);
Task Load();
}
public interface ISearchService
@@ -69,6 +74,16 @@ public interface ISearchService
void Hide();
}
public interface IDialogService
{
public bool IsVisible { get; set; }
public void Subscribe(Action action);
public void Unsubscribe(Action action);
public void Show(DialogContents dialogContents);
public DialogContents GetDialogContents();
public void Hide();
}
public interface IVariableService
{
public Dictionary<string, string> Variables { get; set; }
+1 -12
View File
@@ -338,8 +338,6 @@ public class BuildOrderService : IBuildOrderService
public int? WillMeetTrainingQueue(EntityModel entity)
{
Console.WriteLine($"WillMeetTrainingQueue {entity.Info().Name}");
var supply = entity.Supply();
var production = entity.Production();
@@ -347,15 +345,12 @@ public class BuildOrderService : IBuildOrderService
if (supply == null || production == null || supply.Takes.Equals(0))
{
Console.WriteLine(supply == null ? "Was Null" : supply.Takes);
return 1;
}
var producedBy = production.ProducedBy;
if (producedBy == null)
{
Console.WriteLine("Produced by Nothing");
return 1;
}
@@ -377,10 +372,7 @@ public class BuildOrderService : IBuildOrderService
usedSlots += used.UsedSlots;
var duration = used.StopUsageTime - used.StartingUsageTime;
if (duration < shortestIncrement) shortestIncrement = duration;
Console.WriteLine(
$"Used slots {used.UsedSlots} Duration {duration} Start {used.StartingUsageTime} Stop {used.StopUsageTime} ");
}
}
if (usedSlots + supply.Takes <= trainingSlots)
{
@@ -391,8 +383,6 @@ public class BuildOrderService : IBuildOrderService
Message = $"Had to wait {checkedInterval - _lastInterval}s for Training Queue."
});
Console.WriteLine($"Time {checkedInterval} did Delay {didDelay}");
return checkedInterval;
}
@@ -401,7 +391,6 @@ public class BuildOrderService : IBuildOrderService
if (shortestIncrement == int.MaxValue)
{
Console.WriteLine("MaxValue");
return null;
}
}
+6 -5
View File
@@ -15,14 +15,15 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0-preview.1"/>
<PackageReference Include="Microsoft.AspNetCore.Components.ProtectedBrowserStorage" Version="5.0.0-rc.1.20451.17"/>
<PackageReference Include="Microsoft.JSInterop" Version="7.0.0-preview.2.22153.2"/>
<PackageReference Include="YamlDotNet" Version="11.2.1"/>
<PackageReference Include="Blazor-Analytics" Version="3.11.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0-preview.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.ProtectedBrowserStorage" Version="5.0.0-rc.1.20451.17" />
<PackageReference Include="Microsoft.JSInterop" Version="7.0.0-preview.2.22153.2" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj"/>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>
+50
View File
@@ -0,0 +1,50 @@
using Blazor.Analytics;
using Blazored.LocalStorage;
using Model.Feedback;
namespace Services.Website;
public class DataCollectionKeys
{
// Inputs people are using in the build calculator
public static string BuildCalcInput = "buildcalc-input";
public static string PageInitialized = "page-initialized";
public static string FirstPage = "first-page";
}
public class DataCollectionService : IDataCollectionService, IDisposable
{
private readonly IStorageService _storageService;
private bool _isEnabled = false;
private readonly IAnalytics _globalTracking;
public DataCollectionService(IAnalytics globalTracking,
IStorageService storageService)
{
_globalTracking = globalTracking;
_storageService = storageService;
_storageService.Subscribe(Refresh);
Refresh();
}
void IDisposable.Dispose()
{
_storageService.Unsubscribe(Refresh);
}
private void Refresh()
{
_isEnabled = _storageService.GetValue<bool>(StorageKeys.EnabledDataCollection);
}
public void SendEvent<T>(string eventName, T eventData)
{
if (_isEnabled)
{
_globalTracking.TrackEvent(eventName, eventData);
}
}
}
+63
View File
@@ -0,0 +1,63 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Model.Entity.Data;
using Model.Website;
namespace Services.Website;
public class DialogContents
{
public string Title { get; set; }
public string Message { get; set; }
public string ConfirmButtonLabel { get; set; }
public EventCallback<EventArgs> OnConfirm { get; set; }
public EventCallback<EventArgs> OnCancel { get; set; }
}
public class DialogService : IDialogService
{
private DialogContents _dialogContents;
public DialogService()
{
}
public bool IsVisible { get; set; }
public void Subscribe(Action action)
{
OnChange += action;
}
public void Unsubscribe(Action action)
{
OnChange += action;
}
public void Show(DialogContents dialogContents)
{
_dialogContents = dialogContents;
IsVisible = true;
NotifyDataChanged();
}
public DialogContents GetDialogContents()
{
return _dialogContents;
}
public void Hide()
{
IsVisible = false;
NotifyDataChanged();
}
private event Action OnChange = null!;
private void NotifyDataChanged()
{
OnChange();
}
}
+8 -6
View File
@@ -2,7 +2,7 @@
namespace Services.Website;
public class PermissionService : IPermissionService
public class PermissionService : IPermissionService, IDisposable
{
private IJSRuntime _jsRuntime;
private readonly IStorageService _storageService;
@@ -15,6 +15,13 @@ public class PermissionService : IPermissionService
_jsRuntime = jsRuntime;
_toastService = toastService;
_storageService = storageService;
_storageService.Subscribe(NotifyDataChanged);
}
void IDisposable.Dispose()
{
_storageService.Unsubscribe(NotifyDataChanged);
}
public void Subscribe(Action action)
@@ -47,11 +54,6 @@ public class PermissionService : IPermissionService
_storageService.SetValue(StorageKeys.EnabledDataCollection, isEnabled);
}
public Task Load()
{
throw new NotImplementedException();
}
private event Action OnChange = null!;
private void NotifyDataChanged()
-16
View File
@@ -54,28 +54,12 @@ public class StorageService : IStorageService
{
_localStorageService.SetItem(key, value);
NotifyDataChanged();
_toastService.AddToast(new ToastModel
{
Title = "Test 1",
SeverityType = SeverityType.Error,
Message = "Storage must be enabled before Storage can be used."
});
return;
}
if (key.Equals(StorageKeys.EnabledStorage))
{
_localStorageService.Clear();
_toastService.AddToast(new ToastModel
{
Title = "Test 2",
SeverityType = SeverityType.Error,
Message = "Storage must be enabled before Storage can be used."
});
NotifyDataChanged();
return;
}