diff options
| author | Joe Carstairs <jcarstairs@scottlogic.com> | 2025-07-15 13:48:04 +0100 |
|---|---|---|
| committer | Joe Carstairs <jcarstairs@scottlogic.com> | 2025-07-15 13:48:04 +0100 |
| commit | bf2722034f0ae8ddc2277894542b8d6eb3b90527 (patch) | |
| tree | d3866f7237b19b6422ea780cf43a1d589a5dd03f | |
| parent | 8ce1d909ad205d7f212a66b180d054bcc21e5038 (diff) | |
add req-030
| -rw-r--r-- | requirements/catalogue/req-030.md | 47 | ||||
| -rw-r--r-- | requirements/data_models/dml-bucket.md | 20 | ||||
| -rw-r--r-- | requirements/data_models/dml-drip.md | 14 |
3 files changed, 75 insertions, 6 deletions
diff --git a/requirements/catalogue/req-030.md b/requirements/catalogue/req-030.md new file mode 100644 index 0000000..38961be --- /dev/null +++ b/requirements/catalogue/req-030.md @@ -0,0 +1,47 @@ +# req-030 + +Schist must implement the procedure described below as `calculate_bucket_balance`. + +## calculate_bucket_balance + +Inputs: + +- A bucket name, `name` + +1. If no bucket exists with the name, `name`, then return empty. +2. If more than one bucket exists with the name, `name`, then panic. +3. Let `bucket` be the bucket with the given name. +4. Let `cache_key = bucket.balance_cache_key`. +5. Let `is_up_to_date` be the result of the sub-procedure, + `is_bucket_balance_up_to_date(bucket)`, as described below. +6. If `is_up_to_date = TRUE`, then return `bucket.balance`. +7. 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 + that `d.bucket_id = bucket.id`. +9. Return `drip_sum - transaction_sum`. + +## is_bucket_balance_up_to_date + +Inputs: + +- A bucket, `bucket` + +1. Let `cache_key = bucket.balance_cache_key`. +2. If `cache_key` is not in the format, `<string>:<string>`, then return FALSE. +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. +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`. +10. If there is a transaction, `transaction_2`, such that + `transaction_2.date > transaction.date` and + `transaction.bucket_id = bucket.id`, then return FALSE. +11. Return TRUE. + +Source: req-029 + +Satisfied by: dml-bucket, dml-drip diff --git a/requirements/data_models/dml-bucket.md b/requirements/data_models/dml-bucket.md index 0a7960a..3e33028 100644 --- a/requirements/data_models/dml-bucket.md +++ b/requirements/data_models/dml-bucket.md @@ -2,10 +2,18 @@ A bucket represents a real category of spending, like beer or holidays. -| Field | Type | Description | -| ------- | ------ | ----------------------------------------------------- | -| id | string | | -| name | string | A short description of the real category of spending. | -| balance | number | The amount of money currently in the bucket. | +| Field | Type | Description | +| ----------------- | ------ | ----------------------------------------------------- | +| name | string | A short description of the real category of spending. | +| balance | number | The amount of money currently in the bucket. | +| balance_cache_key | string | A cache key for the balance. See notes. | -Sources: req-027, req-028 +Constraints: + +- `name` must be unique. + +Notes: + +- `balance_cache_key` must be of the format: `<drip_id>:<transaction_id>`. + +Sources: req-027, req-028, req-030 diff --git a/requirements/data_models/dml-drip.md b/requirements/data_models/dml-drip.md new file mode 100644 index 0000000..a421180 --- /dev/null +++ b/requirements/data_models/dml-drip.md @@ -0,0 +1,14 @@ +# dml-drip + +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. | + +Sources: req-030 |
