private ExchangeRatingModel CalculateRating(string exchangeName) { var callStatistic = _statisticsCollector.GetCallStatistics().Where(es => es.ExchangeName == exchangeName).ToArray(); var exCount = _statisticsCollector.GetExceptionStatistics().Count(es => es.ExchangeName == exchangeName); var exCoef = ExceptionWeight * callStatistic.Length / (exCount + callStatistic.Length); var avgResponse = callStatistic.Select(cs => cs.Duration.Milliseconds) .DefaultIfEmpty(_minResponseTime) .Average(cs => cs); var callCoef = SpeedWeight * _minResponseTime / avgResponse; var rating = (exCoef + callCoef) * 10d; return(new ExchangeRatingModel { ExchangeName = exchangeName, Rating = rating }); }