using AIStudio.Components; using Microsoft.AspNetCore.Components; namespace AIStudio.Assistants.ModelComparison; /// /// A ranking of the models: their wins, ties, and losses as a chart, and as a table with their share of wins and how /// sure that share is. /// public partial class ModelComparisonRanking : MSGComponentBase { /// /// Gets or sets the models, best first, by the votes of the user or by the verdicts of the judges. /// [Parameter, EditorRequired] public IReadOnlyList Standings { get; set; } = []; /// /// The wins, ties, and losses of each model, as the three series of a stacked bar chart. /// private List> OutcomeSeries => [ new() { Name = T("Wins"), Data = new([.. this.Standings.Select(standing => (double)standing.Wins)]) }, new() { Name = T("Ties"), Data = new([.. this.Standings.Select(standing => (double)standing.Ties)]) }, new() { Name = T("Losses"), Data = new([.. this.Standings.Select(standing => (double)standing.Losses)]) }, ]; private StackedBarChartOptions ChartOptions => new() { ChartPalette = ModelComparisonCharts.OUTCOME_PALETTE, YAxisTicks = ModelComparisonCharts.AxisStep(this.Standings.Select(standing => (double)(standing.Wins + standing.Ties + standing.Losses))), YAxisToStringFunc = value => ((long)value).CompactCount(), XAxisLabelRotation = ModelComparisonCharts.LabelRotation(this.Standings.Count), }; private string FormatRange(ModelComparisonWinShare winShare) => winShare is { LowerBound: { } lower, UpperBound: { } upper } ? string.Format(ModelComparisonFormat.Culture, T("{0} to {1}"), ModelComparisonFormat.Share(lower), ModelComparisonFormat.Share(upper)) : "-"; private string SignificanceText(ModelComparisonSignificance significance) => significance switch { ModelComparisonSignificance.CLEARLY_BETTER => T("Clearly better"), ModelComparisonSignificance.CLEARLY_WORSE => T("Clearly worse"), _ => T("Not yet clear"), }; }