using AIStudio.Components;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Assistants.ModelComparison;
///
/// One run in the summary of a batch, with the names of the models: closed, a line with the vote of the user and the
/// choice of the judge; open, both answers, the outcome, the times, and the verdict of the judge with its reasoning.
///
///
/// The answers stand in the order of the models, not in the columns of the vote: the columns were drawn fresh for every
/// run, and across several runs, only the names say anything.
///
public partial class ModelComparisonRunPanel : MSGComponentBase
{
///
/// Gets or sets the batch.
///
[Parameter, EditorRequired]
public ModelComparisonBatch Batch { get; set; } = null!;
///
/// Gets or sets the position of the run, zero-based.
///
[Parameter, EditorRequired]
public int Index { get; set; }
private ModelComparisonBatchEntry Entry => this.Batch.Entries[this.Index];
private ModelComparisonModelChoice? VoteChoice => this.Batch.VoteChoiceAt(this.Index);
private ModelComparisonModelChoice? JudgeChoice => this.Batch.JudgeChoiceAt(this.Index);
///
/// Names a model of the run, or says that both answers were equally good.
///
/// A model, or a tie.
private string NameOf(ModelComparisonModelChoice choice) => choice is ModelComparisonModelChoice.TIE
? T("Equally good")
: this.Entry.Result.AnswerOf(choice).Label;
///
/// Says in the title of the run what the user chose.
///
private string Heading
{
get
{
var runNumber = this.Index + 1;
if (!this.Entry.Result.BothCompleted)
return string.Format(ModelComparisonFormat.Culture, T("Run {0}: at least one model did not answer"), runNumber);
return this.VoteChoice switch
{
null => string.Format(ModelComparisonFormat.Culture, TA("Run {0}: without your vote"), runNumber),
ModelComparisonModelChoice.TIE => string.Format(ModelComparisonFormat.Culture, TA("Run {0}: you found both answers equally good"), runNumber),
{ } chosen => string.Format(ModelComparisonFormat.Culture, TA("Run {0}: you preferred {1}"), runNumber, this.NameOf(chosen)),
};
}
}
}