On Sun, 27 Mar 2011 18:07:51 +0100
Jonathan Waller <jonathanmarkwal...@googlemail.com> wrote:
> Something to consider for your current code are that some devices (mine
> included) have a "Smart Recording" mode which inserts points at
> irregular time intervals.  The averaging should be weighted by the time
> between points.  Perhaps the averaging might be best controlled by a 100
> second average rather than a 100 data point average, I don't know fi
> this would have a useful effect.

Let's see. Here's another patch which adds a GraphData.average method.
It takes the 100th x value as the period for averaging. It works both
for distance and time based data. It obviously requires some work but
it shows how results of the approach you've proposed may look like.

-- 
Jan Stępień <j...@stepien.cc>
diff --git a/pytrainer/lib/activity.py b/pytrainer/lib/activity.py
index 56bba60..33710fb 100644
--- a/pytrainer/lib/activity.py
+++ b/pytrainer/lib/activity.py
@@ -497,6 +497,8 @@ class Activity:
 			self.time_data['hr'].addPoints(x=track['time_elapsed'], y=track['hr'])
 			self.time_data['hr_p'].addPoints(x=track['time_elapsed'], y=hr_p)
 			self.time_data['cadence'].addPoints(x=track['time_elapsed'], y=track['cadence'])
+		self.distance_data['speed'].average()
+		self.time_data['speed'].average()
 		#Remove data with no values
 		for item in self.distance_data.keys():
 			if len(self.distance_data[item]) == 0:
diff --git a/pytrainer/lib/graphdata.py b/pytrainer/lib/graphdata.py
index d806cf7..cd3af78 100644
--- a/pytrainer/lib/graphdata.py
+++ b/pytrainer/lib/graphdata.py
@@ -149,7 +149,23 @@ y values: %s''' % (self.title,
     str(self.y_values)
     )
 
-    
-
-
-
+    def average(self):
+        assert len(self.x_values) == len(self.y_values)
+        StartingPoints = 100
+        x_value = x_value_per_average = self.x_values[StartingPoints - 1]
+        y_values_sum = sum(self.y_values[0:StartingPoints])
+        averaged_points = StartingPoints
+        count = len(self.y_values)
+        for i in range(count):
+            self.y_values[i] = y_values_sum / (averaged_points - 1)
+            next_index = i + 1
+            while (next_index < count and
+                    x_value - self.x_values[i] < x_value_per_average):
+                x_value = self.x_values[next_index]
+                next_index += 1
+            if next_index == i + 1:
+                # x_value hasn't changed.
+                averaged_points -= 1
+            else:
+                averaged_points = next_index - i
+            y_values_sum = sum(self.y_values[i + 1 : i + averaged_points])
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Pytrainer-devel mailing list
Pytrainer-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytrainer-devel

Reply via email to