Safe Haskell | None |
---|---|
Language | Haskell2010 |
- readMessages :: ByteString -> Either String Messages
- readFileMessages :: FilePath -> IO (Either String Messages)
- parseMessages :: Parser Messages
- newtype Messages = Messages {}
- data Message = Message {}
- data Field = Field {}
- data Value
- data SingletonValue
- data ArrayValue
- messages :: Applicative f => (Message -> f Message) -> Messages -> f Messages
- message :: (Contravariant f, Applicative f) => Int -> (Message -> f Message) -> Messages -> f Messages
- messageNumber :: Functor f => (Int -> f Int) -> Message -> f Message
- fields :: Applicative f => (Field -> f Field) -> Message -> f Message
- field :: (Contravariant f, Applicative f) => Int -> (Field -> f Field) -> Message -> f Message
- fieldNumber :: Functor f => (Int -> f Int) -> Field -> f Field
- fieldValue :: Functor f => (Value -> f Value) -> Field -> f Field
- int :: Applicative f => (Int -> f Int) -> Field -> f Field
- real :: Applicative f => (Double -> f Double) -> Field -> f Field
- text :: Applicative f => (Text -> f Text) -> Field -> f Field
- byte :: Applicative f => (Word8 -> f Word8) -> Field -> f Field
- ints :: Applicative f => (Seq Int -> f (Seq Int)) -> Field -> f Field
- reals :: Applicative f => (Seq Double -> f (Seq Double)) -> Field -> f Field
- bytestring :: Applicative f => (ByteString -> f ByteString) -> Field -> f Field
Messages API
A high-level view of a FIT file as a sequence of data messages. This is the recommended API for pulling information out of a FIT file, but if you need access to the exact structure of the file you can use the API in Fit.Internal.FitFile and Fit.Internal.Parse.
Some basic lenses are also provided for working with the Messages API. These can make it much easier to extract information from a FIT file, especially since you usually know what sort of data you're expecting to find.
For example, from the FIT global profile we can find that the global message
number for record
messages is 20, and within a record
message the speed
field has field number 6. The following code gets the speed
field from all
record
messages in the file:
Right fit <- readFileMessages "file.fit" let speeds = fit ^.. message 20 . field 6 . int -- speeds :: [Int]
Note that this package doesn't provide any lens combinators (like (^..)
),
so you'll need to use ones from a lens package.
readMessages :: ByteString -> Either String Messages Source
Parse a strict ByteString
containing the FIT data into its Messages
readFileMessages :: FilePath -> IO (Either String Messages) Source
Parse the given FIT file into its Messages
parseMessages :: Parser Messages Source
An Attoparsec parser for Messages
The collection of data messages from the FIT file.
A FIT data message
A single field in a FIT data message
FIT values can either contain a single piece of data or an array. FIT arrays are homogenous
data SingletonValue Source
A singleton value. In the Messages API we abstract over the specific FIT base type of the field. For example, the FIT types uint8, sint8, uint16, etc. are all presented as an IntValue
. FIT strings (ie. character arrays) are presented as singleton TextValue
s. If you need to know the specific base type of a field you can use the Raw API.
data ArrayValue Source
Array values. Like singleton values these ignore the specific FIT base type to present a simpler interface. Byte arrays are presented as strict ByteString
s. There are no character arrays, since the singleton TextValue
handles that case.
Lenses for the Messages API
messages :: Applicative f => (Message -> f Message) -> Messages -> f Messages Source
Traverse all the messages in a Messages
messages :: Traversal' Messages Message
message :: (Contravariant f, Applicative f) => Int -> (Message -> f Message) -> Messages -> f Messages Source
A Fold over the messages with the given message number
message :: Int -> Fold Messages Message
messageNumber :: Functor f => (Int -> f Int) -> Message -> f Message Source
Lens on the message number from a Message
messageNumber :: Lens' Message Int
fields :: Applicative f => (Field -> f Field) -> Message -> f Message Source
Traverse all the fields in a Message
fields :: Traversal' Message Field
field :: (Contravariant f, Applicative f) => Int -> (Field -> f Field) -> Message -> f Message Source
A Fold over the fields in a Message
with the given field number
field :: Int -> Fold Message Field
fieldNumber :: Functor f => (Int -> f Int) -> Field -> f Field Source
Lens on the field number from a Field
fieldNumber :: Lens Field Int
fieldValue :: Functor f => (Value -> f Value) -> Field -> f Field Source
Lens on the Value
from a Field
fieldValue :: Lens Field Value
int :: Applicative f => (Int -> f Int) -> Field -> f Field Source
Traverse the Singleton
and IntValue
constructors for a field value
int :: Traversal' Field Int
real :: Applicative f => (Double -> f Double) -> Field -> f Field Source
Traverse the Singleton
and RealValue
constructors for a field value
real :: Traversal' Field Double
text :: Applicative f => (Text -> f Text) -> Field -> f Field Source
Traverse the Singleton
and TextValue
constructors for a field value
text :: Traversal' Field Text
byte :: Applicative f => (Word8 -> f Word8) -> Field -> f Field Source
Traverse the Singleton
and ByteValue
constructors for a field value
byte :: Traversal' Field Word8
ints :: Applicative f => (Seq Int -> f (Seq Int)) -> Field -> f Field Source
Traverse the Array
and IntArray
constructors for a field value
ints :: Traversal' Field (Seq Int)
reals :: Applicative f => (Seq Double -> f (Seq Double)) -> Field -> f Field Source
Traverse the Array
and RealArray
constructors for a field value
reals :: Traversal' Field (Seq Double)
bytestring :: Applicative f => (ByteString -> f ByteString) -> Field -> f Field Source
Travese the Array
and ByteArray
constructors for a field value
bytestring :: Traversal' Field ByteString