2026-10-12 10:19:20 +08:00

39 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
{
var root = JObject.Parse(calculationJson);
return root["factors"] is JObject factors
? factors["m"]?.Value<decimal?>()
: null;
}
catch (Exception ex) when (ex is JsonException or FormatException or InvalidCastException or OverflowException)
{
return null;
}
}
}