Feat/usage stats collection (#317)
* feat: implement anonymous usage data collection Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com>
This commit is contained in:
parent
b25335acbd
commit
1c9b2572ae
23 changed files with 613 additions and 17 deletions
36
API/DTOs/ClientInfoDto.cs
Normal file
36
API/DTOs/ClientInfoDto.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
|
||||
namespace API.DTOs
|
||||
{
|
||||
public class ClientInfoDto
|
||||
{
|
||||
public ClientInfoDto()
|
||||
{
|
||||
CollectedAt = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public string KavitaUiVersion { get; set; }
|
||||
public string ScreenResolution { get; set; }
|
||||
public string PlatformType { get; set; }
|
||||
public DetailsVersion Browser { get; set; }
|
||||
public DetailsVersion Os { get; set; }
|
||||
|
||||
public DateTime? CollectedAt { get; set; }
|
||||
|
||||
public bool IsTheSameDevice(ClientInfoDto clientInfoDto)
|
||||
{
|
||||
return (clientInfoDto.ScreenResolution ?? "").Equals(ScreenResolution) &&
|
||||
(clientInfoDto.PlatformType ?? "").Equals(PlatformType) &&
|
||||
(clientInfoDto.Browser?.Name ?? "").Equals(Browser?.Name) &&
|
||||
(clientInfoDto.Os?.Name ?? "").Equals(Os?.Name) &&
|
||||
clientInfoDto.CollectedAt.GetValueOrDefault().ToString("yyyy-MM-dd")
|
||||
.Equals(CollectedAt.GetValueOrDefault().ToString("yyyy-MM-dd"));
|
||||
}
|
||||
}
|
||||
|
||||
public class DetailsVersion
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
12
API/DTOs/ServerInfoDto.cs
Normal file
12
API/DTOs/ServerInfoDto.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
namespace API.DTOs
|
||||
{
|
||||
public class ServerInfoDto
|
||||
{
|
||||
public string Os { get; set; }
|
||||
public string DotNetVersion { get; set; }
|
||||
public string RunTimeVersion { get; set; }
|
||||
public string KavitaVersion { get; set; }
|
||||
public string BuildBranch { get; set; }
|
||||
public string Culture { get; set; }
|
||||
}
|
||||
}
|
|
@ -7,5 +7,6 @@
|
|||
public string LoggingLevel { get; set; }
|
||||
public string TaskBackup { get; set; }
|
||||
public int Port { get; set; }
|
||||
public bool AllowStatCollection { get; set; }
|
||||
}
|
||||
}
|
24
API/DTOs/UsageInfoDto.cs
Normal file
24
API/DTOs/UsageInfoDto.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System.Collections.Generic;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.DTOs
|
||||
{
|
||||
public class UsageInfoDto
|
||||
{
|
||||
public UsageInfoDto()
|
||||
{
|
||||
FileTypes = new HashSet<string>();
|
||||
LibraryTypesCreated = new HashSet<LibInfo>();
|
||||
}
|
||||
|
||||
public int UsersCount { get; set; }
|
||||
public IEnumerable<string> FileTypes { get; set; }
|
||||
public IEnumerable<LibInfo> LibraryTypesCreated { get; set; }
|
||||
}
|
||||
|
||||
public class LibInfo
|
||||
{
|
||||
public LibraryType Type { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
33
API/DTOs/UsageStatisticsDto.cs
Normal file
33
API/DTOs/UsageStatisticsDto.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace API.DTOs
|
||||
{
|
||||
public class UsageStatisticsDto
|
||||
{
|
||||
public UsageStatisticsDto()
|
||||
{
|
||||
MarkAsUpdatedNow();
|
||||
ClientsInfo = new List<ClientInfoDto>();
|
||||
}
|
||||
|
||||
public string InstallId { get; set; }
|
||||
public DateTime LastUpdate { get; set; }
|
||||
public UsageInfoDto UsageInfo { get; set; }
|
||||
public ServerInfoDto ServerInfo { get; set; }
|
||||
public List<ClientInfoDto> ClientsInfo { get; set; }
|
||||
|
||||
public void MarkAsUpdatedNow()
|
||||
{
|
||||
LastUpdate = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void AddClientInfo(ClientInfoDto clientInfoDto)
|
||||
{
|
||||
if (ClientsInfo.Any(x => x.IsTheSameDevice(clientInfoDto))) return;
|
||||
|
||||
ClientsInfo.Add(clientInfoDto);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue