Skip to content

Commit f6833e1

Browse files
authored
Fixes (#63)
1 parent 2df916f commit f6833e1

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.2.0</Version>
3+
<Version>0.2.1</Version>
44
<Authors>Tony Redondo, Grégory Léocadie</Authors>
55
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
66
<ImplicitUsings>enable</ImplicitUsings>

src/TimeItSharp.Common/Utils.cs

+36-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text;
22
using MathNet.Numerics.Distributions;
3+
using Spectre.Console;
34
using TimeItSharp.Common.Results;
45

56
namespace TimeItSharp.Common;
@@ -42,7 +43,7 @@ public static IEnumerable<double> RemoveOutliers(IEnumerable<double> data, doubl
4243
// If the data is empty, return an empty array
4344
if (lstData.Count == 0)
4445
{
45-
return Array.Empty<double>();
46+
return [];
4647
}
4748

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

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

282283
public static double[] CalculateConfidenceInterval(double mean, double standardError, int sampleSize, double confidenceLevel)
283284
{
284-
// Check if we should use the Student's t-distribution or the standard normal distribution
285-
double criticalValue;
286-
if (sampleSize < 30)
287-
{
288-
// Let's use the t-distribution
289-
var degreesOfFreedom = sampleSize - 1;
290-
criticalValue = StudentT.InvCDF(0, 1, degreesOfFreedom, 1 - (1 - confidenceLevel) / 2);
291-
}
292-
else
285+
try
293286
{
294-
// Let's use the standard normal distribution
295-
criticalValue = Normal.InvCDF(0, 1, 1 - (1 - confidenceLevel) / 2);
296-
}
287+
// Check if we should use the Student's t-distribution or the standard normal distribution
288+
double criticalValue;
289+
if (sampleSize < 30)
290+
{
291+
// Let's use the t-distribution
292+
var degreesOfFreedom = sampleSize - 1;
293+
if (degreesOfFreedom > 0)
294+
{
295+
criticalValue = StudentT.InvCDF(0, 1, degreesOfFreedom, 1 - (1 - confidenceLevel) / 2);
296+
}
297+
else
298+
{
299+
return [mean, mean];
300+
}
301+
}
302+
else
303+
{
304+
// Let's use the standard normal distribution
305+
criticalValue = Normal.InvCDF(0, 1, 1 - (1 - confidenceLevel) / 2);
306+
}
297307

298-
// Calc the margin of error
299-
var marginOfError = criticalValue * standardError;
308+
// Calc the margin of error
309+
var marginOfError = criticalValue * standardError;
300310

301-
// Create confidence interval
302-
var lowerBound = mean - marginOfError;
303-
var upperBound = mean + marginOfError;
311+
// Create confidence interval
312+
var lowerBound = mean - marginOfError;
313+
var upperBound = mean + marginOfError;
304314

305-
return [lowerBound, upperBound];
315+
return [lowerBound, upperBound];
316+
}
317+
catch (Exception ex)
318+
{
319+
AnsiConsole.WriteException(ex);
320+
return [mean, mean];
321+
}
306322
}
307323
}

0 commit comments

Comments
 (0)