Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. namespace yield
  4. {
  5. public static class MovingAverageTask
  6. {
  7. public static IEnumerable<DataPoint> MovingAverage(this IEnumerable<DataPoint> data, int windowWidth)
  8. {
  9. var sum = 0.0;
  10. var queue = new Queue<double>();
  11. foreach (var i in data)
  12. {
  13. queue.Enqueue(i.OriginalY);
  14. sum += i.OriginalY;
  15. if (queue.Count > windowWidth)
  16. sum -= queue.Dequeue();
  17. i.AvgSmoothedY = sum / queue.Count;
  18. yield return i;
  19. }
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement