Fixed magic values in Probmethods

This commit is contained in:
2025-12-13 17:55:04 +01:00
parent b8a6cf07a2
commit f0f01c3c66

View File

@@ -21,27 +21,36 @@ public class ProbMethod
} }
} }
public enum ProbMethodEnum
{
Mean,
HarmonicMean,
QuadraticMean,
GeometricMean,
EVEWAvg,
HVEWAvg,
LVEWavg,
DictionaryWeightedAverage
}
public static class Probmethods public static class Probmethods
{ {
public delegate float probMethodProtoDelegate(List<(string, float)> list, string parameters); public delegate float probMethodProtoDelegate(List<(string, float)> list, string parameters);
public delegate float probMethodDelegate(List<(string, float)> list); public delegate float probMethodDelegate(List<(string, float)> list);
public static readonly Dictionary<string, probMethodProtoDelegate> probMethods; public static readonly Dictionary<ProbMethodEnum, probMethodProtoDelegate> probMethods;
static Probmethods() static Probmethods()
{ {
probMethods = new Dictionary<string, probMethodProtoDelegate> probMethods = new Dictionary<ProbMethodEnum, probMethodProtoDelegate>
{ {
["Mean"] = Mean, [ProbMethodEnum.Mean] = Mean,
["HarmonicMean"] = HarmonicMean, [ProbMethodEnum.HarmonicMean] = HarmonicMean,
["QuadraticMean"] = QuadraticMean, [ProbMethodEnum.QuadraticMean] = QuadraticMean,
["GeometricMean"] = GeometricMean, [ProbMethodEnum.GeometricMean] = GeometricMean,
["ExtremeValuesEmphasisWeightedAverage"] = ExtremeValuesEmphasisWeightedAverage, [ProbMethodEnum.EVEWAvg] = ExtremeValuesEmphasisWeightedAverage,
["EVEWAvg"] = ExtremeValuesEmphasisWeightedAverage, [ProbMethodEnum.HVEWAvg] = HighValueEmphasisWeightedAverage,
["HighValueEmphasisWeightedAverage"] = HighValueEmphasisWeightedAverage, [ProbMethodEnum.LVEWavg] = LowValueEmphasisWeightedAverage,
["HVEWAvg"] = HighValueEmphasisWeightedAverage, [ProbMethodEnum.DictionaryWeightedAverage] = DictionaryWeightedAverage
["LowValueEmphasisWeightedAverage"] = LowValueEmphasisWeightedAverage,
["LVEWAvg"] = LowValueEmphasisWeightedAverage,
["DictionaryWeightedAverage"] = DictionaryWeightedAverage
}; };
} }
@@ -58,7 +67,12 @@ public static class Probmethods
jsonArg = name[(colonIndex + 1)..]; 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; return null;
} }