namespace YD_Event.Application.Scoring; /// 从已保存的计算快照读取展示值,不能在查询时静默重算历史成绩。 public static class ScoreDisplayService { /// 按角色格式化本人得分,主裁系数保留三位。 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); /// 本裁判分值;主裁为本人的系数预览,综合M以成绩快照为准。 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; } /// 花样得分系数 M;非花样或缺少计算快照时不推断数值。 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() : null; } catch (Exception ex) when (ex is JsonException or FormatException or InvalidCastException or OverflowException) { return null; } } }