summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Carstairs <jcarstairs@scottlogic.com>2025-07-15 15:09:31 +0100
committerJoe Carstairs <jcarstairs@scottlogic.com>2025-07-15 15:10:04 +0100
commit519721cd14e31fcc6998b387a27eaf3ad34d2869 (patch)
treeb47613ceced8be37c466d68a355d7eeae35b48c1
parent136650f884576da871e48f6c1b2a927edea636d1 (diff)
add req-037
-rw-r--r--requirements/catalogue/req-030.md8
-rw-r--r--requirements/catalogue/req-035.md4
-rw-r--r--requirements/catalogue/req-037.md48
-rw-r--r--requirements/data_models/dml-drip.md17
-rw-r--r--requirements/data_models/dml-pipe.md10
5 files changed, 73 insertions, 14 deletions
diff --git a/requirements/catalogue/req-030.md b/requirements/catalogue/req-030.md
index 2cb1bdd..e09a281 100644
--- a/requirements/catalogue/req-030.md
+++ b/requirements/catalogue/req-030.md
@@ -15,10 +15,12 @@ Inputs:
5. Let `is_up_to_date` be the result of the procedure,
`is_bucket_balance_up_to_date(bucket)`, as described in req-035.
6. If `is_up_to_date = TRUE`, then return `bucket.balance`.
-7. Let `transaction_sum` be the sum over the property, `amount`, of all
+7. Carry out the procedure, `update_bucket_drips(bucket)`, as described in
+ req-037.
+8. Let `transaction_sum` be the sum over the property, `amount`, of all
transactions `t` such that `t.bucket_id = bucket.id`.
-8. Let `drip_sum` be the sum over the property, `amount`, of all drips `d` such
+9. Let `drip_sum` be the sum over the property, `amount`, of all drips `d` such
that `d.bucket_id = bucket.id`.
-9. Return `drip_sum - transaction_sum`.
+10. Return `drip_sum - transaction_sum`.
Source: req-029
diff --git a/requirements/catalogue/req-035.md b/requirements/catalogue/req-035.md
index 0dc9aaf..15b797b 100644
--- a/requirements/catalogue/req-035.md
+++ b/requirements/catalogue/req-035.md
@@ -14,8 +14,8 @@ Inputs:
3. Let `drip_id` be the part of `cache_key` before the `:`.
4. If there is no drip with the ID, `drip_id`, then return FALSE.
5. Let `drip` be the drip with the ID, `drip_id`.
-6. If there is a drip, `drip_2`, such that `drip_2.date > drip.date` and
- `drip.bucket_id = bucket.id`, then return FALSE.
+6. If there is a drip, `drip_2`, such that `drip_2.timestamp > drip.timestamp`
+ and `drip.bucket_id = bucket.id`, then return FALSE.
7. Let `transaction_id` be the part of `cache_key` after the `:`.
8. If there is no transaction with the ID, `transaction_id`, then return FALSE.
9. Let `transaction` be the transaction with the ID, `transaction_id`.
diff --git a/requirements/catalogue/req-037.md b/requirements/catalogue/req-037.md
new file mode 100644
index 0000000..0d27984
--- /dev/null
+++ b/requirements/catalogue/req-037.md
@@ -0,0 +1,48 @@
+# req-037
+
+Schist must implement the procedure, described below as
+`update_budget_drips_for_bucket`.
+
+## update_budget_drips_for_bucket
+
+Inputs:
+
+- A bucket, `bucket`
+
+1. For each pipe `p` such that `p.bucket_id = bucket.id`, carry out the
+ sub-procedure, `update_budget_drips_for_pipe(pipe)`, as described below.
+
+## update_budget_drips_for_pipe
+
+Inputs:
+
+- A pipe, `pipe`
+
+1. Let `prev_drip` be a drip `d` with a most recent value for the property
+ `date` such that `d.pipe_id = pipe.id`
+2. For each calendar date `d` in the range `(prev_drip.date, today]`, insert
+ a new drip for `pipe`:
+ - `bucket_id`: `pipe.bucket_id`
+ - `pipe_id`: `pipe.id`
+ - `date`: `d`
+ - `amount`: the result of the sub-procedure, `pipe_amount_for_day(pipe, d)`
+ as described below
+ - `timestamp`: now as a Unix timestamp
+
+## pipe_amount_for_date
+
+Inputs:
+
+- A pipe, `pipe`
+- A calendar date, `date`
+
+1. If `pipe.period` is `day`, return `pipe.amount`.
+2. If `pipe.period` is `week`, return `pipe.amount ÷ 7`.
+3. Let `days_in_month` be the number of days in the month to which `date`
+ belongs.
+4. If `pipe.period` is `month`, return `pipe.amount ÷ days_in_month`.
+5. Let `days_in_year` be the number of days in the year to which `date` belongs.
+6. If `period` is not `year`, panic.
+7. Return `pipe.amount ÷ days_in_year`.
+
+Source: req-030 \ No newline at end of file
diff --git a/requirements/data_models/dml-drip.md b/requirements/data_models/dml-drip.md
index a421180..127c73e 100644
--- a/requirements/data_models/dml-drip.md
+++ b/requirements/data_models/dml-drip.md
@@ -3,12 +3,13 @@
A drip represents a single daily transaction from the tank into a bucket as a
result of a pipe.
-| Field | Type | Description |
-| --------- | ------ | --------------------------------------------------- |
-| id | string | A unique ID. |
-| bucket_id | string | The ID of the bucket into which this drip drap. |
-| pipe_id | string | The ID of the pipe which from which this drip drap. |
-| date | date | The date on which this drip drap. |
-| amount | number | The amount of money which dripped. |
+| Field | Type | Description |
+| --------- | ------ | ------------------------------------------------------------- |
+| id | string | A unique ID. |
+| bucket_id | string | The ID of the bucket into which this drip drap. |
+| pipe_id | string | The ID of the pipe which from which this drip drap. |
+| date | date | The date on which this drip drap. |
+| amount | number | The amount of money which dripped. |
+| timestamp | number | The time on which this drip was inserted as a Unix timestamp. |
-Sources: req-030
+Sources: req-030, req-037
diff --git a/requirements/data_models/dml-pipe.md b/requirements/data_models/dml-pipe.md
index a701ea3..d889b0a 100644
--- a/requirements/data_models/dml-pipe.md
+++ b/requirements/data_models/dml-pipe.md
@@ -10,4 +10,12 @@ bucket. In other words, it represents a flow of money from the tank to a bucket.
| period | string | How long it takes for `amount` to flow through the pipe. |
| bucket_id | string | The ID of the bucket to which this pipe corresponds. |
-Source: req-017
+Constraints:
+
+- `period` must be one of these options:
+ - `day`
+ - `week`
+ - `month`
+ - `year`
+
+Sources: req-017, req-037