commit 617feef05167a1bebdbd243203ddab5167dd3dae
parent 200c1019c4fba3ecd8330da4de15806dfd59fd0a
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 10 Nov 2024 15:43:13 +0000
extract Point from Track
Diffstat:
3 files changed, 62 insertions(+), 35 deletions(-)
diff --git a/lib/Point.hs b/lib/Point.hs
@@ -0,0 +1,59 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE RecordWildCards #-}
+
+module Point
+ ( Pos (..),
+ Point (..),
+ )
+where
+
+import Control.Exception
+import Data.Aeson
+import Data.ByteString.Lazy.Char8 qualified as L
+import Data.Either
+import Data.Functor ((<&>))
+import Data.List as List
+import Data.List qualified
+import Data.Map as Map
+import Data.Maybe
+import Data.Text qualified
+import Data.Text.Lazy as T
+import Data.Time
+import Data.Time.ISO8601 qualified
+import Debug.Trace (trace, traceShow)
+import Text.Read (readMaybe)
+import Text.XML
+import Text.XML.Cursor as Cursor
+
+data Pos = Pos Double Double (Maybe Double) deriving (Show, Eq)
+
+type Power = Maybe Int
+
+type Cadence = Maybe Int
+
+type HeartRate = Maybe Int
+
+data Point = Point
+ { pos :: Pos,
+ time :: UTCTime,
+ cadence :: Cadence,
+ power :: Power,
+ heartRate :: HeartRate
+ }
+ deriving (Show)
+
+instance ToJSON Pos where
+ toJSON (Pos lat lon ele) =
+ case ele of
+ Just e -> object ["lat" .= lat, "lon" .= lon, "ele" .= e]
+ Nothing -> object ["lat" .= lat, "lon" .= lon, "ele" .= Null]
+
+instance ToJSON Point where
+ toJSON Point {..} =
+ object
+ [ "pos" .= pos,
+ "time" .= time,
+ "cadence" .= cadence,
+ "power" .= power,
+ "heartRate" .= heartRate
+ ]
diff --git a/lib/Track.hs b/lib/Track.hs
@@ -3,9 +3,8 @@
module Track
( Track,
- Pos (..),
+ module Point,
BadFile,
- Point (..),
parse,
parseFile,
parseBS,
@@ -32,39 +31,7 @@ import Debug.Trace (trace, traceShow)
import Text.Read (readMaybe)
import Text.XML
import Text.XML.Cursor as Cursor
-
-data Pos = Pos Double Double (Maybe Double) deriving (Show, Eq)
-
-type Power = Maybe Int
-
-type Cadence = Maybe Int
-
-type HeartRate = Maybe Int
-
-data Point = Point
- { pos :: Pos,
- time :: UTCTime,
- cadence :: Cadence,
- power :: Power,
- heartRate :: HeartRate
- }
- deriving (Show)
-
-instance ToJSON Pos where
- toJSON (Pos lat lon ele) =
- case ele of
- Just e -> object ["lat" .= lat, "lon" .= lon, "ele" .= e]
- Nothing -> object ["lat" .= lat, "lon" .= lon, "ele" .= Null]
-
-instance ToJSON Point where
- toJSON Point {..} =
- object
- [ "pos" .= pos,
- "time" .= time,
- "cadence" .= cadence,
- "power" .= power,
- "heartRate" .= heartRate
- ]
+import Point
-- TODO do we even need this type?
type Track = [Point]
diff --git a/souplesse.cabal b/souplesse.cabal
@@ -98,6 +98,7 @@ library souplesse-lib
exposed-modules:
Track
Store
+ Point
hs-source-dirs:
lib
build-depends: