本文整理汇总了C#中IList.Average方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Average方法的具体用法?C# IList.Average怎么用?C# IList.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.Average方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Calculate
public async Task<IssuesCollectionStatistics> Calculate(IList<JiraIssue> issues)
{
if(issues == null || issues.Any() == false)
return null;
return await Task.Factory.StartNew(() =>
{
return new IssuesCollectionStatistics
{
IssuesCount = issues.Count(),
ResolvedIssuesCount = issues.Where(i => i.Resolved.HasValue).Count(),
UnresolvedIssuesCount = issues.Where(i => i.Resolved.HasValue == false).Count(),
AverageResolutionTimeHours = issues
.Where(i => i.Resolved.HasValue)
.Select(i => (i.Resolved.Value - i.Created).TotalHours).Average(),
MaxResolutionTimeHours = issues
.Where(i => i.Resolved.HasValue)
.Select(i => (i.Resolved.Value - i.Created).TotalHours).Max(),
TotalStorypoints = issues.Sum(i => i.StoryPoints),
AverageStorypointsPerTask = issues.Average(i => i.StoryPoints),
AverageSubtasksCount = issues.Average(i => i.Subtasks),
EpicsInvolved = issues.Select(i => i.EpicLink).Distinct().Count(),
DistinctReporters = issues.Select(i => i.Reporter).Distinct().Count()
};
});
}
示例2: Calculate
public RiskProfile Calculate(Bet bet, IList<Bet> settledBets)
{
if (settledBets.Count == 0)
{
return Constants.SAFE_PROFILE;
}
var avergaStake = settledBets.Average(bets => bets.Stake);
if (bet.Stake > (avergaStake * Constants.EXCEPTIONALLY_RISKY_STAKE_FACTOR))
{
return new RiskProfile
{
Risk = Risk.HighlyRisky,
Reason = "Stake is exceptionally large based on betting history."
};
}
if (bet.Stake > (avergaStake * Constants.UNUSUAL_STAKE_FACTOR))
{
return new RiskProfile
{
Risk = Risk.Unusual,
Reason = "Stake is unusually large based on betting history."
};
}
return Constants.SAFE_PROFILE;
}
示例3: DisplayStats
static void DisplayStats(IList<Response> responses)
{
if (!responses.Any())
{
return;
}
var average = responses.Average(x => (x.EndUtc - x.StartUtc).TotalMilliseconds);
ClearLine();
Console.WriteLine("Average time: {0} ms", Convert.ToInt32(average));
var min = responses.Min(x => x.StartUtc);
var max = responses.Max(x => x.EndUtc);
var count = responses.Count;
var timespan = Convert.ToInt32((max - min).TotalMilliseconds);
timespan = timespan == 0 ? 0 : timespan / 1000;
var rps = timespan == 0 ? 0 : count / timespan;
ClearLine();
Console.WriteLine("Performance: {0} rps ({1} reqs in {2})", Convert.ToInt32(rps), responses.Count, timespan);
ClearLine();
Console.WriteLine("Threads: {0}", responses.Select(x => x.TaskId).Distinct().Count());
ClearLine();
Console.WriteLine("Errors: {0}", responses.Count(x => !x.Success));
}
示例4: Compute
public RatingResult Compute(IList<RestaurantReview> reviews)
{
var result = new RatingResult();
result.Rating = (int)reviews.Average(r => r.Rating);
return result;
}
示例5: Do
public AggregationOperationResult Do(IList<UniversalValue> input)
{
if (input == null)
throw new ArgumentNullException("input");
AggregationOperationResult result = new AggregationOperationResult();
result.Add("avg", input.Average());
return result;
}
示例6: CalculateAverages
private static AggregatedWeatherResponse CalculateAverages(IList<WeatherServiceResponse> weatherServiceResponses)
{
AggregatedWeatherResponse aggregatedResponse = null;
if (weatherServiceResponses.Count > 0)
{
aggregatedResponse = new AggregatedWeatherResponse
{
AverageTemperatureCelsius = Math.Round(weatherServiceResponses.Average(a => a.TemperatureCelsius), 1),
AverageTemperatureFahrenheit = Math.Round(weatherServiceResponses.Average(a => a.TemperatureFahrenheit), 1),
AverageWindSpeedKph = Math.Round(weatherServiceResponses.Average(a => a.WindSpeedKph), 1),
AverageWindSpeedMph = Math.Round(weatherServiceResponses.Average(a => a.WindSpeedMph), 1)
};
}
return aggregatedResponse;
}
示例7: Do
public AggregationOperationResult Do(IList<double> input)
{
if (input == null)
throw new ArgumentNullException("input");
if (!input.Any())
throw new InvalidOperationException("No elements to aggregate");
return new AggregationOperationResult(AggregationType.Avg,input.Average());
}
示例8: FindSumAndAverage
private static void FindSumAndAverage(IList<int> numbers)
{
long numbersSum = 0;
double numbersAverage = 0;
numbersSum = numbers.Sum();
numbersAverage = numbers.Average();
Console.WriteLine("The sum of your sequence is: {0} and the avgerage is: {1}.", numbersSum, numbersAverage);
}
示例9: GetAverage
public static ArrayVector GetAverage(IList<ArrayVector> vectors)
{
if (vectors == null) throw new ArgumentNullException("vectors");
if (vectors.Count == 0) throw new ArgumentException("The source must not be empty.", "vectors");
return Enumerable.Range(0, vectors[0].Dimension)
.Select(i => vectors.Average(v => v.Value[i]))
.ToArray();
}
示例10: Calculate
public double Calculate(IList<Coder> participants)
{
var n = participants.Count;
var ratAvg = participants.Average(x => x.R);
var sqrRatStdev = participants.Sum(x => Math.Pow(x.R - ratAvg, 2)) / (n - 1);
var sqrVolAvg = participants.Sum(x => x.V * x.V) / n;
return Math.Sqrt(sqrVolAvg + sqrRatStdev);
}
示例11: Analyze
public static Movement Analyze(IList<Movement> movements)
{
Movement movement;
if (movements.Any(x => x > Movement.Higher))
movement = Movement.Highest;
else if (movements.Any(x => x > Movement.High))
movement = Movement.High;
else if (movements.Any(x => x > Movement.Med))
movement = Movement.Med;
else if (movements.Average(x => (double)x) > (double)Movement.Lowest)
movement = Movement.Low;
else
movement = Movement.Lowest;
return movement;
}
示例12: RelatorioJogosDisponiveisModel
public RelatorioJogosDisponiveisModel(IList<Jogo> jogosDisponiveis)
{
this.Jogos = new List<JogoDisponivelModel>();
if(jogosDisponiveis != null && jogosDisponiveis.Count > 0)
{
foreach (Jogo jogo in jogosDisponiveis)
{
var jogoModel = new JogoDisponivelModel(jogo);
this.Jogos.Add(jogoModel);
}
this.QuantidadeTotalDeJogos = jogosDisponiveis.Count;
this.ValorMedio = jogosDisponiveis.Average(j => j.Preco);
decimal maiorPreco = jogosDisponiveis.Max(j => j.Preco);
decimal menorPreco = jogosDisponiveis.Min(j => j.Preco);
this.JogoMaisCaro = this.Jogos.First(j => j.Preco == maiorPreco);
this.JogoMaisBarato = this.Jogos.First(j => j.Preco == menorPreco);
}
}
示例13: CalculateSummaries
public static StatSummary CalculateSummaries(IList<decimal> vals)
{
var res = new StatSummary();
res.Count = vals.Count;
res.Average = vals.Average();
var sorted = new List<decimal>(vals);
sorted.Sort();
res.Median = CalculateQuantile(sorted, 0.5M);
res.LowerQuartile = CalculateQuantile(sorted, 0.25M);
res.UpperQuartile = CalculateQuantile(sorted, 0.75M);
res.Min = sorted.First();
res.Max = sorted.Last();
res.Percentile2 = CalculateQuantile(sorted, 0.02M);
res.Percentile98 = CalculateQuantile(sorted, 0.98M);
Validate(sorted, res);
return res;
}
示例14: StandardDeviation
public static double StandardDeviation(IList<double> doubleList, out double average, out double max, out double min)
{
average = doubleList.Average();
double sumOfDerivation = 0;
max = -1e9;
min = 1e9;
foreach (double value in doubleList)
{
max = Math.Max(max, value);
min = Math.Min(min, value);
sumOfDerivation += (value) * (value);
}
double sumOfDerivationAverage = sumOfDerivation / doubleList.Count;
return Math.Sqrt(sumOfDerivationAverage - (average * average));
}
示例15: AverageIList
public static double AverageIList(IList<double> numbers)
{
return numbers.Average();
}