61 lines
1.3 KiB
Haskell
61 lines
1.3 KiB
Haskell
{-# 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
|
|
import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds)
|
|
|
|
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" .= utcTimeToPOSIXSeconds time,
|
|
"cadence" .= cadence,
|
|
"power" .= power,
|
|
"heartRate" .= heartRate
|
|
]
|