elanhickler

Untitled

Feb 15th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. Points average(const Points & points, double timerange)
  2. {
  3.     Points result;
  4.  
  5.     for (int i = 0; i < points.size(); ++i)
  6.     {
  7.         auto p = points[i];
  8.         double start = p.first - timerange/2;
  9.         double end = p.first + timerange/2;
  10.         double avg = p.second;
  11.         int num_pts_found = 1;
  12.  
  13.         int needle = i-1;
  14.         while (needle >= 0 && points[needle].first >= start)
  15.         {
  16.             avg += points[needle--].second;
  17.             ++num_pts_found;
  18.         }
  19.  
  20.         needle = i+1;
  21.         while (needle < points.size() && points[needle].first <= end)
  22.         {
  23.             avg += points[needle++].second;
  24.             ++num_pts_found;
  25.         }
  26.  
  27.         result.push_back({ p.first, avg/=num_pts_found });
  28.     }
  29.  
  30.     return result;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment