diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index e33b34b0..e4c5aa68 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -523,8 +523,9 @@ namespace PluralKit.Bot title.Append($"`{targetSystem.Hid}`"); var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only"); + var showFlat = ctx.MatchFlag("flat"); var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, targetSystem.Id, target.Id, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, targetSystem, target, targetSystem.Zone, ctx.LookupContextFor(targetSystem), title.ToString(), ignoreNoFronters)); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, targetSystem, target, targetSystem.Zone, ctx.LookupContextFor(targetSystem), title.ToString(), ignoreNoFronters, showFlat)); } private async Task GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn) diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index 16520c31..eaef310c 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -135,8 +135,9 @@ namespace PluralKit.Bot title.Append($"`{system.Hid}`"); var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only"); + var showFlat = ctx.MatchFlag("flat"); var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, null, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, system.Zone, ctx.LookupContextFor(system), title.ToString(), ignoreNoFronters)); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, system.Zone, ctx.LookupContextFor(system), title.ToString(), ignoreNoFronters, showFlat)); } } } \ No newline at end of file diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index 50a20e2b..61d4484b 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -334,7 +334,7 @@ namespace PluralKit.Bot { return eb.Build(); } - public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle, bool ignoreNoFronters) + public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle, bool ignoreNoFronters, bool showFlat) { string color = system.Color; if (group != null) @@ -351,17 +351,32 @@ namespace PluralKit.Bot { { embedColor = DiscordUtils.Gray; } - - var period = breakdown.RangeEnd - breakdown.RangeStart; - var actualPeriod = period; - - if (ignoreNoFronters) - period = period - breakdown.NoFronterDuration; var eb = new EmbedBuilder() .Title(embedTitle) - .Color(embedColor) - .Footer(new($"Since {breakdown.RangeStart.FormatZoned(tz)} ({actualPeriod.FormatDuration()} ago)")); + .Color(embedColor); + + string footer = $"Since {breakdown.RangeStart.FormatZoned(tz)} ({(breakdown.RangeEnd - breakdown.RangeStart).FormatDuration()} ago)"; + + Duration period; + + if (showFlat) + { + period = Duration.FromTicks(breakdown.MemberSwitchDurations.Values.ToList().Sum(i => i.TotalTicks)); + footer += ". Showing flat list (percentages add up to 100%)"; + if (!ignoreNoFronters) period += breakdown.NoFronterDuration; + else footer += ", ignoring switch-outs"; + } + else if (ignoreNoFronters) + { + period = breakdown.RangeEnd - breakdown.RangeStart - breakdown.NoFronterDuration; + footer += ". Ignoring switch-outs"; + } + else + period = breakdown.RangeEnd - breakdown.RangeStart; + + eb.Footer(new(footer)); + var maxEntriesToDisplay = 24; // max 25 fields allowed in embed - reserve 1 for "others" // We convert to a list of pairs so we can add the no-fronter value diff --git a/docs/content/tips-and-tricks.md b/docs/content/tips-and-tricks.md index 1a2c1d19..3d7b018b 100644 --- a/docs/content/tips-and-tricks.md +++ b/docs/content/tips-and-tricks.md @@ -73,4 +73,5 @@ These flags only work with the full member list (`pk;system list full`). |Command|Flag|Aliases|Description| |---|---|---|---| |pk;system frontpercent|-fronters-only|-fo|Shows the system's frontpercent without the "no fronter" entry| +|pk;system frontpercent|-flat||Shows "flat" frontpercent - percentages add up to 100%| |pk;group \ frontpercent|-fronters-only|-fo|Shows a group's frontpercent without the "no fronter" entry| diff --git a/docs/content/user-guide.md b/docs/content/user-guide.md index dbe25047..ab0bd18f 100644 --- a/docs/content/user-guide.md +++ b/docs/content/user-guide.md @@ -462,6 +462,15 @@ To look at the per-member breakdown of the front over a given time period, use t pk;system qazws frontpercent 100d12h Note that in cases of switches with multiple members, each involved member will have the full length of the switch counted towards it. This means that the percentages may add up to over 100%. +
It is possible to disable this with the `-flat` flag; percentages will then add up to 100%. + +::: tip +If you use the `switch-out` function, the time when no-one was fronting will show up in front history as "no fronter". To disable this, use the `-fronters-only`, or `-fo` flag: + +``` +pk;system frontpercent -fronters-only +``` +::: ## Member groups PluralKit allows you to categorize system members in different **groups**.