extract Point from Track
This commit is contained in:
parent
200c1019c4
commit
617feef051
59
lib/Point.hs
Normal file
59
lib/Point.hs
Normal file
@ -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
|
||||||
|
]
|
37
lib/Track.hs
37
lib/Track.hs
@ -3,9 +3,8 @@
|
|||||||
|
|
||||||
module Track
|
module Track
|
||||||
( Track,
|
( Track,
|
||||||
Pos (..),
|
module Point,
|
||||||
BadFile,
|
BadFile,
|
||||||
Point (..),
|
|
||||||
parse,
|
parse,
|
||||||
parseFile,
|
parseFile,
|
||||||
parseBS,
|
parseBS,
|
||||||
@ -32,39 +31,7 @@ import Debug.Trace (trace, traceShow)
|
|||||||
import Text.Read (readMaybe)
|
import Text.Read (readMaybe)
|
||||||
import Text.XML
|
import Text.XML
|
||||||
import Text.XML.Cursor as Cursor
|
import Text.XML.Cursor as Cursor
|
||||||
|
import Point
|
||||||
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
|
|
||||||
]
|
|
||||||
|
|
||||||
-- TODO do we even need this type?
|
-- TODO do we even need this type?
|
||||||
type Track = [Point]
|
type Track = [Point]
|
||||||
|
@ -98,6 +98,7 @@ library souplesse-lib
|
|||||||
exposed-modules:
|
exposed-modules:
|
||||||
Track
|
Track
|
||||||
Store
|
Store
|
||||||
|
Point
|
||||||
hs-source-dirs:
|
hs-source-dirs:
|
||||||
lib
|
lib
|
||||||
build-depends:
|
build-depends:
|
||||||
|
Loading…
Reference in New Issue
Block a user