本文整理汇总了C#中System.Collections.Queue.Average方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Average方法的具体用法?C# Queue.Average怎么用?C# Queue.Average使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.Average方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuyLowStrategy
public BuyLowStrategy(int PreviousDaysN, int RunsPerDay, string symbol)
{
this.previousDaysN = PreviousDaysN;
this.runsPerDay = RunsPerDay;
// Initializing the fields
isDownReady = true;
isUpReady = true;
isReady = true;
turnAround = false;
orderSignal = 0;
firstDay = true;
// Initializing the previous days runs and the thresholds
dailyDownwardRuns = WarmUp(symbol, FieldName.downwardRuns);
dailyUpwardRuns = WarmUp(symbol, FieldName.upwardRuns);
downwardRunsThreshold = dailyDownwardRuns.Average();
upwardRunsThreshold = dailyUpwardRuns.Average();
}
示例2: getCorner
private myCoord getCorner()
{
const float eps = 0.00006f; //epsilon value, dictates precision for the variance
myCoord sample = new myCoord(); //sample data we get after each time span
Queue<float> xQueue = new Queue<float>(10); //queues for the x, y, z values
Queue<float> yQueue = new Queue<float>(10); //we get data every 0.2 seconds, and stop when we detect that the
Queue<float> zQueue = new Queue<float>(10); //hand has stayed still for 2 seconds, hence analyse the last 10 values
System.DateTime t1 = System.DateTime.Now; //current time
System.TimeSpan span = new System.TimeSpan(0, 0, 0, 0, 200); //time span of 0.2 seconds between each sampling of the position
System.DateTime t3 = new System.DateTime(); //time at which we have to get the new sample
//fill the queues with the initial 10 samples
while (xQueue.Count < 10)
{
t3 = t1.Add(span); //when we get the next round of data
xQueue.Enqueue(xCoord); yQueue.Enqueue(yCoord); zQueue.Enqueue(zCoord); //get current round of data
//wait until next round
while (t1 < t3)
{
t1 = System.DateTime.Now;
}
}
//compute the initial variances of position data
float xVar = Variance(xQueue);
float yVar = Variance(yQueue);
float zVar = Variance(zQueue);
//while the variances are to high, meaning the hand isn't still, keep tracking the hand
while ((xVar > eps | yVar > eps | zVar > eps) || (xQueue.Average() == 0 && yQueue.Average() == 0 && zQueue.Average() == 0))
{
t3 = t1.Add(span); //when we get next round of data
xQueue.Dequeue(); yQueue.Dequeue(); zQueue.Dequeue(); //discard old data
xQueue.Enqueue(xCoord); yQueue.Enqueue(yCoord); zQueue.Enqueue(zCoord); //get current round
xVar = Variance(xQueue); yVar = Variance(yQueue); zVar = Variance(zQueue); //compute new variance
//wait until next round
while (t1 < t3)
{
t1 = System.DateTime.Now;
}
}
//when the hand hasn't moved return it's position, averaging over the last 10 positions
sample.X = xQueue.Average();
sample.Y = yQueue.Average();
sample.Z = zQueue.Average();
Console.Beep(); //give an audio confirmation to the user
return sample;
}