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
May 27, 2010 at 10:17 pm
So…. how far is your morning run?
May 27, 2010 at 10:18 pm
5.4 km. I knew it – I’m out of shape.
July 9, 2010 at 3:28 am
So what programming language is that? Impressive for 10 minutes of research and work!
July 9, 2010 at 3:29 am
oh, probably haskell huh? =)
July 9, 2010 at 3:57 am
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).