2026-09-29 17:19:03 +08:00
|
|
|
|
namespace YD_Event.Application.Scoring;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>从已保存的计算快照读取展示值,不能在查询时静默重算历史成绩。</summary>
|
|
|
|
|
|
public static class ScoreDisplayService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>按角色格式化本人得分,主裁系数保留三位。</summary>
|
|
|
|
|
|
public static string JudgeText(EventJudgeScoreSheet sheet, bool isFactorTotal) =>
|
|
|
|
|
|
sheet.IsDisqualified ? "DQ" : JudgeValue(sheet, isFactorTotal).ToString(
|
|
|
|
|
|
isFactorTotal && JudgeRoleSchemaService.NormalizeRoleType(sheet.JudgeRoleType) == "T" ? "F3" : "F2",
|
|
|
|
|
|
System.Globalization.CultureInfo.InvariantCulture);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>本裁判分值;主裁为本人的系数预览,综合M以成绩快照为准。</summary>
|
|
|
|
|
|
public static decimal JudgeValue(EventJudgeScoreSheet sheet, bool isFactorTotal)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!isFactorTotal) return sheet.TotalScore;
|
|
|
|
|
|
var role = JudgeRoleSchemaService.NormalizeRoleType(sheet.JudgeRoleType);
|
|
|
|
|
|
if (role == "T") return Math.Max(0m, 1m - sheet.DeductionScore);
|
|
|
|
|
|
if (role == "P") return sheet.PerformanceScore;
|
|
|
|
|
|
return role.StartsWith("D", StringComparison.OrdinalIgnoreCase) ? sheet.DifficultyScore : sheet.TotalScore;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>花样得分系数 M;非花样或缺少计算快照时不推断数值。</summary>
|
|
|
|
|
|
public static decimal? DeductionFactor(string? calculationJson)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(calculationJson)) return null;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2026-10-12 10:19:20 +08:00
|
|
|
|
var root = JObject.Parse(calculationJson);
|
|
|
|
|
|
return root["factors"] is JObject factors
|
|
|
|
|
|
? factors["m"]?.Value<decimal?>()
|
|
|
|
|
|
: null;
|
2026-09-29 17:19:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex) when (ex is JsonException or FormatException or InvalidCastException or OverflowException)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|