add Track.parseFile and call it from the main app

that's right, this is no longer a hello world app
This commit is contained in:
Daniel Barlow 2024-10-31 18:29:57 +00:00
parent b572e353b4
commit a15346ae7a
4 changed files with 22 additions and 2 deletions

View File

@ -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

View File

@ -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)))

View File

@ -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

View File

@ -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