Skip to content

Commit

Permalink
Optimise previous commit, proper null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Plenyx committed Feb 23, 2024
1 parent e7be5c1 commit 0e5e9eb
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 51 deletions.
18 changes: 16 additions & 2 deletions DpsReport/ExtraJSON/StatsBarrier.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System.Linq;
using System;

namespace PlenBotLogUploader.DpsReport.ExtraJson
{
Expand All @@ -11,6 +11,20 @@ internal class StatsBarrier
[JsonProperty("outgoingBarrierAllies")]
internal OutgoingBarrier[][] OutgoingBarrierAllies { get; set; }

internal long TotalBarrierOnSquad => OutgoingBarrierAllies.Sum(x => x.Sum(y => y.Barrier));
internal long TotalBarrierOnSquad
{
get
{
long result = 0;
foreach (var squadMember in OutgoingBarrierAllies.AsSpan())
{
foreach (var squadMemberPhase in squadMember.AsSpan())
{
result += squadMemberPhase.Barrier;
}
}
return result;
}
}
}
}
18 changes: 16 additions & 2 deletions DpsReport/ExtraJSON/StatsHealing.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using System.Linq;
using System;

namespace PlenBotLogUploader.DpsReport.ExtraJson
{
Expand All @@ -11,6 +11,20 @@ internal class StatsHealing
[JsonProperty("outgoingHealingAllies")]
internal OutgoingHealing[][] OutgoingHealingAllies { get; set; }

internal long TotalHealingOnSquad => OutgoingHealingAllies.Sum(x => x.Sum(y => y.Healing));
internal long TotalHealingOnSquad
{
get
{
long result = 0;
foreach (var squadMember in OutgoingHealingAllies.AsSpan())
{
foreach (var squadMemberPhase in squadMember.AsSpan())
{
result += squadMemberPhase.Healing;
}
}
return result;
}
}
}
}
100 changes: 54 additions & 46 deletions Forms/FormDiscordWebhooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,57 +264,65 @@ internal async Task ExecuteAllActiveWebhooksAsync(DpsReportJson reportJSON, List
Value = $"```{boonStripsSummary.Render()}```",
};
// healing summary
var healingStats = reportJSON.ExtraJson.Players
.Where(x => !x.FriendlyNpc && !x.NotInSquad && ((x.StatsHealing?.TotalHealingOnSquad ?? 0) > 0))
.OrderByDescending(x => x.StatsHealing?.TotalHealingOnSquad ?? 0)
.Take(10)
.ToArray();
var healingSummary = new TextTable(3, tableStyle, tableBorders);
healingSummary.SetColumnWidthRange(0, 3, 3);
healingSummary.SetColumnWidthRange(1, 27, 27);
healingSummary.SetColumnWidthRange(2, 12, 12);
healingSummary.AddCell("#", tableCellCenterAlign);
healingSummary.AddCell("Name");
healingSummary.AddCell("Healing", tableCellRightAlign);
rank = 0;
foreach (var player in healingStats)
DiscordApiJsonContentEmbedField healingField = null;
if ((reportJSON?.ExtraJson?.Players?[0]?.StatsHealing ?? null) is not null)
{
rank++;
healingSummary.AddCell($"{rank}", tableCellCenterAlign);
healingSummary.AddCell($"{player.Name} ({player.ProfessionShort})");
healingSummary.AddCell($"{(player.StatsHealing?.TotalHealingOnSquad ?? 0).ParseAsK()}", tableCellRightAlign);
var healingStats = reportJSON.ExtraJson.Players
.Where(x => !x.FriendlyNpc && !x.NotInSquad && ((x.StatsHealing?.TotalHealingOnSquad ?? 0) > 0))
.OrderByDescending(x => x.StatsHealing?.TotalHealingOnSquad ?? 0)
.Take(10)
.ToArray();
var healingSummary = new TextTable(3, tableStyle, tableBorders);
healingSummary.SetColumnWidthRange(0, 3, 3);
healingSummary.SetColumnWidthRange(1, 27, 27);
healingSummary.SetColumnWidthRange(2, 12, 12);
healingSummary.AddCell("#", tableCellCenterAlign);
healingSummary.AddCell("Name");
healingSummary.AddCell("Healing", tableCellRightAlign);
rank = 0;
foreach (var player in healingStats)
{
rank++;
healingSummary.AddCell($"{rank}", tableCellCenterAlign);
healingSummary.AddCell($"{player.Name} ({player.ProfessionShort})");
healingSummary.AddCell($"{(player.StatsHealing?.TotalHealingOnSquad ?? 0).ParseAsK()}", tableCellRightAlign);
}
healingField = new DiscordApiJsonContentEmbedField()
{
Name = "Healing summary:",
Value = $"```{healingSummary.Render()}```",
};
}
var healingField = new DiscordApiJsonContentEmbedField()
{
Name = "Healing summary:",
Value = $"```{healingSummary.Render()}```",
};
// barrier summary
var barrierStats = reportJSON.ExtraJson.Players
.Where(x => !x.FriendlyNpc && !x.NotInSquad && ((x.StatsBarrier?.TotalBarrierOnSquad ?? 0) > 0))
.OrderByDescending(x => x.StatsBarrier?.TotalBarrierOnSquad ?? 0)
.Take(10)
.ToArray();
var barrierSummary = new TextTable(3, tableStyle, tableBorders);
barrierSummary.SetColumnWidthRange(0, 3, 3);
barrierSummary.SetColumnWidthRange(1, 27, 27);
barrierSummary.SetColumnWidthRange(2, 12, 12);
barrierSummary.AddCell("#", tableCellCenterAlign);
barrierSummary.AddCell("Name");
barrierSummary.AddCell("Barrier", tableCellRightAlign);
rank = 0;
foreach (var player in barrierStats)
DiscordApiJsonContentEmbedField barrierField = null;
if ((reportJSON?.ExtraJson?.Players?[0]?.StatsBarrier ?? null) is not null)
{
rank++;
barrierSummary.AddCell($"{rank}", tableCellCenterAlign);
barrierSummary.AddCell($"{player.Name} ({player.ProfessionShort})");
barrierSummary.AddCell($"{(player.StatsBarrier?.TotalBarrierOnSquad ?? 0).ParseAsK()}", tableCellRightAlign);
var barrierStats = reportJSON.ExtraJson.Players
.Where(x => !x.FriendlyNpc && !x.NotInSquad && ((x.StatsBarrier?.TotalBarrierOnSquad ?? 0) > 0))
.OrderByDescending(x => x.StatsBarrier?.TotalBarrierOnSquad ?? 0)
.Take(10)
.ToArray();
var barrierSummary = new TextTable(3, tableStyle, tableBorders);
barrierSummary.SetColumnWidthRange(0, 3, 3);
barrierSummary.SetColumnWidthRange(1, 27, 27);
barrierSummary.SetColumnWidthRange(2, 12, 12);
barrierSummary.AddCell("#", tableCellCenterAlign);
barrierSummary.AddCell("Name");
barrierSummary.AddCell("Barrier", tableCellRightAlign);
rank = 0;
foreach (var player in barrierStats)
{
rank++;
barrierSummary.AddCell($"{rank}", tableCellCenterAlign);
barrierSummary.AddCell($"{player.Name} ({player.ProfessionShort})");
barrierSummary.AddCell($"{(player.StatsBarrier?.TotalBarrierOnSquad ?? 0).ParseAsK()}", tableCellRightAlign);
}
barrierField = new DiscordApiJsonContentEmbedField()
{
Name = "Barrier summary:",
Value = $"```{barrierSummary.Render()}```",
};
}
var barrierField = new DiscordApiJsonContentEmbedField()
{
Name = "Barrier summary:",
Value = $"```{barrierSummary.Render()}```",
};
// add the fields
discordContentEmbedSquadAndPlayers.AddRange(squadField, enemyField, damageField, cleansesField, boonStripsField, healingField, barrierField);
discordContentEmbedSquad.AddRange(squadField, enemyField);
Expand Down
9 changes: 8 additions & 1 deletion Tools/ClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ internal static void AddRange<T>(this List<T> list, params T[] items)
{
return;
}
list.AddRange(items);
foreach (var item in items.AsSpan())
{
if (item is null)
{
continue;
}
list.Add(item);
}
}

internal static async Task<GitHubReleaseLatest> GetGitHubLatestReleaseAsync(this HttpClientController controller, string repository)
Expand Down

0 comments on commit 0e5e9eb

Please sign in to comment.