本文整理汇总了C#中IEnumerable.Average方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.Average方法的具体用法?C# IEnumerable.Average怎么用?C# IEnumerable.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.Average方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AverangeCorrection
private ProjectedAfrCorrection AverangeCorrection(IEnumerable<LogLine> lines, float targetAfr)
{
return new ProjectedAfrCorrection()
{
AfrDiffPercent = (float)lines.WeightedAverage(
l => (l.AfrWideband.Value / targetAfr) * 100 - 100,
l => l.ProximityIndex),
//widebandDiffPercent.Average(),
AfrDiffAbsolute = (float) lines.WeightedAverage(
l => targetAfr - l.AfrWideband.Value,
l => l.ProximityIndex), //widebandDiffAbsolute.Average(),
NboCorrection = (float) lines.WeightedAverage(
l => l.AfrCorrection.Value,
l => l.ProximityIndex
),
Count = lines.Count(),
AvgAfr = (float)lines.WeightedAverage(
l => l.AfrWideband.Value,
l => l.ProximityIndex
),
AvgKpa = lines.Average(l => l.Map.Value),
AvgRpm = (int)lines.Average(l => l.Rpm.Value)
};
}
示例2: AggregateMeasurements
protected override Measurement AggregateMeasurements(IEnumerable<Measurement> measurements)
{
return new Measurement
{
X = (int)measurements.Average(m => m.X),
Y = (int)measurements.Average(m => m.Y)
};
}
示例3: Aggregate
public Measurement Aggregate(IEnumerable<Measurement> measurements)
{
return new Measurement
{
X = (int)measurements.Average(m => m.X),
Y = (int)measurements.Average(m => m.Y)
};
}
示例4: SlopeOfPoints
/// <summary>
/// Gets the slope for a set of points using the formula:
/// m = SUM(x-AVG(x)(y-AVG(y)) / SUM(x-AVG(x))^2
/// </summary>
/// <param name="points">Points to calculate the Slope from</param>
/// <returns>SlopeOfPoints</returns>
private static float SlopeOfPoints(IEnumerable<PointF> points)
{
float avgX = points.Average(p => p.X);
float avgY = points.Average(p => p.Y);
float dividend = points.Sum(p => (p.X - avgX) * (p.Y - avgY));
float divisor = (float)points.Sum(p => Math.Pow(p.X - avgX, 2));
return dividend / divisor;
}
示例5: Aggregate
public Measurement Aggregate(IEnumerable<Measurement> measurements)
{
if (measurements.Contains(null))
throw new ArgumentNullException();
return new Measurement()
{
HighValue = measurements.Average(m => m.HighValue),
LowValue = measurements.Average(m => m.LowValue)
};
}
示例6: Covariance
private static double Covariance(IEnumerable<double> xs, IEnumerable<double> ys)
{
var xAvg = xs.Average();
var yAvg = ys.Average();
var cov = xs.Zip(ys, (x, y) => (x - xAvg) * (y - yAvg)).Average();
return cov;
}
示例7: CalculateStatistics
/// <summary>
/// Calculates the statistics.
/// </summary>
/// <param name="benchmarks">The composite query benchmarks.</param>
private static void CalculateStatistics(IEnumerable<BenchmarkBase> benchmarks)
{
if (null != benchmarks) {
var avgSelect = benchmarks.Average(b => ((CompositeQueries)b).SimpleQuery.Time.ElapsedMilliseconds);
Console.WriteLine("{0:0.0000} : Average simple select", avgSelect / 1000.0);
var avgFilter = benchmarks.Average(b => ((CompositeQueries)b).FilterQuery.Time.ElapsedMilliseconds);
Console.WriteLine("{0:0.0000} : Average simple filter", avgFilter / 1000.0);
var avgMapReduceTags = benchmarks.Average(b => ((CompositeQueries)b).TagCountMapReduce.Time.ElapsedMilliseconds);
Console.WriteLine("{0:0.0000} : Average Map-Reduce tags", avgMapReduceTags / 1000.0);
var avgMapReduceComments = benchmarks.Average(b => ((CompositeQueries)b).CommentAuthorMapReduce.Time.ElapsedMilliseconds);
Console.WriteLine("{0:0.0000} : Average Map-Reduce comments", avgMapReduceComments / 1000.0);
}
}
示例8: FillInSusiInfo
public void FillInSusiInfo(Student student, StudentInfo studentInfo, IEnumerable<CourseInfo> courseInfo)
{
student.FirstName = studentInfo.FirstName;
student.LastName = studentInfo.LastName;
Tuple<int, int> startEndYears = studentInfo.GetStartEndYear();
Bachelor bachelor = new Bachelor
{
StartYear = startEndYears.Item1,
EndYear = startEndYears.Item2,
CurrentCourse = studentInfo.Year,
Specialty = StudentManager.programmeMapping[studentInfo.Programme],
Subjects = courseInfo.Select(x => x.ToSubject()).ToList(),
CurrentAverageGrade = courseInfo.Average(x => x.Grade)
};
FMIEdu fmiEdu = new FMIEdu
{
Bachelor = bachelor,
};
student.FMIInfo = fmiEdu;
db.SaveChanges();
}
示例9: AverageBool
private bool AverageBool(IEnumerable<bool> itemBools)
{
var avgBool = itemBools.Average(i => Convert.ToDouble(i));
var isBool = Convert.ToBoolean(Round(avgBool));
return isBool;
}
示例10: GetStandardDeviation
private int GetStandardDeviation(IEnumerable<int> values)
{
var setAverage = values.Average();
var diffSqTotal = values.Sum((val) => (val - setAverage) * (val - setAverage));
var diffSqAvg = (diffSqTotal / (values.Count() - 1));
return (int)Math.Sqrt(diffSqAvg);
}
示例11: Average
public static FlowView Average(IEnumerable<FlowView> views)
{
if (views == null || !views.Any()) return null;
var first = views.FirstOrDefault();
return new FlowView
{
StatTime = first.StatTime,
ENodebId = first.ENodebId,
SectorId = first.SectorId,
PdcpUplinkFlow = views.Average(x => x.PdcpUplinkFlow),
PdcpDownlinkFlow = views.Average(x => x.PdcpDownlinkFlow),
AverageUsers = views.Average(x => x.AverageUsers),
MaxUsers = views.Max(x => x.MaxUsers),
AverageActiveUsers = views.Average(x => x.AverageActiveUsers),
MaxActiveUsers = views.Max(x => x.MaxActiveUsers)
};
}
示例12: calcStdDev
static double calcStdDev(IEnumerable<double> values)
{
double ret = 0;
double avg = values.Average();
double sum = values.Sum(d => Math.Pow(d - avg, 2));
ret = Math.Sqrt((sum) / (values.Count() - 1));
return ret;
}
示例13: GetRating
/// <summary>
/// Gets the average rating for the given players.
/// These players are typically all players in a specific line.
/// </summary>
/// <param name="players"></param>
/// <returns></returns>
public static decimal GetRating(IEnumerable<Player> players)
{
//TODO per linie de rating uitrekenen door de primary en wellicht ook secondary skills te pakken ofzoiets...
// Nu eerst gewoon de gemiddelde rating van elke speler pakken...
var average = players.Average(player => player.Rating);
return average;
}
示例14: PerfIteratorResult
public PerfIteratorResult(IEnumerable<PerfRoundResult> resultsList)
{
this.ResultsList = resultsList;
this.RepeatCount = resultsList.Count();
this.OverallAverageTicks = resultsList.Average(r => r.AverageTicks);
this.OverallMaxTicks = resultsList.Max(r => r.MaxTicks);
this.OverallMinTicks = resultsList.Min(r => r.MinTicks);
}
示例15: CalculatePricePerServing2
public static decimal CalculatePricePerServing2(IEnumerable<Meal> meals)
{
if (meals == null || !meals.Any(p => p != null && p.Price != 0 && p.Servings != 0))
{
return -1;
}
return meals.Average(p => p.Servings / p.Price);
}