How Far is my Morning Run

May 27, 2010

I always assumed my run was about 5k, but being out of shape it felt more like 7km.  Eventually this bugged me enough that I spent a whole ten minutes at a coffee shop to learn the GPX library and make a program that converts my GPX traces (I carry a GPS logger on jogs) to a distance.  Thank you hackage, thank you Tony.

module Main where

import Data.Geo.GPX
import Data.GPS
import Control.Monad
import System.Environment (getArgs)

main = do
 file <- liftM head getArgs
 run <- readGpxFile file
 let cs = map (degreePairToDMS. latlon) . trkpts . head . trksegs . head . trks . head $ run
     pairs = zip cs (drop 1 cs)
     dist = sum (map (uncurry distance) pairs)
 print dist

5 Responses to “How Far is my Morning Run”

  1. Michael Says:

    So…. how far is your morning run?

  2. tommd Says:

    5.4 km. I knew it – I’m out of shape.

  3. Brian Says:

    So what programming language is that? Impressive for 10 minutes of research and work!

  4. Brian Says:

    oh, probably haskell huh? =)

  5. tommd Says:

    Yes, it is Haskell. To be fair I already knew about GPX but not how to use it, so I had to look up the functions (readGPXFile, latlon, trkpts, trksegs, trks). Also, I am the author of the piddly little GPS library (providing distance calculations, basic operations on tracks).

Comments are closed.

%d bloggers like this: