author andrei1089 Sun, 14 Feb 2010 13:09:04 +0000 (15:09 +0200) committer andrei1089 Sun, 14 Feb 2010 13:09:04 +0000 (15:09 +0200)
Using formula from [1] to calculate the number of lost calories.

[1] http://www.indiacurry.com/weightloss/walkingrunningcalories.htm

index 31992ca..bfd6a8f 100644 (file)
@@ -460,7 +460,7 @@ class PedoController(Singleton):
else:
self.v[0].steps += cnt
self.v[0].dist += self.get_distance(cnt)
-            self.v[0].calories += self.get_distance(cnt)
+            self.v[0].calories += self.get_calories(self.get_distance(cnt))
self.v[0].time += time.time() - self.last_time
if last_steps:
self.save_values()
@@ -469,6 +469,24 @@ class PedoController(Singleton):
self.notify(True)
self.last_time = time.time()

+    def get_calories(self, distance):
+        """calculate lost calories for the distance and weight given as parameters
+        """
+        #different coefficient for running and walking
+        if self.mode == 0:
+            coef = 0.53
+        else:
+            coef = 0.75
+
+        #convert distance from meters to miles
+        distance *= 0.000621371192
+
+        weight = self.weight
+        #convert weight from kg to pounds
+        if self.unit == 0:
+            weight *= 2.20462262
+        return weight * distance * coef
+
def set_mode(self, mode):
self.mode = mode
self.set_height(self.height_interval)
@@ -525,9 +543,6 @@ class PedoController(Singleton):
steps = self.counter
return self.STEP_LENGTH * steps;

-    def get_calories(self, steps):
-        return steps
-