souplesse

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a15346ae7ac0d0b9b9647f7c8f8e5c24e2535c50
parent b572e353b47bc2e1da79b995fe019f6aaaea9c97
Author: Daniel Barlow <dan@telent.net>
Date:   Thu, 31 Oct 2024 18:29:57 +0000

add Track.parseFile and call it from the main app

that's right, this is no longer a hello world app

Diffstat:
MREADME.md | 3+++
Mapp/Main.hs | 8+++++++-
Mlib/Track.hs | 9+++++++++
Msouplesse.cabal | 4+++-
4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -61,3 +61,6 @@ _Do not look below this line_ * [done] need a real gpx file with namespace decls before we can parse power and stuff * [done] tests seem to pass without <gpx> element? * [done] stop returning bogus data when missing required elements (e.g. time) +* can we lose this "if isJust lat && isJust lon && isJust ts" wart? +* probably we should store points in a more efficient form than + a singly-linked list diff --git a/app/Main.hs b/app/Main.hs @@ -1,4 +1,10 @@ module Main where +import Control.Exception +import Track(parseFile) +import Data.List as List + main :: IO () -main = putStrLn "Hello, Haskell!" +main = do + points <- Track.parseFile "track.gpx" + putStrLn ("loaded " ++ (show (List.length points))) diff --git a/lib/Track.hs b/lib/Track.hs @@ -10,6 +10,7 @@ module Track heartRate, time, parse, + parseFile, Track.length, ) where @@ -20,6 +21,7 @@ import Data.List as List import Data.List qualified import Data.Map as Map import Data.Maybe +import Data.Either import Data.Text qualified import Data.Text.Lazy as T import Data.Time @@ -110,3 +112,10 @@ parse str = do length :: Track -> Int length = Data.List.length + +-- parseFile :: FilePath -> IO [Point] +parseFile name = do + gpx <- Text.XML.readFile def name + return $ case getPoints (fromDocument gpx) of + Left err -> [] + Right points -> points diff --git a/souplesse.cabal b/souplesse.cabal @@ -68,7 +68,9 @@ executable souplesse -- other-extensions: -- Other library packages from which modules are imported. - build-depends: base ^>=4.18.2.1 + build-depends: + base ^>=4.18.2.1 + , souplesse-lib -- Directories containing source files. hs-source-dirs: app