using System.Globalization; namespace AIStudio.Assistants.ModelComparison; /// /// Formats the numbers which the Model Comparison assistant shows, in the culture of the active language. /// public static class ModelComparisonFormat { /// /// Gets the culture of the active language. Qualified with its namespace because the namespace of the localization /// assistant, AIStudio.Assistants.I18N, hides the class I18N from every assistant. /// public static CultureInfo Culture => Tools.PluginSystem.I18N.I.Culture; /// /// Gets the English name of the active language, without a region ("German", not "German (Germany)"), for an /// instruction which the models and the judges understand regardless of their own default language. The culture /// carries a region, so its neutral parent names the language alone, except for the invariant culture, which has /// no parent to ask. /// public static string LanguageName => Culture.IsNeutralCulture || Culture.Equals(CultureInfo.InvariantCulture) ? Culture.EnglishName : Culture.Parent.EnglishName; /// /// Formats seconds with one decimal place, e.g., "2.5 s". /// /// The seconds. /// The seconds with their unit. public static string Seconds(double seconds) => $"{seconds.ToString("0.0", Culture)} s"; /// /// Formats a duration in seconds. /// /// The duration, or null when it is not known. /// The seconds with their unit, or a dash. public static string Duration(TimeSpan? duration) => duration is { } value ? Seconds(value.TotalSeconds) : "-"; /// /// Formats a duration in minutes with one decimal place, e.g., "12.5 min". /// /// The duration, or null when it is not known. /// The minutes with their unit, or a dash. public static string Minutes(TimeSpan? duration) => duration is { } value ? $"{value.TotalMinutes.ToString("0.0", Culture)} min" : "-"; /// /// Formats a number with one decimal place, e.g., an average. /// /// The number, or null when it is not known. /// The number, or a dash. public static string Decimal(double? number) => number is { } value ? value.ToString("0.0", Culture) : "-"; /// /// Formats a share as a whole percentage. /// /// The share between 0 and 1, or null when it is not known. /// The percentage, or a dash. public static string Share(double? share) => share is { } value ? value.ToString("P0", Culture) : "-"; }