1
1
using System . Text ;
2
2
using MathNet . Numerics . Distributions ;
3
+ using Spectre . Console ;
3
4
using TimeItSharp . Common . Results ;
4
5
5
6
namespace TimeItSharp . Common ;
@@ -42,7 +43,7 @@ public static IEnumerable<double> RemoveOutliers(IEnumerable<double> data, doubl
42
43
// If the data is empty, return an empty array
43
44
if ( lstData . Count == 0 )
44
45
{
45
- return Array . Empty < double > ( ) ;
46
+ return [ ] ;
46
47
}
47
48
48
49
// Calculate the standard deviation of the data
@@ -187,7 +188,7 @@ public static OverheadResult[][] GetComparisonTableData(IReadOnlyList<ScenarioRe
187
188
// Check if the results list is null or empty
188
189
if ( results is null || results . Count == 0 )
189
190
{
190
- return Array . Empty < OverheadResult [ ] > ( ) ;
191
+ return [ ] ;
191
192
}
192
193
193
194
// Initialize a 2D array to hold the comparison table data
@@ -281,27 +282,42 @@ public static string ToDurationString(this TimeSpan timeSpan)
281
282
282
283
public static double [ ] CalculateConfidenceInterval ( double mean , double standardError , int sampleSize , double confidenceLevel )
283
284
{
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
293
286
{
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
+ }
297
307
298
- // Calc the margin of error
299
- var marginOfError = criticalValue * standardError ;
308
+ // Calc the margin of error
309
+ var marginOfError = criticalValue * standardError ;
300
310
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 ;
304
314
305
- return [ lowerBound , upperBound ] ;
315
+ return [ lowerBound , upperBound ] ;
316
+ }
317
+ catch ( Exception ex )
318
+ {
319
+ AnsiConsole . WriteException ( ex ) ;
320
+ return [ mean , mean ] ;
321
+ }
306
322
}
307
323
}
0 commit comments