Skip to content

Commit

Permalink
Fixes (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyredondo authored Nov 25, 2024
1 parent 2df916f commit f6833e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.2.0</Version>
<Version>0.2.1</Version>
<Authors>Tony Redondo, Grégory Léocadie</Authors>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
56 changes: 36 additions & 20 deletions src/TimeItSharp.Common/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text;
using MathNet.Numerics.Distributions;
using Spectre.Console;
using TimeItSharp.Common.Results;

namespace TimeItSharp.Common;
Expand Down Expand Up @@ -42,7 +43,7 @@ public static IEnumerable<double> RemoveOutliers(IEnumerable<double> data, doubl
// If the data is empty, return an empty array
if (lstData.Count == 0)
{
return Array.Empty<double>();
return [];
}

// Calculate the standard deviation of the data
Expand Down Expand Up @@ -187,7 +188,7 @@ public static OverheadResult[][] GetComparisonTableData(IReadOnlyList<ScenarioRe
// Check if the results list is null or empty
if (results is null || results.Count == 0)
{
return Array.Empty<OverheadResult[]>();
return [];
}

// Initialize a 2D array to hold the comparison table data
Expand Down Expand Up @@ -281,27 +282,42 @@ public static string ToDurationString(this TimeSpan timeSpan)

public static double[] CalculateConfidenceInterval(double mean, double standardError, int sampleSize, double confidenceLevel)
{
// Check if we should use the Student's t-distribution or the standard normal distribution
double criticalValue;
if (sampleSize < 30)
{
// Let's use the t-distribution
var degreesOfFreedom = sampleSize - 1;
criticalValue = StudentT.InvCDF(0, 1, degreesOfFreedom, 1 - (1 - confidenceLevel) / 2);
}
else
try
{
// Let's use the standard normal distribution
criticalValue = Normal.InvCDF(0, 1, 1 - (1 - confidenceLevel) / 2);
}
// Check if we should use the Student's t-distribution or the standard normal distribution
double criticalValue;
if (sampleSize < 30)
{
// Let's use the t-distribution
var degreesOfFreedom = sampleSize - 1;
if (degreesOfFreedom > 0)
{
criticalValue = StudentT.InvCDF(0, 1, degreesOfFreedom, 1 - (1 - confidenceLevel) / 2);
}
else
{
return [mean, mean];
}
}
else
{
// Let's use the standard normal distribution
criticalValue = Normal.InvCDF(0, 1, 1 - (1 - confidenceLevel) / 2);
}

// Calc the margin of error
var marginOfError = criticalValue * standardError;
// Calc the margin of error
var marginOfError = criticalValue * standardError;

// Create confidence interval
var lowerBound = mean - marginOfError;
var upperBound = mean + marginOfError;
// Create confidence interval
var lowerBound = mean - marginOfError;
var upperBound = mean + marginOfError;

return [lowerBound, upperBound];
return [lowerBound, upperBound];
}
catch (Exception ex)
{
AnsiConsole.WriteException(ex);
return [mean, mean];
}
}
}

0 comments on commit f6833e1

Please sign in to comment.