fact-models User Guide
Getting Started
Nix Setup
To develop within event-data-model,
and to use the fact-models tool
we recommend using a development shell defined in flake.nix
.
This guarantees applications are
pinned to the same version as other developers and the CI.
For instructions on installing nix
, see
the nsBuild setup instructions.
For information on nix usage, see the nsBuild usage guide.
TODO add haskell, rust and dhall setup
Instructions
How to create a new Fact
Instructions for creating a new fact are below.
Each new Fact
will need to be hooked up to a new or existing Model
.
See the instructions for creating a new model for more details.
Please note that the subject identifier,
and begin and end dates for an event are not defined in the Fact
.
That information is defined in the source-to-model ETL parsers.
Adding a new Fact
-
If not previously done, pull down the event-data-model repo and create a new branch.
-
In the new branch, add a new directory for your fact in
fact-models/src/Facts
. UseCamelCase
for the fact’s name. -
In the new directory, create a file called
Fact.dhall
. -
In
Fact.dhall
define the newFact
as described in Anatomy ofFact.dhall
. -
Do a dry run of the
fact
application. In the project’s root directory, run the following command, changingNameOfFact
to the name of the new fact:cabal run fact-models:exe:fact -- build --fact=NameOfFact --dry-run
-
Review the output from the dry-run, and make changes as needed.
-
When ready, run the
fact
application. In the project’s root directory, run the following command, changingNameOfFact
to the name of the new fact:cabal run fact-models:exe:fact -- build --fact=NameOfFact
This command also creates the files derived from
Fact.dhall
such as:Fact
,Fact.dhallType
,Fact-examples.dhall
, etc. -
Add entries for the new fact in:
-
fact-models/src/Facts/package.dhall
-
fact-models/src/package.dhall
in thefact-srcs
object -
docs/modules/models/pages/facts.adoc
-
-
Update the documentation.
-
in
docs/modules/fact-models/facts.adoc
add a new entry for your fact, by copy-pasting from a previousFact
and updating the name.
-
-
Follow the directions to create a new model, to hook the new
Fact
up to aModel
. -
Create a merge request from the new branch to master and assign a member of the stats-dev-team to review.
-
This can be done at any point, and is a great way to ask questions during the process.
-
The branch should not be merged until the stats-dev-team member has approved.
-
-
Once approved, merge in the new branch.
-
Follow the directions in
asclepias
to add the newFact
andModel
to your cohort building application.
How to add a new model
Adding a model is quite similar to adding a new fact with the main differences being working within the Models directory and the creation of the model’s Haskell module in Model.hs.
-
If not previously done, pull down the event-data-model repo and create a new branch.
-
In the new branch, add a new directory for your fact in fact-models/src/Models. Use CamelCase for the model’s name.
-
In this directory, create a
Model.dhall
file in which to define your new model, as describe in anatomy of Model.dhall -
To check the new model, run the following command from the same directory as the new
Model.dhall
file.cabal run fact-models:exe:fact -- build --model=NameOfModel
This command also creates the files derived from
Model.dhall
such as:Model
,Model.dhallType
,Model-examples.dhall
, etc. -
Implement the model in Haskell.
-
Copy Model.hs from the ExampleModel directory, and paste in same directory as Model.dhall.
-
Update the new Model.hs with the specific Fact types needed for your project. See
fact-models/src/Utilties.hs
for information on the construct* and derive* functions used to create theModel
.
-
-
In the
cabal
object infact-models/src/package.dhall
, add an entry forModels.MyNewModel
in thelibrary.exposed-modules
field. -
Run
nix run .#build-fact-models-manifests
to updatefact-models.cabal
. -
Now run
cabal build fact-models
to check that the new Haskell module successfully builds. -
Add a
Tests.hs
module for the Model to add tests for the model. See an existing model’sTest.hs
file for an example. Add tests model tofact-models
test suite infact-models/src/Tests.hs
. -
Run
cabal test all --test-show-details=always
to be sure your tests run and succeed.
How to use the fact
application
The fact-models
packages provides an executable for working with fact files
within the event-data-model
directory.
The executable builds the files derived from Fact.dhall
and Model.dhall
.
The files derived from Fact.dhall
are:
-
Fact-examples.dhall
-
The examples from the fact for use in testing routines
-
-
Fact-examples.dhallb
-
An encoded version of Fact-examples.dhall
-
-
Fact-examples.json
-
The facts from the examples (deduplicated) in JSON format
-
-
Fact-example.json
-
The fact from the head example.
-
Used to present example JSON in the documentation site.
-
-
Fact.dhallType
-
The Type field from Fact.dhall .
-
Used to display the type in the documentation site.
-
-
Fact
-
A frozen version of Fact.dhall, which an be used to check the integrity of facts, as in
dhall freeze --check
.
-
The files derived from Model.dhall
are
-
Model
-
Model-example.json
-
Model-examples.dhall
-
Model-examples.dhallb
-
Model-examples.json
-
Model.dhallType
TODO describe what above files do
Instructions for how to use the fact application follow.
Building the application
There are two ways to use the application:
-
Run with
cabal run
-
This approach ensures that you’re using the latest version of the app without having to reinstall new updates.
-
Use the following command in the root directory of event-data-model to access the help menu
cabal run fact-models:exe:fact -- --help
-
You can run
build
,check
, orlist
as outlined in the help menu.
-
-
Install via cabal
-
Use the following command in the root directory of event-data-model
cabal install fact-models:exe:fact
-
This will install the application in your
$PATH
. -
Confirm this by running
fact --help
-
Usage
The application currenlty has three commmands:
-
build
: Build artifacts for fact(s) -
check
: Check that fact artifacts are up-to-date -
list
: List available facts
Commands are invoked at the command-line as in:
cabal run fact-models:exe:fact -- build --help
cabal run fact-models:exe:fact -- check --help
cabal run fact-models:exe:fact -- list --help
Examples
Dry-run build of a fact
The following command prints a preview of the files
that will be created when the --dry-run
flag is removed.
cabal run fact-models:exe:fact -- build --fact=ServiceLocation --dry-run
Check of a fact
You can check that a fact’s artifacts are up-to-date with the following:
cabal run fact-models:exe:fact -- check --fact=Claim
The command should produce no output if the files are up-to-date.