private static void CalculateAndWriteStatisticConclusionsForOneParam(List <OneGameStatisticsDto> allGameStats, Func <OneGameStatisticsDto, int> parameterToCalculate, string gameParameterName) { //make a list of only selected gamer parameter from every game (i.e. filter out other game parameter types) IEnumerable <int> rawParameterValueFromEachGame = allGameStats.Select(parameterToCalculate); //do the statistics on this list of numbers StaticsParametersOfAnArrayDto statResultsOfAGameParameter = MathemtaticalStatisticCalculator.CalculateStatsForOneParam(rawParameterValueFromEachGame); //write results of the statistics analysis of the list of numbers WriteStasForOneGameParam(statResultsOfAGameParameter, gameParameterName); }
public static StaticsParametersOfAnArrayDto CalculateStatsForOneParam(IEnumerable <int> statisticParamterValueInAllGames) { StaticsParametersOfAnArrayDto statisticParameter = new StaticsParametersOfAnArrayDto { Avg = statisticParamterValueInAllGames.Average(), StdDev = CalculateStandardDeviation(statisticParamterValueInAllGames.Select(number => (double)number)), Min = statisticParamterValueInAllGames.Min(), Max = statisticParamterValueInAllGames.Max() }; return(statisticParameter); }
/// <summary> /// Clulcates relative deviation from the absolute one which is default. /// Caluclate how many percents values deviate instead of for HOW MUCH they deviate. /// </summary> /// <param name="statisticParameter"></param> /// <returns></returns> private static double CalculateDeviationInPercents(StaticsParametersOfAnArrayDto statisticParameter) { double deviationInPercents; if (statisticParameter.Avg != 0) { deviationInPercents = statisticParameter.StdDev / statisticParameter.Avg * 100; } else { deviationInPercents = double.NaN; //could be postive or ngeative infinity or undifined, but this scneario is not important that much } return(deviationInPercents); }
private static void WriteStasForOneGameParam(StaticsParametersOfAnArrayDto statisticParameter, string gameParameterName) { //lower and uuper boundary values with certanity of 68% (i.e. values in range of one sigma to the left or to the rigt from the averge value) double stdDevLowerBoundDecimal = statisticParameter.Avg - statisticParameter.StdDev; double stdDevUpperBoundDecimal = statisticParameter.Avg + statisticParameter.StdDev; double deviationInPercentsDecimal = CalculateDeviationInPercents(statisticParameter); string decimalsFormatting = GetDecimalsFormatting(DecimalsToWrite); //formating decimals to string string avg = statisticParameter.Avg.ToString(decimalsFormatting); string stdDev = statisticParameter.StdDev.ToString(decimalsFormatting); string min = statisticParameter.Min.ToString(decimalsFormatting); string max = statisticParameter.Max.ToString(decimalsFormatting); string stdDevLowerBound = stdDevLowerBoundDecimal.ToString(decimalsFormatting); string stdDevUpperBound = stdDevUpperBoundDecimal.ToString(decimalsFormatting); string deviationInPercents = deviationInPercentsDecimal.ToString(decimalsFormatting); Console.WriteLine($"{gameParameterName}: avg = {avg}, std dev = {stdDev}, min = {min}, max = {max}."); Console.WriteLine($"Game will usually have {avg} +- {stdDev} (i.e. {stdDevLowerBound} - {stdDevUpperBound}) {gameParameterName.ToLower()}.\r\n"); // this statement has certanity of 68% }