Add "flat" front history view (percentages add up to 100%)

This commit is contained in:
spiral 2021-06-21 11:30:38 -04:00
parent bc32943824
commit c727a71161
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
5 changed files with 38 additions and 11 deletions

View File

@ -523,8 +523,9 @@ namespace PluralKit.Bot
title.Append($"`{targetSystem.Hid}`"); title.Append($"`{targetSystem.Hid}`");
var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only"); 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)); 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<PKSystem> GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn) private async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn)

View File

@ -135,8 +135,9 @@ namespace PluralKit.Bot
title.Append($"`{system.Hid}`"); title.Append($"`{system.Hid}`");
var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only"); 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)); 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));
} }
} }
} }

View File

@ -334,7 +334,7 @@ namespace PluralKit.Bot {
return eb.Build(); return eb.Build();
} }
public Task<Embed> CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle, bool ignoreNoFronters) public Task<Embed> CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle, bool ignoreNoFronters, bool showFlat)
{ {
string color = system.Color; string color = system.Color;
if (group != null) if (group != null)
@ -351,17 +351,32 @@ namespace PluralKit.Bot {
{ {
embedColor = DiscordUtils.Gray; embedColor = DiscordUtils.Gray;
} }
var period = breakdown.RangeEnd - breakdown.RangeStart;
var actualPeriod = period;
if (ignoreNoFronters)
period = period - breakdown.NoFronterDuration;
var eb = new EmbedBuilder() var eb = new EmbedBuilder()
.Title(embedTitle) .Title(embedTitle)
.Color(embedColor) .Color(embedColor);
.Footer(new($"Since {breakdown.RangeStart.FormatZoned(tz)} ({actualPeriod.FormatDuration()} ago)"));
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" 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 // We convert to a list of pairs so we can add the no-fronter value

View File

@ -73,4 +73,5 @@ These flags only work with the full member list (`pk;system list full`).
|Command|Flag|Aliases|Description| |Command|Flag|Aliases|Description|
|---|---|---|---| |---|---|---|---|
|pk;system frontpercent|-fronters-only|-fo|Shows the system's frontpercent without the "no fronter" entry| |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 \<group> frontpercent|-fronters-only|-fo|Shows a group's frontpercent without the "no fronter" entry| |pk;group \<group> frontpercent|-fronters-only|-fo|Shows a group's frontpercent without the "no fronter" entry|

View File

@ -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 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%. 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%.
<br> 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 ## Member groups
PluralKit allows you to categorize system members in different **groups**. PluralKit allows you to categorize system members in different **groups**.