using AIStudio.Components;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Assistants.ModelComparison;
///
/// How fast the models answered: the median times as a chart, and as a table which also lists the models without a
/// complete answer.
///
public partial class ModelComparisonSpeeds : MSGComponentBase
{
///
/// Gets or sets the speeds of all models.
///
[Parameter, EditorRequired]
public IReadOnlyList Speeds { get; set; } = [];
///
/// The models with complete answers, whose median times the chart can show.
///
private IReadOnlyList timedSpeeds = [];
#region Overrides of ComponentBase
protected override void OnParametersSet()
{
this.timedSpeeds = [.. this.Speeds.Where(speed => speed is { MedianFirstTokenTime: not null, MedianTotalTime: not null })];
base.OnParametersSet();
}
#endregion
///
/// The median times of each model in seconds, as the two series of a bar chart.
///
private List> SpeedSeries =>
[
new() { Name = T("Until the first token"), Data = new([.. this.timedSpeeds.Select(speed => speed.MedianFirstTokenTime!.Value.TotalSeconds)]) },
new() { Name = T("Until the complete answer"), Data = new([.. this.timedSpeeds.Select(speed => speed.MedianTotalTime!.Value.TotalSeconds)]) },
];
private BarChartOptions ChartOptions => new()
{
ChartPalette = ModelComparisonCharts.SPEED_PALETTE,
YAxisTicks = ModelComparisonCharts.AxisStep(this.timedSpeeds.Select(speed => speed.MedianTotalTime!.Value.TotalSeconds)),
YAxisToStringFunc = ModelComparisonFormat.Seconds,
XAxisLabelRotation = ModelComparisonCharts.LabelRotation(this.timedSpeeds.Count),
};
}