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
About these ads

5 Responses to “How Far is my Morning Run”

  1. Michael Says:

    So…. how far is your morning run?

  2. Brian Says:

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

    • Brian Says:

      oh, probably haskell huh? =)

      • 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).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: