From f0f01c3c6626e9a78983ea9bcfc8c6dc97534df1 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Sat, 13 Dec 2025 17:55:04 +0100 Subject: [PATCH] Fixed magic values in Probmethods --- src/Server/Probmethods.cs | 42 ++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/Server/Probmethods.cs b/src/Server/Probmethods.cs index 5655f40..34d6a86 100644 --- a/src/Server/Probmethods.cs +++ b/src/Server/Probmethods.cs @@ -21,27 +21,36 @@ public class ProbMethod } } +public enum ProbMethodEnum +{ + Mean, + HarmonicMean, + QuadraticMean, + GeometricMean, + EVEWAvg, + HVEWAvg, + LVEWavg, + DictionaryWeightedAverage +} + public static class Probmethods { public delegate float probMethodProtoDelegate(List<(string, float)> list, string parameters); public delegate float probMethodDelegate(List<(string, float)> list); - public static readonly Dictionary probMethods; + public static readonly Dictionary probMethods; static Probmethods() { - probMethods = new Dictionary + probMethods = new Dictionary { - ["Mean"] = Mean, - ["HarmonicMean"] = HarmonicMean, - ["QuadraticMean"] = QuadraticMean, - ["GeometricMean"] = GeometricMean, - ["ExtremeValuesEmphasisWeightedAverage"] = ExtremeValuesEmphasisWeightedAverage, - ["EVEWAvg"] = ExtremeValuesEmphasisWeightedAverage, - ["HighValueEmphasisWeightedAverage"] = HighValueEmphasisWeightedAverage, - ["HVEWAvg"] = HighValueEmphasisWeightedAverage, - ["LowValueEmphasisWeightedAverage"] = LowValueEmphasisWeightedAverage, - ["LVEWAvg"] = LowValueEmphasisWeightedAverage, - ["DictionaryWeightedAverage"] = DictionaryWeightedAverage + [ProbMethodEnum.Mean] = Mean, + [ProbMethodEnum.HarmonicMean] = HarmonicMean, + [ProbMethodEnum.QuadraticMean] = QuadraticMean, + [ProbMethodEnum.GeometricMean] = GeometricMean, + [ProbMethodEnum.EVEWAvg] = ExtremeValuesEmphasisWeightedAverage, + [ProbMethodEnum.HVEWAvg] = HighValueEmphasisWeightedAverage, + [ProbMethodEnum.LVEWavg] = LowValueEmphasisWeightedAverage, + [ProbMethodEnum.DictionaryWeightedAverage] = DictionaryWeightedAverage }; } @@ -58,7 +67,12 @@ public static class Probmethods jsonArg = name[(colonIndex + 1)..]; } - if (!probMethods.TryGetValue(methodName, out probMethodProtoDelegate? method)) + ProbMethodEnum probMethodEnum = (ProbMethodEnum)Enum.Parse( + typeof(ProbMethodEnum), + methodName + ); + + if (!probMethods.TryGetValue(probMethodEnum, out probMethodProtoDelegate? method)) { return null; }