using AIStudio.Components; using Microsoft.AspNetCore.Components; namespace AIStudio.Assistants.ModelComparison; /// /// The effort with each model of a comparison series as two bar charts: how many messages the user wrote on average, /// and the median time the user worked with it. A model without a value is left out of that chart. /// public partial class ModelComparisonEffortCharts : MSGComponentBase { /// /// Gets or sets the effort with each model, in the order of the models of the series. /// [Parameter, EditorRequired] public IReadOnlyList Efforts { get; set; } = []; /// /// The efforts with an average of the messages. /// private List messageEfforts = []; /// /// The efforts with a median time. /// private List timeEfforts = []; #region Overrides of ComponentBase protected override void OnParametersSet() { this.messageEfforts = [.. this.Efforts.Where(effort => effort.AverageUserMessages is not null)]; this.timeEfforts = [.. this.Efforts.Where(effort => effort.MedianDuration is not null)]; base.OnParametersSet(); } #endregion private List> MessageSeries => [ new() { Name = TA("Your messages on average"), Data = new([.. this.messageEfforts.Select(effort => effort.AverageUserMessages!.Value)]) }, ]; private List> TimeSeries => [ new() { Name = T("Median time"), Data = new([.. this.timeEfforts.Select(effort => effort.MedianDuration!.Value.TotalMinutes)]) }, ]; /// /// A single series needs no legend: the title above the chart names it. /// private BarChartOptions MessageChartOptions => new() { ChartPalette = ModelComparisonCharts.SINGLE_PALETTE, ShowLegend = false, YAxisTicks = ModelComparisonCharts.AxisStep(this.messageEfforts.Select(effort => effort.AverageUserMessages!.Value)), YAxisToStringFunc = value => ((long)value).CompactCount(), XAxisLabelRotation = ModelComparisonCharts.LabelRotation(this.messageEfforts.Count), }; private BarChartOptions TimeChartOptions => new() { ChartPalette = ModelComparisonCharts.SINGLE_PALETTE, ShowLegend = false, YAxisTicks = ModelComparisonCharts.AxisStep(this.timeEfforts.Select(effort => effort.MedianDuration!.Value.TotalMinutes)), YAxisToStringFunc = value => ModelComparisonFormat.Minutes(TimeSpan.FromMinutes(value)), XAxisLabelRotation = ModelComparisonCharts.LabelRotation(this.timeEfforts.Count), }; }