Youtube video and text (draft).
[speedfreak] / Client / calculate.cpp
index 85c22c7..edd4246 100644 (file)
@@ -2,6 +2,7 @@
  * Calculate class to process accelerometer data
  *
  * @author      Kai Rasilainen
+ * @author      Jukka Kurttila <jukka.kurttila@fudeco.com>
  * @copyright   (c) 2010 Speed Freak team
  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
  */
@@ -40,18 +41,31 @@ void Calculate::reset()
     peakPower = 0;
     currentPower = 0;
     currentSpeed = 0;
+    maxSpeed = 0;
     distanceTraveled = 0;
     lastAcceleration = 0;
     lastDistance = 0;
     lastSpeed = 0;
     numOfIterations = 0;
     totalTime = 0;
-    //count = 0;
+    count = 0;
 
-    speedCheckPoints.append(10);
-    speedCheckPoints.append(20);
-    speedCheckPoints.append(30);
-    speedCheckPoints.append(40);
+    if(speedCheckPoints.count() == 0)
+    {
+        speedCheckPoints.append(10);
+        speedCheckPoints.append(20);
+        speedCheckPoints.append(30);
+        speedCheckPoints.append(40);
+        speedCheckPoints.append(50);
+        speedCheckPoints.append(60);
+        speedCheckPoints.append(70);
+        speedCheckPoints.append(80);
+        speedCheckPoints.append(90);
+        speedCheckPoints.append(100);
+    }
+
+    checkPointCounter = 0;
+    checkPoint = speedCheckPoints[checkPointCounter];
 
 }
 
@@ -78,6 +92,10 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds)
     // First integration of acceleration provides speed
     currentSpeed = (lastSpeed + (((currentAcceleration + lastAcceleration) * seconds) / 2));
 
+    // Update maximum speed
+    if (currentSpeed > maxSpeed)
+        maxSpeed = currentSpeed;
+
     // Second integration: distance.
     distanceTraveled = (lastDistance + (((currentSpeed + lastSpeed) * seconds) / 2));
 
@@ -109,22 +127,22 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds)
         numOfIterations--;
     }
 
-    // Checkpoints
-    if ((lastSpeed == 0))
-    {
-        lastCheckpoint = 0;
-    }
-
-    // List of checkpoints
-    if (!(speedCheckPoints.isEmpty()))
+    if( (checkPoint > 0) && (currentSpeed*3.6 > checkPoint) )
     {
-        foreach (double speed, speedCheckPoints)
+        //Update checkPoint
+        if( checkPointCounter <= speedCheckPoints.count() )
         {
-            if ((lastCheckpoint != floor(speed)) && (floor(getCurrentSpeed()) == floor(speed)))
+            //Save time
+            valuesMap.insert( checkPoint, totalTime );
+            if( checkPointCounter < speedCheckPoints.count() )
             {
-                emit checkPointReached(totalTime, getCurrentSpeed());
-                lastCheckpoint = floor(getCurrentSpeed());
+                checkPoint = speedCheckPoints[checkPointCounter];
             }
+            else
+            {
+                checkPoint = 0;
+            }
+            checkPointCounter++;
         }
     }
 
@@ -141,10 +159,8 @@ void Calculate::calculateParameters(double currentAcceleration, double seconds)
   * a short period of time. Velocity is set to zero to avoid
   * distance errors.
   */
-/*
 void Calculate::accelStoppedCheck(double currentAcceleration)
 {
-
     // counting number of acceleration samples that equals zero
     if (currentAcceleration==0) {
         count++;
@@ -152,13 +168,13 @@ void Calculate::accelStoppedCheck(double currentAcceleration)
         count = 0;
     }
 
-    // if count exceeds 15, we assume that velocity is zero
-    if (count >= 15)
+    // if count exceeds 25, we assume that velocity is zero
+    if (count >= 25)
     {
         currentSpeed=0;
     }
 }
-*/
+
 // Getters and setters
 
 double Calculate::getAverageSpeed()
@@ -278,4 +294,17 @@ void Calculate::setAveragePower(double value)
     averagePower = value;
 }
 
+double Calculate::getMaxSpeed()
+{
+    return maxSpeed;
+}
 
+void Calculate::setMaxSpeed(double value)
+{
+    maxSpeed = value;
+}
+
+QMap<int,double> Calculate::getValuesMap()
+{
+    return valuesMap;
+}