
Crux Neptune Assignment: Bitemporality

Introduction
This is the bitemporal installment of the Crux "choose your own adventure" tutorial series.
We shall assume you have a Crux standalone node set up locally and are now comfortable with put
operations and basic datalog queries.
If this is not the case, you can find all you need to know on Earth, Pluto and Mercury. Click on a destination above to take you there.
Arrival on Neptune
You enter the Neptunian atmosphere and your communications panel lights up.
It is our honor to welcome you to the planet Neptune.
If you are visiting for business reasons, please present your manifest.
Otherwise, have your visa ready for inspection.
The government is asking to see your flight manifest.
Space Port
On your way down to the landing site you take the time to read the Crux manual.
One or more documents can be inserted into Crux via a
put
transaction at a specificvalid-time
. Thevalid-time
can be any time (past, future or present).If no
valid-time
is provided, Crux will default to the transaction time, i.e. the present. Each document survives until it is deleted or a new version of it is added.
Read More
Assignment
Upon landing on the ice giant, your communications panel lights up indicating that the job ticket is available.
Task |
|
Company |
|
Contact |
|
Submitted |
|
Additional information |
|
Attachments |
— |
Outside your ship you are met by a panicked looking Lyndon.
Thank goodness you’re here.
We need you to show us how to put our customers information into Crux in order of time. Working with insurance claims, we should be able to easily look back in time at what type of coverage the customer had at the time of the incident.
Are you able to help us?
Coast Insurance
Choose your path
"Yes I’ll give it a go." | "I’m not sure how to even begin." |
---|

Lyndon gives you some data for a client that you can use as an example. Coast Insurance need to know what kind of cover each customer has and if it was valid at a given time.
You show them how to ingest a document using a valid-time
so that the information is backdated to when the customer took the cover out.
(crux/submit-tx
node
[[:crux.tx/put
{:crux.db/id :consumer/RJ29sUU
:consumer-id :RJ29sUU
:first-name "Jay"
:last-name "Rose"
:cover? true
:cover-type :Full}
#inst "2114-12-03"]])
;;=> #:crux.tx{:tx-id 0, :tx-time #inst "2020-06-18T14:38:29.240-00:00"}
The company needs to know the history of insurance for each cover. You show them how to use the bitemporality of Crux to do this.
(crux/submit-tx
node
[[:crux.tx/put ;; 1
{:crux.db/id :consumer/RJ29sUU
:consumer-id :RJ29sUU
:first-name "Jay"
:last-name "Rose"
:cover? true
:cover-type :Full}
#inst "2113-12-03" ;; Valid time start
#inst "2114-12-03"] ;; Valid time end
[:crux.tx/put ;; 2
{:crux.db/id :consumer/RJ29sUU
:consumer-id :RJ29sUU
:first-name "Jay"
:last-name "Rose"
:cover? true
:cover-type :Full}
#inst "2112-12-03"
#inst "2113-12-03"]
[:crux.tx/put ;; 3
{:crux.db/id :consumer/RJ29sUU
:consumer-id :RJ29sUU
:first-name "Jay"
:last-name "Rose"
:cover? false}
#inst "2112-06-03"
#inst "2112-12-02"]
[:crux.tx/put ;; 4
{:crux.db/id :consumer/RJ29sUU
:consumer-id :RJ29sUU
:first-name "Jay"
:last-name "Rose"
:cover? true
:cover-type :Promotional}
#inst "2111-06-03"
#inst "2112-06-03"]])
;;=> #:crux.tx{:tx-id 1, :tx-time #inst "2020-06-18T14:39:11.189-00:00"}
-
This is the insurance that the customer had last year. Along with the start
valid-time
you use an endvalid-time
so as not to affect the most recent version of the document. -
This is the previous insurance plan. Again, you use a start and end
valid-time
. -
There was a period when the customer was not covered,
-
and before that the customer was on a promotional plan.
Queries through time
You now show them a few queries.
You know that you can query Crux as of a given valid-time
.
This shows the state of Crux at that time.
First you pick a date that the customer had full cover:
(crux/q (crux/db node #inst "2114-01-01")
'{:find [cover type]
:where [[e :consumer-id :RJ29sUU]
[e :cover? cover]
[e :cover-type type]]})
;;=> #{[true :Full]}
Next you show them a query for a the customer in a time when they had a different type of cover:
(crux/q (crux/db node #inst "2111-07-03")
'{:find [cover type]
:where [[e :consumer-id :RJ29sUU]
[e :cover? cover]
[e :cover-type type]]})
;;=> #{[true :Promotional]}
And finally you show them a time when the customer had no cover at all.
(crux/q (crux/db node #inst "2112-07-03")
'{:find [cover type]
:where [[e :consumer-id :RJ29sUU]
[e :cover? cover]
[e :cover-type type]]})
;;=> #{}
Confident in their ability to put the remainder of their records into Crux, Lyndon thanks you.
I can’t believe we’ve not digitized sooner. There was a huge push to start using more paper as the Neptune tree population was getting out of control from the accelerated terraforming, but since all these floods I’m not sure paper was the right choice.
Coast Insurance
You say goodbye to Lyndon and head back to the space port.
Space Port
Back at your spaceship you check your communications panel. There is a new assignment waiting for you.
We have assigned you a quick task on Saturn helping a small company who are having some problems keeping their records in order.
This shouldn’t take long, but don’t forget they will still need to see your manifest.
Update Manifest
You add the new badge to your manifest
(crux/submit-tx
node [[:crux.tx/put
(assoc manifest
:badges ["SETUP" "PUT" "DATALOG-QUERIES" "BITEMP"])]])
;;=> #:crux.tx{:tx-id 2, :tx-time #inst "2020-06-18T14:46:47.606-00:00"}
Enter countdown for lift off, destination: Saturn. See you soon.
Click on Saturn to take you to your next assignment.