Skip to content

Commit

Permalink
Update IAsyncCommand.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Apr 9, 2024
1 parent f937f9f commit 468114f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion MyApp.ServiceInterface/IAsyncCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ public class CommandSummary
public int TotalMs { get; set; }
public int MinMs { get; set; }
public int MaxMs { get; set; }
public int AverageMs => (int) Math.Floor(TotalMs / (double)Count);
public double AverageMs => Count == 0 ? 0 : Math.Round(TotalMs / (double)Count, 2);
public double MedianMs => Math.Round(Timings.Median(), 2);
public string? LastError { get; set; }
public ConcurrentQueue<int> Timings { get; set; } = new();
}
Expand Down Expand Up @@ -367,4 +368,14 @@ public static Task ExecuteCommandsAsync<T>(this IRequest? req, T requestDto) whe
var feature = HostContext.AssertPlugin<CommandsFeature>();
return feature.ExecuteCommandsAsync(services, requestDto);
}

public static double Median(this IEnumerable<int> nums)
{
var array = nums.ToArray();
Array.Sort(array);
var mid = array.Length / 2;
return array.Length % 2 == 0
? (array[mid] + array[mid - 1]) / 2.0
: array[mid];
}
}

0 comments on commit 468114f

Please sign in to comment.