| Copyright | (c) Target RWE 2023 |
|---|---|
| License | BSD3 |
| Maintainer | bbrown@targetrwe.com ljackman@targetrwe.com dpritchard@targetrwe.com |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
EventDataTheory.Core
Contents
Description
Events may be represented in different structures for transferring or storing data, for example. The To/FromJSON instances for types defined in this module are derived generically. These can be useful for writing tests, for example, but they are not designed to encode/decode data in the new line delimited format defined in the event data model docs See the neighboring EventLine module for types and To/FromJSON instances designed for the purpose of marshaling data from JSON lines.
Synopsis
- data Event t m a
- event :: Interval a -> Context t m -> Event t m a
- getEvent :: Event t m a -> PairedInterval (Context t m) a
- getContext :: Event t m a -> Context t m
- data Source = MkSource {}
- data Tag t
- data TagSet t
- data Context t m
- type TagSetInterval t a = PairedInterval (TagSet t) a
- $sel:getFacts:MkContext :: Context t m -> m
- $sel:getSource:MkContext :: Context t m -> Maybe Source
- $sel:getTagSet:MkContext :: Context t m -> TagSet t
- context :: TagSet t -> d -> Maybe Source -> Context t d
- toTagSet :: Ord t => Set (Tag t) -> TagSet t
- packTag :: t -> Tag t
- unpackTag :: Tag t -> t
- packTagSet :: Ord t => [t] -> TagSet t
- unpackTagSet :: Ord t => TagSet t -> [t]
- hasTag :: HasTag a t => a -> t -> Bool
- hasAnyTag :: HasTag a t => a -> [t] -> Bool
- hasAllTags :: HasTag a t => a -> [t] -> Bool
- addTagSet :: Ord t => [t] -> TagSet t -> TagSet t
- liftToEventPredicate :: EventPredicate element t m a => Predicate element -> Predicate (Event t m a)
- liftToEventFunction :: (EventFunction f t t' m m' a a', Ord t, Ord t') => f -> Event t m a -> Event t' m' a'
- liftToContextFunction :: (ContextFunction f t t' m m', Ord t, Ord t') => f -> Context t m -> Context t' m'
- bimapContext :: Ord t2 => (t1 -> t2) -> (d1 -> d2) -> Context t1 d1 -> Context t2 d2
- mapTagSet :: Ord t2 => (t1 -> t2) -> TagSet t1 -> TagSet t2
- dropSource :: Context t m -> Context t m
- type SubjectID = Text
- class HasTag a t
- class EventPredicate element t m a
- type Eventable t m a = (Eq m, Ord t, Ord a, Show m, Show t, Show a)
- type FromJSONEvent t m a = (FromJSON m, FromJSON t, FromJSON a)
- type ToJSONEvent t m a = (ToJSON m, ToJSON t, ToJSON a)
Documentation
The Event type puts a certain amount of structure on
temporally organized data,
while being flexible in the details.
An 'Event t m a' contains information about
when something occurred (the 'Interval a')
and what occurred (the 'Context m t').
The type parameters m, t, and a allow to specify
the types for the Contexts model and tagSet
and for the type of the Interval end points.
The Event type parameters are ordered from changing the least often to most often.
A model tends to be shared across projects.
For example, multiple projects use data from insurance claims,
and thus share a single model.
A project often defines its own tagSet,
though tag sets can be shared across projects.
Within a project, multiple Interval types may used.
Data may be imported as 'Interval Day',
but then modified to 'Interval Integer' based on some reference point.
The contents of a Context are explained in a separate section,
but we give a couple examples of using events here.
The event function is a smart constructor for Event.
>>>:set -XOverloadedStrings>>>import IntervalAlgebra ( beginerval )
>>>data SomeModel = A | B deriving (Eq, Ord, Show, Generic)>>>>>>type MyEvent = Event T.Text SomeModel Integer>>>let myEvent = event (beginerval 5 0) (context (packTagSet ["foo"]) A Nothing) :: MyEvent>>>show myEvent"MkEvent {(0, 5), MkContext {getTagSet = MkTagSet (fromList [MkTag \"foo\"]), getFacts = A, getSource = Nothing}}"
>>>hasAnyTag myEvent (["foo", "duck"] :: [T.Text])True
>>>hasAllTags myEvent (["foo", "duck"] :: [T.Text])False
>>>data NewModel = A T.Text | B Integer deriving (Eq, Ord, Show, Generic)>>>data MyTagSet = Foo | Bar | Baz deriving (Eq, Ord, Show, Generic)>>>>>>type NewEvent = Event MyTagSet NewModel Integer>>>let newEvent = event (beginerval 5 0) (context (packTagSet [Foo, Bar]) (A "cool") Nothing) :: NewEvent>>>show newEvent"MkEvent {(0, 5), MkContext {getTagSet = MkTagSet (fromList [MkTag Foo,MkTag Bar]), getFacts = A \"cool\", getSource = Nothing}}"
>>>hasTag newEvent FooTrue
>>>hasTag newEvent BazFalse
Instances
| Intervallic (Event t m) Source # | |
Defined in EventDataTheory.Core Methods getInterval :: Event t m a -> Interval a setInterval :: Event t m a -> Interval b -> Event t m b | |
| (SizedIv (Interval a), Eventable t m a) => TryFrom (EventLine t m a, ParseEventLineOption) (Event t m a) | Try to parse an |
Defined in EventDataTheory.EventLines Methods tryFrom :: (EventLine t m a, ParseEventLineOption) -> Either (TryFromException (EventLine t m a, ParseEventLineOption) (Event t m a)) (Event t m a) | |
| (Ord t, Arbitrary m, Arbitrary t, Arbitrary (Interval a)) => Arbitrary (Event t m a) Source # | |
| (Ord t, FromJSON t, FromJSON m, FromJSON a) => FromJSON (Event t m a) Source # | |
Defined in EventDataTheory.Core | |
| (Ord t, ToJSON t, ToJSON m, ToJSON a) => ToJSON (Event t m a) Source # | |
Defined in EventDataTheory.Core Methods toJSON :: Event t m a -> Value toEncoding :: Event t m a -> Encoding toJSONList :: [Event t m a] -> Value toEncodingList :: [Event t m a] -> Encoding | |
| Generic (Event t m a) Source # | |
| (Show t, Show m, Show a, Ord a) => Show (Event t m a) Source # | |
| (Binary m, Binary t, Binary a) => Binary (Event t m a) Source # | |
| (NFData a, NFData m, NFData t) => NFData (Event t m a) Source # | |
Defined in EventDataTheory.Core | |
| (Eq a, Eq t, Eq m) => Eq (Event t m a) Source # | |
| (Ord a, Ord t, Eq m) => Ord (Event t m a) Source # | |
Defined in EventDataTheory.Core | |
| Ord t => HasTag (Event t m a) t Source # | |
| From (Event t m a) (Interval a) Source # | |
Defined in EventDataTheory.Core | |
| From (Event t m a) (TagSetInterval t a) Source # | |
Defined in EventDataTheory.Core Methods from :: Event t m a -> TagSetInterval t a | |
| type Rep (Event t m a) Source # | |
Defined in EventDataTheory.Core | |
getEvent :: Event t m a -> PairedInterval (Context t m) a Source #
Unpack an Event from its constructor.
A Source may be used to record the source of an event from a database.
This data is sometimes useful for debugging.
We generally discourage using Source information in defining features.
Constructors
| MkSource | |
Instances
A Tag is simply a label for an Event.
Instances
| Functor Tag Source # | |
| From t (Tag t) Source # | |
Defined in EventDataTheory.Core | |
| FromJSON t => FromJSON (Tag t) Source # | |
Defined in EventDataTheory.Core | |
| ToJSON t => ToJSON (Tag t) Source # | |
Defined in EventDataTheory.Core Methods toEncoding :: Tag t -> Encoding toJSONList :: [Tag t] -> Value toEncodingList :: [Tag t] -> Encoding | |
| Generic (Tag t) Source # | |
| Show t => Show (Tag t) Source # | |
| Binary t => Binary (Tag t) Source # | |
| NFData t => NFData (Tag t) Source # | |
Defined in EventDataTheory.Core | |
| FromDhall t => FromDhall (Tag t) Source # | |
Defined in EventDataTheory.Core | |
| ToDhall t => ToDhall (Tag t) Source # | |
Defined in EventDataTheory.Core Methods injectWith :: InputNormalizer -> Encoder (Tag t) | |
| Eq t => Eq (Tag t) Source # | |
| Ord t => Ord (Tag t) Source # | |
| From (Tag t) t Source # | |
Defined in EventDataTheory.Core | |
| Ord t => From (Set (Tag t)) (TagSet t) Source # | |
Defined in EventDataTheory.Core | |
| Ord t => From (Set (Tag t)) [t] Source # | |
Defined in EventDataTheory.Core | |
| Ord t => From (TagSet t) (Set (Tag t)) Source # | |
Defined in EventDataTheory.Core | |
| Ord t => From [t] (Set (Tag t)) Source # | |
Defined in EventDataTheory.Core | |
| type Rep (Tag t) Source # | |
Defined in EventDataTheory.Core | |
Instances
| (Arbitrary t, Ord t) => Arbitrary (TagSet t) Source # | |
| (Ord t, FromJSON t) => FromJSON (TagSet t) Source # | |
Defined in EventDataTheory.Core | |
| ToJSON t => ToJSON (TagSet t) Source # | |
Defined in EventDataTheory.Core Methods toEncoding :: TagSet t -> Encoding toJSONList :: [TagSet t] -> Value toEncodingList :: [TagSet t] -> Encoding | |
| Ord t => Monoid (TagSet t) Source # | |
| Ord t => Semigroup (TagSet t) Source # | |
| Generic (TagSet t) Source # | |
| Show t => Show (TagSet t) Source # | |
| Binary t => Binary (TagSet t) Source # | |
| NFData t => NFData (TagSet t) Source # | |
Defined in EventDataTheory.Core | |
| (FromDhall t, Ord t, Show t) => FromDhall (TagSet t) Source # | |
Defined in EventDataTheory.Core | |
| ToDhall t => ToDhall (TagSet t) Source # | |
Defined in EventDataTheory.Core Methods injectWith :: InputNormalizer -> Encoder (TagSet t) | |
| Eq t => Eq (TagSet t) Source # | |
| Ord t => Ord (TagSet t) Source # | |
Defined in EventDataTheory.Core | |
| Ord t => HasTag (TagSet t) t Source # | |
| EventPredicate (TagSet t) t m a Source # | |
Defined in EventDataTheory.Core | |
| Ord t => From (Set (Tag t)) (TagSet t) Source # | |
Defined in EventDataTheory.Core | |
| Ord t => From (TagSet t) (Set (Tag t)) Source # | |
Defined in EventDataTheory.Core | |
| Ord t => From (TagSet t) [t] Source # | |
Defined in EventDataTheory.Core | |
| Ord t => From [t] (TagSet t) Source # | |
Defined in EventDataTheory.Core | |
| (Ord t, Ord t) => From (Interval a) (TagSetInterval t a) Source # | Creates a |
Defined in EventDataTheory.Core Methods from :: Interval a -> TagSetInterval t a | |
| Ord t => HasTag (PairedInterval (TagSet t) a) t Source # | |
| Ord a => From (TagSetInterval t a) (Interval a) Source # | |
Defined in EventDataTheory.Core Methods from :: TagSetInterval t a -> Interval a | |
| From (Event t m a) (TagSetInterval t a) Source # | |
Defined in EventDataTheory.Core Methods from :: Event t m a -> TagSetInterval t a | |
| type Rep (TagSet t) Source # | |
Defined in EventDataTheory.Core | |
A Context contains information about what ocurred during an Events interval.
This information is carried in context's tagSet and/or facts.
TagSet are set of tags that can be used to identify and filter events
using the hasTag function
or the related hasAnyTag and hasAllTags functions.
The facts field contains data of type m.
The m stands for model,
meaning the scope and shape of facts
relevant to a particular scientific line of work.
For example, some studies using health care claims data may be sufficiently different
in scope, semanitcs, and aims to warrant having a different collection of facts
from, say, electronic medical records data.
However, one could create a collection of facts that includes both claims and EHR data.
By having a Context parametrized by the shape of a model,
users are free to define the structure of their facts as needed.
A context also has a source field,
possibly containing a Source,
which carries information about the provenance of the data.
Instances
type TagSetInterval t a = PairedInterval (TagSet t) a Source #
A Tag Interval is simply a synonym for an Interval paired with TagSet.
$sel:getFacts:MkContext :: Context t m -> m Source #
the facts of a Context.
packTagSet :: Ord t => [t] -> TagSet t Source #
Put a list of values into a set of tagSet.
unpackTagSet :: Ord t => TagSet t -> [t] Source #
Take a tag set to a list of values.
addTagSet :: Ord t => [t] -> TagSet t -> TagSet t Source #
A utility for adding tag sets to a TagSet from a list.
liftToEventPredicate :: EventPredicate element t m a => Predicate element -> Predicate (Event t m a) Source #
liftToEventFunction :: (EventFunction f t t' m m' a a', Ord t, Ord t') => f -> Event t m a -> Event t' m' a' Source #
liftToContextFunction :: (ContextFunction f t t' m m', Ord t, Ord t') => f -> Context t m -> Context t' m' Source #
The HasTag typeclass provides predicate functions
for determining whether an a contains a tag.
This class is only used in this Core module
for the purposes of having a single hasTag function
that works on TagSet, Context, or Event data.
Minimal complete definition
class EventPredicate element t m a Source #
Provides a common interface to lift a to a
Predicate ePredicate (Event t m a).
For example, if x is a Predicate on some 'Context m t',
liftToEventPredicate x yields a Predicate (Event t m a),
thus the predicate then also be applied to Events.
This class is only used in this Core module
for the purposes of having a single liftToEventPredicate function
that works on TagSet, Context, or Event data.
Minimal complete definition
Instances
| EventPredicate m t m a Source # | |
Defined in EventDataTheory.Core | |
| EventPredicate (TagSet t) t m a Source # | |
Defined in EventDataTheory.Core | |
| EventPredicate (Interval a) t m a Source # | |
Defined in EventDataTheory.Core | |
| EventPredicate (Maybe Source) t m a Source # | |
Defined in EventDataTheory.Core | |
| EventPredicate (Context t m) t m a Source # | |
Defined in EventDataTheory.Core | |
type Eventable t m a = (Eq m, Ord t, Ord a, Show m, Show t, Show a) Source #
A synonym for a basic set of constraints frequently used with
the Event type.
type FromJSONEvent t m a = (FromJSON m, FromJSON t, FromJSON a) Source #
Constraint synonym for FromSON on an event's component types.
type ToJSONEvent t m a = (ToJSON m, ToJSON t, ToJSON a) Source #
Constraint synonym for ToJSON on an event's component types.
Orphan instances
| FromJSON a => FromJSON (Interval a) Source # | |
| ToJSON a => ToJSON (Interval a) Source # | |
Methods toJSON :: Interval a -> Value toEncoding :: Interval a -> Encoding toJSONList :: [Interval a] -> Value toEncodingList :: [Interval a] -> Encoding | |
| (FromJSON b, FromJSON a) => FromJSON (PairedInterval b a) Source # | |
Methods parseJSON :: Value -> Parser (PairedInterval b a) parseJSONList :: Value -> Parser [PairedInterval b a] | |
| (ToJSON b, ToJSON a) => ToJSON (PairedInterval b a) Source # | |
Methods toJSON :: PairedInterval b a -> Value toEncoding :: PairedInterval b a -> Encoding toJSONList :: [PairedInterval b a] -> Value toEncodingList :: [PairedInterval b a] -> Encoding | |