当前位置: 首页>>代码示例>>C#>>正文


C# Queue.Average方法代码示例

本文整理汇总了C#中Queue.Average方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Average方法的具体用法?C# Queue.Average怎么用?C# Queue.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue.Average方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SmoothSamples

        private void SmoothSamples(int windowSize)
        {
            Queue<double> window = new Queue<double>();// Enumerable.Repeat(0.0, windowSize));

            SmoothedSamples = new List<double>();

            foreach (double s in Samples)
            {
                if (window.Count == windowSize)
                {
                    window.Dequeue();
                }
                window.Enqueue(s);
                double avg = window.Average();
                SmoothedSamples.Add(avg);
            }
        }
开发者ID:david-wb,项目名称:Transcriber,代码行数:17,代码来源:WaveFile.cs

示例2: MovingAverageKendall

 public static IEnumerable<double> MovingAverageKendall(IEnumerable<double> list, int window)
 {
     Queue<double> buffer = new Queue<double>(window);
     int i = 0;
     foreach (double item in list)
     {
         if (i < window)
         {
             i++;
         }
         else
         {
             buffer.Dequeue();
         }
         buffer.Enqueue(item);
         if (i == window)
         {
             yield return buffer.Average();
         }
     }
 }
开发者ID:JohanLarsson,项目名称:ChatMaChampionship,代码行数:21,代码来源:Mas.cs

示例3: RunServer

 private static Task RunServer(string host, int port, int faultInterval) {
     return Task.Factory.StartNew(() => {
         var t = Stopwatch.StartNew();
         var instrumentation = new ClacksInstrumentation();
         var dispatcher = new SyncCommandRepository();
         dispatcher.AddCommand("BIN", request => Response.Create("OK").WithData(request.Data), DataExpectation.Auto);
         var clientHandlerFactory = new FaultingSyncClientHandlerFactory(dispatcher, faultInterval);
         using(new ClacksServer(new IPEndPoint(IPAddress.Parse(host), port), instrumentation, clientHandlerFactory)) {
             Console.WriteLine("created server");
             Thread.Sleep(TimeSpan.FromMinutes(1));
             var rates = new Queue<double>();
             var totalRequests = 0;
             while(true) {
                 lock(instrumentation.Connections) {
                     var requestCount = instrumentation.Requests - totalRequests;
                     totalRequests += requestCount;
                     rates.Enqueue(requestCount / t.Elapsed.TotalSeconds);
                     if(rates.Count > 5) {
                         rates.Dequeue();
                     }
                     t.Restart();
                     Console.WriteLine("{0} Processed {1} requests with {2} faults via {3}/{4} total/active connections at {5,6:0} requests/second and {6:0.000}ms/request",
                         DateTime.Now,
                         instrumentation.Requests,
                         clientHandlerFactory.Faults,
                         instrumentation.Connected,
                         instrumentation.Connections.Count,
                         rates.Average(),
                         TimeSpan.FromTicks(instrumentation.RequestTicks).TotalMilliseconds / instrumentation.Requests
                         );
                     foreach(var statusGroup in from con in instrumentation.Connections
                                                group con by con.Value.Status into grouped
                                                select new { Status = grouped.Key, Connections = grouped }) {
                         Console.WriteLine("  {0} in state '{1}': {2}",
                             statusGroup.Connections.Count(),
                             statusGroup.Status,
                             string.Join(", ", from con in statusGroup.Connections orderby con.Value.Id select con.Value.Id)
                         );
                     }
                 }
                 Thread.Sleep(TimeSpan.FromMinutes(1));
             }
         }
     });
 }
开发者ID:MindTouch,项目名称:MindTouch.Clacks,代码行数:45,代码来源:Program.cs

示例4: createADV

 private static void createADV()
 {
     bool flag;
     bool flag1;
     string[] files = Directory.GetFiles("C:\\Users\\Jiahai\\Documents\\Visual Studio 2012\\Projects\\earingdataProj\\earingdataProj\\bin\\Debug\\Daily\\DB");
     for (int i = 0; i < (int)files.Length; i++)
     {
         string str = files[i];
         char[] chrArray = new char[] { '\\' };
         string[] strArrays = str.Split(chrArray);
         FileHelperEngine fileHelperEngine = new FileHelperEngine(typeof(RowDailyData));
         RowDailyData[] rowDailyDataArray = (RowDailyData[])fileHelperEngine.ReadFile(str);
         Queue<long> nums = new Queue<long>();
         List<DailyData1> dailyData1s = new List<DailyData1>();
         int num = -1;
         decimal num1 = new decimal(0);
         decimal num2 = new decimal(0);
         bool flag2 = true;
         decimal num3 = new decimal(0);
         bool flag3 = true;
         RowDailyData[] rowDailyDataArray1 = rowDailyDataArray;
         for (int j = 0; j < (int)rowDailyDataArray1.Length; j++)
         {
             RowDailyData rowDailyDatum = rowDailyDataArray1[j];
             DailyData1 dailyData1 = new DailyData1();
             if (flag2)
             {
                 flag2 = false;
             }
             else if (!(num2 == new decimal(0)))
             {
                 num3 = rowDailyDatum.adjusted / num2;
                 flag1 = (num3 > new decimal(49) ? false : !(num3 < new decimal(2, 0, 0, false, 2)));
                 if (!flag1)
                 {
                     flag3 = false;
                     break;
                 }
             }
             else
             {
                 flag3 = false;
                 break;
             }
             num2 = rowDailyDatum.adjusted;
             if (rowDailyDatum.close != new decimal(0))
             {
                 num1 = rowDailyDatum.adjusted / rowDailyDatum.close;
             }
             flag = (num1 <= new decimal(6, 0, 0, false, 1) ? false : !(num1 >= new decimal(14, 0, 0, false, 1)));
             if (flag)
             {
                 dailyData1.open = rowDailyDatum.open;
                 dailyData1.high = rowDailyDatum.high;
                 dailyData1.low = rowDailyDatum.low;
                 dailyData1.close = rowDailyDatum.close;
             }
             else
             {
                 dailyData1.open = rowDailyDatum.open * num1;
                 dailyData1.high = rowDailyDatum.high * num1;
                 dailyData1.low = rowDailyDatum.low * num1;
                 dailyData1.close = rowDailyDatum.close * num1;
             }
             dailyData1.symbol = rowDailyDatum.symbol;
             dailyData1.date = rowDailyDatum.date;
             dailyData1.volume = rowDailyDatum.Volume;
             if (nums.Count == 20)
             {
                 num = (int)nums.Average();
                 nums.Dequeue();
                 nums.Enqueue(rowDailyDatum.Volume);
             }
             else
             {
                 nums.Enqueue(rowDailyDatum.Volume);
             }
             dailyData1.adv = num;
             dailyData1s.Add(dailyData1);
         }
         if (flag3)
         {
             FileHelperEngine fileHelperEngine1 = new FileHelperEngine(typeof(DailyData1));
             fileHelperEngine1.WriteFile(string.Format("Daily\\DBadv\\{0}", strArrays[12]), dailyData1s);
         }
     }
 }
开发者ID:Jack-coastal,项目名称:earningProj,代码行数:87,代码来源:Program.cs

示例5: strategyCloseIn


//.........这里部分代码省略.........
                                tempitem.pnl = size * (item.close - pricein);
                                tempitem.daypnl = size * (item.close - item.open);
                                tempitem.overnightpnl = size * (item.open - pricein);
                                tempitem.priceout = item.close;
                                #region short spy hedge
                                spysize = Convert.ToInt32(buyinpower / spyin);
                                tempitem.spypnl = -spysize * (item.spyclose - spyin);
                                tempitem.dayspypnl = -spysize * (item.spyclose - item.spyopen);
                                tempitem.overnightspypnl = -spysize * (item.spyopen - spyin);
                                #endregion

                                #region win10 or lose10
                                if (tempitem.pnl / (pricein * size) >= (decimal)0.1)
                                {
                                    tempitem.win10 = 1;
                                }
                                else
                                {
                                    tempitem.win10 = 0;
                                }
                                if (tempitem.pnl / (pricein * size) <= -(decimal)0.1)
                                {
                                    tempitem.lose10 = 1;
                                }
                                else
                                {
                                    tempitem.lose10 = 0;
                                }
                                #endregion

                                #region 5 days beta array
                                if (Beta5Ds.Count == 5)
                                {
                                    avgBeta = Beta5Ds.Average();
                                    Beta5Ds.Dequeue();
                                    Beta5Ds.Enqueue(tempitem.beta);
                                }
                                else
                                {
                                    Beta5Ds.Enqueue(tempitem.beta);
                                }

                                #endregion

                                ReportEaring.Add(tempitem);
                                pricein = item.close;
                                spyin = item.spyclose;
                            }
                            #endregion

                            #endregion

                            #region exit logic
                            if (!findout && (item.close < (lowEaring * item.spyclose / spyearingdate)
                                //|| avgBeta<(decimal)-2
                                 || item.date == lastdate
                                ))
                            {
                                priceout = lowEaring * item.spyclose / spyearingdate;
                                findout = true;
                                exitdate = true;
                            }
                            #endregion
                        }

                        #region entry logic
开发者ID:Jack-coastal,项目名称:earningProj,代码行数:67,代码来源:Program.cs

示例6: checkMagnitude

 private int checkMagnitude(ref Queue<int> mags)
 {
     double avg = mags.Average();
     mags.Clear();
     return (int)Math.Round(avg);
 }
开发者ID:jburnett31,项目名称:SoftEng,代码行数:6,代码来源:YAMDDetector.cs

示例7: RunTuner

        private void RunTuner(double targetFreq, int stringNum)
        {
            double delta = 0;
            //double display = 50;
            //double currentFreq;
            double scaleFactor;

            switch (stringNum)
            {
                case 0:
                    scaleFactor = 4;
                    break;
                case 1:
                    scaleFactor = 5;
                    break;
                case 2:
                    scaleFactor = 6;
                    break;
                case 3:
                    scaleFactor = 9;
                    break;
                case 4:
                    scaleFactor = 11;
                    break;
                case 5:
                    scaleFactor = 14;
                    break;
                case 6:
                    scaleFactor = 20;
                    break;
                default:
                    scaleFactor = 5;
                    break;
            }

            Queue<Note> avgNoteQueue = new Queue<Note>();
            int maxAvgNoteQueueLength = 5;

            while (_runningTuner)
            {
                Note[] notes = _noteSource.GetNotes();
                if (notes == null)
                    continue;

                if (notes[0].ClosestRealNoteFrequency == 0)
                    continue;
                else if ((targetFreq - scaleFactor) > notes[0].frequency || notes[0].frequency > (targetFreq + scaleFactor))
                    continue;

                avgNoteQueue.Enqueue(notes[0]);
                if (avgNoteQueue.Count > maxAvgNoteQueueLength)
                {
                    avgNoteQueue.Dequeue();
                }

                double currentFreq = avgNoteQueue.Average(x => x.frequency);

                Application.Current.Dispatcher.Invoke(
                    DispatcherPriority.Render,
                    new Action<double>(setFreqText),
                    currentFreq);

                delta = currentFreq - targetFreq;

                double display = delta*(50/scaleFactor) + 50;

                Application.Current.Dispatcher.Invoke(
                    DispatcherPriority.Render,
                    new Action<double>(setTunerBarValue),
                    display);

                Thread.Sleep(100);

            }
        }
开发者ID:robinvierich,项目名称:fydp,代码行数:75,代码来源:TunerControl.xaml.cs

示例8: MainAsync


//.........这里部分代码省略.........

						long curKeys =  Volatile.Read(ref Keys);
						long curTrans = Volatile.Read(ref Transactions);
						long curBytes = Volatile.Read(ref Bytes);
						double curDiskWrites = perfDiskWrites.NextValue();
						double curDiskReads = perfDiskReads.NextValue();
						double curDiskWriteIo = perfDiskWriteIops.NextValue();
						double curDiskReadIo = perfDiskReadIops.NextValue();

						while (history.Count >= CAPACITY) history.Dequeue();

						var now = DateTime.UtcNow;
						history.Enqueue(new Datum
						{
							Date = now,
							Keys = curKeys,
							Commits = curTrans,
							Bytes = curBytes,
							DiskWriteBps = curDiskWrites,
							DiskReadBps = curDiskReads,
							DiskWriteIops = curDiskWriteIo,
							DiskReadIops = curDiskReadIo,
						});

						if (repaint)
						{
							Console.Title = "FdbBurner - " + (!hot ? "ICY COLD" : Randomized ? "HOT HOT HOT" : "HOT HOT");

							Console.BackgroundColor = !hot ? ConsoleColor.DarkCyan : Randomized ? ConsoleColor.DarkRed : ConsoleColor.DarkGreen;
							Console.Clear();
							Console.ForegroundColor = ConsoleColor.Gray;
							WriteAt(COL0, 1, "Pattern   : {0,10}", "");
							WriteAt(COL2, 1, "Value Size: {0,6} bytes", "");
							WriteAt(COL0, 3, "{0,-12}", "Transactions");
							WriteAt(COL1, 3, "{0,-12}", "Keys");
							WriteAt(COL2, 3, "{0,-10}", "Written Bytes");
							WriteAt(COL3, 3, "{0,-10}", "Disk Writes");
							WriteAt(COL4, 3, "{0,-10}", "Disk Reads");
							WriteAt(COL3, 7, "{0,-10}", "Write IOPS");
							WriteAt(COL4, 7, "{0,-10}", "Read IOPS");

							repaint = false;
						}

						Console.ForegroundColor = ConsoleColor.White;
						WriteAt(COL0 + 12, 1, "{0,-10}", Randomized ? "Random" : "Sequential");
						WriteAt(COL2 + 12, 1, "{0,6:N0}", Value.Count);

						WriteAt(COL0, 4, "{0,12:N0}", curTrans);
						WriteAt(COL1, 4, "{0,12:N0}", curKeys);
						WriteAt(COL2, 4, "{0,10:N1} MB", curBytes / 1048576.0);
						WriteAt(COL3, 4, "{0,10:N1} MB/s", curDiskWrites / 1048576.0);
						WriteAt(COL4, 4, "{0,10:N1} MB/s", curDiskReads / 1048576.0);

						if (history.Count > 1)
						{
							var old = history.Peek();
							var dur = (now - old.Date).TotalSeconds;
							double speed;

							Console.ForegroundColor = ConsoleColor.White;

							speed = (curTrans - old.Commits) / dur;
							WriteAt(COL0, 5, "{0,12:N0}", speed);

							speed = (curKeys - old.Keys) / dur;
							WriteAt(COL1, 5, "{0,12:N0}", speed);

							speed = (curBytes - old.Bytes) / dur;
							WriteAt(COL2, 5, "{0,10:N1} MB/s", speed / 1048576.0);

							var writeSpeed = history.Average(d => d.DiskWriteBps);
							var readSpeed = history.Average(d => d.DiskReadBps);
							WriteAt(COL3, 5, "{0,10:N1} MB/s", writeSpeed / 1048576.0);
							WriteAt(COL4, 5, "{0,10:N1} MB/s", readSpeed / 1048576.0);

							var writeIops = history.Average(d => d.DiskWriteIops);
							var readIops = history.Average(d => d.DiskReadIops);
							WriteAt(COL3, 8, "{0,10:N0} iops", writeIops);
							WriteAt(COL4, 8, "{0,10:N0} iops", readIops);

							var factor = speed > 0 ? writeSpeed / speed : 0;
							WriteLarge(0, 16, "{0,8:F3}", speed / 1048576.0);
							WriteLarge(0, 24, "{0,8:F3}", writeSpeed / 1048576.0);
							WriteLarge(0, 32, "X{0,5:F1}", factor);
						}


						Console.SetCursorPosition(0, 0);
					}

				}
			}
			finally
			{
				Console.CursorVisible = true;
				Console.ResetColor();
				Console.Clear();
			}
		}
开发者ID:rektide,项目名称:foundationdb-dotnet-client,代码行数:101,代码来源:Program.cs

示例9: GetSqrt3

 private static double GetSqrt3(double delta, Queue<double> datas)
 {
     double avg = datas.Average();
     double sqr = 0;
     foreach (double v in datas)
     {
         sqr = sqr + v * (v - avg);
     }
     sqr = Math.Sqrt(sqr / (datas.Count - 1));
     if (Math.Abs(sqr / avg) < 5e-9) //0.05ppm
         sqr = avg * 5e-9;
     else if (Math.Abs(sqr) < 1e-9) //10nV
         sqr = 1e-9;
     return sqr * delta;
 }
开发者ID:imdmmp,项目名称:kpgweigher,代码行数:15,代码来源:DeviceMgr.cs

示例10: FWaitForFish

        private bool FWaitForFish()
        {
            var devEnum = new MMDeviceEnumerator();
            var defaultDevice = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);

            var dtStart = DateTime.Now;
            var qMpv = new Queue<float>();

            while ((DateTime.Now - dtStart).TotalSeconds < 30)
            {
                Thread.Sleep(100);
                qMpv.Enqueue(defaultDevice.AudioMeterInformation.MasterPeakValue);
                if (qMpv.Count > 5)
                    qMpv.Dequeue();
                if (qMpv.Average() > 0.15)
                    return true;
                DoEvents();
            }

            return false;
        }
开发者ID:encse,项目名称:horgaszbot,代码行数:21,代码来源:MainWindow.xaml.cs


注:本文中的Queue.Average方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。