Skip to content

Commit

Permalink
Optimize speed
Browse files Browse the repository at this point in the history
  • Loading branch information
JimGeersinga committed Nov 13, 2024
1 parent 20ad68a commit 395104c
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 283 deletions.
52 changes: 41 additions & 11 deletions NED.WoT.BattleResults.Client/Components/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@page "/"
@using System.Collections.ObjectModel;
@using System.Collections.Specialized;
@using System.Diagnostics

@inject BattleReportService BattleResultService;
@inject SettingService SettingService;
Expand Down Expand Up @@ -61,7 +62,6 @@
<MudTh Style="text-align: center">#</MudTh>
</HeaderContent>
<GroupHeaderTemplate>

<MudTh Class="mud-table-cell-custom-group " colspan="7">
@{
var wins = context.Items.Count(x => x.IsWin(SettingService.Settings));
Expand Down Expand Up @@ -98,13 +98,19 @@
<MudTh colspan="2" />
</GroupHeaderTemplate>
<RowTemplate>
@if (context.Error != null)
@if (_loading)
{
<MudTd colspan="9">
<MudSkeleton Animation="Animation.Wave" />
</MudTd>
}
else if (context.Error != null)
{
<MudTd colspan="7"><MudAlert Severity="Severity.Warning">@context.Error</MudAlert></MudTd>
}
else
{
var group = _reports.Where(x => TableFilter(x)).GroupBy(x => x.Group).First(x => x.Any(i => i.FileName == context.FileName)).OrderBy(x => x.MatchStart).ToList();
var group = _filteredReports.GroupBy(x => x.Group).First(x => x.Any(i => i.FileName == context.FileName)).OrderBy(x => x.MatchStart).ToList();
var index = group.FindIndex(x => x.FileName == context.FileName) + 1;

Team ownTeam = context.GetOwnTeam(SettingService.Settings);
Expand Down Expand Up @@ -180,7 +186,9 @@
var percentage_color = winPercentage > 50 ? "Win" : winPercentage < 40 ? "Lose" : "Draw";
}
<div class="d-flex justify-space-between">
<MudText Typo="Typo.subtitle1" Class="d-inline text-bold">Totaal <b>@_filteredReports.Count</b> gevechten <span class="ml-2 @percentage_color">@winPercentage.ToString("0.00")%</span></MudText>
<MudText Typo="Typo.subtitle1" Class="d-inline text-bold">Totaal <b>@_filteredReports.Count()</b> gevechten <span class="ml-2 @percentage_color">@winPercentage.ToString("0.00")%</span></MudText>



<MudText Typo="Typo.subtitle1" Class="d-inline mr-12">
<b class="@Result.Win.ToString()">@wins</b> Gewonnen
Expand All @@ -193,7 +201,12 @@
</MudText>
</div>
</MudTd>
<MudTd Class="mud-background-gray" colspan="2"></MudTd>
<MudTd Class="mud-background-gray text-right" colspan="2">
@if (_loadingTime != TimeSpan.Zero)
{
<MudText Typo="Typo.subtitle2"> @_loadingTime.ToString(@"hh\:mm\:ss\.fff")</MudText>
}
</MudTd>
</FooterContent>
</MudTable>

Expand All @@ -203,11 +216,12 @@
private bool _loading = true;
private string searchString = "";
private bool _hideNormalMatchMaking = true;
private TimeSpan _loadingTime = TimeSpan.Zero;

private bool _showOnlyUnkown = false;

private List<BattleReport> _reports = new List<BattleReport>();
private List<BattleReport> _filteredReports => _reports.Where(x => TableFilter(x)).ToList();
private IEnumerable<BattleReport> _filteredReports => _reports.Where(x => TableFilter(x));
private TableGroupDefinition<BattleReport> _groupDefinition = new()
{
Indentation = false,
Expand All @@ -217,32 +231,48 @@

protected override async Task OnInitializedAsync()
{
long timestamp = 0;

BattleResultService.LoadingBattleReportsStarted += async (s, e) =>
{
await InvokeAsync(() =>
{
_reports = new List<BattleReport>();
_loading = true;
timestamp = Stopwatch.GetTimestamp();
StateHasChanged();
});
};

BattleResultService.BattleReportAdded += (s, e) =>
BattleResultService.BattleReportAdded += async (s, e) =>
{
_reports.Add(e.Report);
await InvokeAsync(() =>
{
_reports.Add(e.Report);
if (_loading)
{
_loadingTime = Stopwatch.GetElapsedTime(timestamp);
}
StateHasChanged();
});
};

BattleResultService.BattleReportRemoved += (s, e) =>
BattleResultService.BattleReportRemoved += async (s, e) =>
{
_reports.Remove(e.Report);
await InvokeAsync(() =>
{
_reports.Remove(e.Report);
StateHasChanged();
});
};

BattleResultService.LoadingBattleReportsFinished += async (s, e) =>
{
await InvokeAsync(() =>
{
_reports = BattleResultService.BattleReports.OrderByDescending(x => x.Value.MatchStart).Select(x => x.Value).ToList();
_reports = BattleResultService.BattleReports.Select(x => x.Value).OrderByDescending(x => x.MatchStart).ToList();
_loading = false;
_loadingTime = Stopwatch.GetElapsedTime(timestamp);
StateHasChanged();
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@code {
[CascadingParameter] MudDialogInstance MudDialog { get; set; }

[Parameter] public List<BattleReport> Reports { get; set; } = [];
[Parameter] public IEnumerable<BattleReport> Reports { get; set; } = [];


private IEnumerable<ClanMember> GetClanMembers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

<MudSwitch Label="Alleen eigen match results highlighten" Color="Color.Primary"
@bind-Value="@modal.OnlyHighlistOwnMatches" For="(() => modal.OnlyHighlistOwnMatches)" />

<MudSwitch Label="Update het scherm voor ieder rapport bij opstarten" Color="Color.Primary"
@bind-Value="@modal.StartupUpdateOnEveryReport" For="(() => modal.StartupUpdateOnEveryReport)" />
</DialogContent>
<DialogActions>
<MudButton OnClick="AppInfo.Current.ShowSettingsUI" Class="mr-auto">Ga naar app settings</MudButton>
Expand Down Expand Up @@ -59,7 +62,8 @@
ClanAbbreviation = SettingService.Settings.ClanAbbreviation,
PlayerName = SettingService.Settings.PlayerName,
SingleBattleResultOpenedOnly = SettingService.Settings.SingleBattleResultOpenedOnly,
OnlyHighlistOwnMatches = SettingService.Settings.OnlyHighlistOwnMatches
OnlyHighlistOwnMatches = SettingService.Settings.OnlyHighlistOwnMatches,
StartupUpdateOnEveryReport = SettingService.Settings.StartupUpdateOnEveryReport
};
}

Expand All @@ -77,6 +81,7 @@
settings.PlayerName = modal.PlayerName;
settings.SingleBattleResultOpenedOnly = modal.SingleBattleResultOpenedOnly;
settings.OnlyHighlistOwnMatches = modal.OnlyHighlistOwnMatches;
settings.StartupUpdateOnEveryReport = modal.StartupUpdateOnEveryReport;

SettingService.Save(settings);

Expand All @@ -103,5 +108,6 @@

public bool OnlyHighlistOwnMatches { get; set; }

public bool StartupUpdateOnEveryReport { get; set; }
}
}
2 changes: 1 addition & 1 deletion NED.WoT.BattleResults.Client/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
MauiAppBuilder builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
Expand Down
12 changes: 6 additions & 6 deletions NED.WoT.BattleResults.Client/Models/BattleReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public MarkupString MatchDurationDisplay
{
get
{
var duration = string.Empty;
string duration = string.Empty;
if (MatchDuration.HasValue)
{
var time = new TimeSpan(MatchDuration.Value * TimeSpan.TicksPerSecond);
var minutes = time.Minutes.ToString();
TimeSpan time = new TimeSpan(MatchDuration.Value * TimeSpan.TicksPerSecond);
string minutes = time.Minutes.ToString();
if (minutes.Length == 1) minutes = "&nbsp;&nbsp;" + minutes;
var seconds = time.Seconds.ToString();
string seconds = time.Seconds.ToString();
if (seconds.Length == 1) seconds = "&nbsp;&nbsp;" + seconds;

return (MarkupString)$"{minutes}m {seconds}s";
Expand All @@ -58,7 +58,7 @@ public string Group
{
get
{
var daysAgo = (DateTime.Now.Date - MatchStart.Date).Days;
int daysAgo = (DateTime.Now.Date - MatchStart.Date).Days;
if (MatchStart.Hour <= 2)
{
daysAgo += 1;
Expand Down Expand Up @@ -157,7 +157,7 @@ public bool IsOwnTeam(Settings settings)

public string GetResult(string map)
{
var lines = Players.Where(x => x.Name != null).OrderByDescending(x => x.ExperienceEarned).Select(x => x.Name).ToList();
List<string> lines = Players.Where(x => x.Name != null).OrderByDescending(x => x.ExperienceEarned).Select(x => x.Name).ToList();
lines.Insert(0, $"{map} {(Number == 1 ? "I" : "II")}");
lines.Insert(1, ResultDisplay);

Expand Down
1 change: 1 addition & 0 deletions NED.WoT.BattleResults.Client/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class Settings
public bool ShowCopyNamesOnlyWhenClanMatches { get; set; }
public bool SingleBattleResultOpenedOnly { get; set; }
public bool OnlyHighlistOwnMatches { get; set; }
public bool StartupUpdateOnEveryReport { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">

<Identity Name="maui-package-name-placeholder" Publisher="CN=JimG" Version="1.11.1.0" />
<Identity Name="maui-package-name-placeholder" Publisher="CN=JimG" Version="1.11.2.0" />

<mp:PhoneIdentity PhoneProductId="3DAE7680-3F65-440F-908F-252D648F20FC" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
Loading

0 comments on commit 395104c

Please sign in to comment.