]> git.street.me.uk Git - andy/viking.git/commitdiff
Add function to return an average moving speed for a track.
authorRob Norris <rw_norris@hotmail.com>
Fri, 20 Jan 2012 01:00:50 +0000 (01:00 +0000)
committerRob Norris <rw_norris@hotmail.com>
Fri, 20 Jan 2012 01:00:50 +0000 (01:00 +0000)
This method doesn't use samples that differ over the specified time limit - effectively skipping that time chunk from the total time - hence removing the 'stationary' bits to give only the moving parts.

src/viktrack.c
src/viktrack.h

index f56637527f6bac27e14d779ad253dc0b74710d1d..06bac07742deeb77b4004920e834d2f50ba242f0 100644 (file)
@@ -309,6 +309,42 @@ gdouble vik_track_get_average_speed(const VikTrack *tr)
   return (time == 0) ? 0 : ABS(len/time);
 }
 
+/**
+ * Based on a simple average speed, but with a twist - to give a moving average.
+ *  . GPSs often report a moving average in their statistics output
+ *  . bicycle speedos often don't factor in time when stopped - hence reporting a moving average for speed
+ *
+ * Often GPS track will record every second but not when stationary
+ * This method doesn't use samples that differ over the specified time limit - effectively skipping that time chunk from the total time
+ *
+ * Suggest to use 60 seconds as the stop length (as the default used in the TrackWaypoint draw stops factor)
+ */
+gdouble vik_track_get_average_speed_moving (const VikTrack *tr, int stop_length_seconds)
+{
+  gdouble len = 0.0;
+  guint32 time = 0;
+  if ( tr->trackpoints )
+  {
+    GList *iter = tr->trackpoints->next;
+    while (iter)
+    {
+      if ( VIK_TRACKPOINT(iter->data)->has_timestamp &&
+          VIK_TRACKPOINT(iter->prev->data)->has_timestamp &&
+          (! VIK_TRACKPOINT(iter->data)->newsegment) )
+      {
+       if ( ( VIK_TRACKPOINT(iter->data)->timestamp - VIK_TRACKPOINT(iter->prev->data)->timestamp ) < stop_length_seconds ) {
+         len += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
+                                 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
+       
+         time += ABS(VIK_TRACKPOINT(iter->data)->timestamp - VIK_TRACKPOINT(iter->prev->data)->timestamp);
+       }
+      }
+      iter = iter->next;
+    }
+  }
+  return (time == 0) ? 0 : ABS(len/time);
+}
+
 gdouble vik_track_get_max_speed(const VikTrack *tr)
 {
   gdouble maxspeed = 0.0, speed = 0.0;
index 9742a15ef46b85ee5ecd3b72aca2a43da49b0882..51337fe6b9c19dc0240560fe2324ef545994dfb6 100644 (file)
@@ -83,6 +83,7 @@ void vik_track_remove_dup_points ( VikTrack *vt );
 
 gdouble vik_track_get_max_speed(const VikTrack *tr);
 gdouble vik_track_get_average_speed(const VikTrack *tr);
+gdouble vik_track_get_average_speed_moving ( const VikTrack *tr, int stop_length_seconds );
 
 void vik_track_convert ( VikTrack *tr, VikCoordMode dest_mode );
 gdouble *vik_track_make_elevation_map ( const VikTrack *tr, guint16 num_chunks );