From bf2722034f0ae8ddc2277894542b8d6eb3b90527 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 15 Jul 2025 13:48:04 +0100 Subject: add req-030 --- requirements/catalogue/req-030.md | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 requirements/catalogue/req-030.md (limited to 'requirements/catalogue/req-030.md') 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, `:`, 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 -- cgit v1.2.3 From af7920c8e9405ea0e7591907555edad3a19688c8 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 15 Jul 2025 14:06:41 +0100 Subject: edit req-030 --- requirements/catalogue/req-030.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'requirements/catalogue/req-030.md') diff --git a/requirements/catalogue/req-030.md b/requirements/catalogue/req-030.md index 38961be..09286df 100644 --- a/requirements/catalogue/req-030.md +++ b/requirements/catalogue/req-030.md @@ -38,7 +38,7 @@ Inputs: 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_2.timestamp >= transaction.timestamp` and `transaction.bucket_id = bucket.id`, then return FALSE. 11. Return TRUE. -- cgit v1.2.3 From ea21b9246ca930c88b9092156767b437447b8280 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 15 Jul 2025 14:36:26 +0100 Subject: edit req-030 --- requirements/catalogue/req-030.md | 2 -- 1 file changed, 2 deletions(-) (limited to 'requirements/catalogue/req-030.md') diff --git a/requirements/catalogue/req-030.md b/requirements/catalogue/req-030.md index 09286df..cb27f11 100644 --- a/requirements/catalogue/req-030.md +++ b/requirements/catalogue/req-030.md @@ -43,5 +43,3 @@ Inputs: 11. Return TRUE. Source: req-029 - -Satisfied by: dml-bucket, dml-drip -- cgit v1.2.3 From ee6d4d87ffe36fe286e9976a7785a83d0d340c92 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 15 Jul 2025 14:41:01 +0100 Subject: add req-035 --- requirements/catalogue/req-030.md | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'requirements/catalogue/req-030.md') diff --git a/requirements/catalogue/req-030.md b/requirements/catalogue/req-030.md index cb27f11..2cb1bdd 100644 --- a/requirements/catalogue/req-030.md +++ b/requirements/catalogue/req-030.md @@ -12,8 +12,8 @@ Inputs: 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. +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 transactions `t` such that `t.bucket_id = bucket.id`. @@ -21,25 +21,4 @@ Inputs: 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, `:`, 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.timestamp >= transaction.timestamp` and - `transaction.bucket_id = bucket.id`, then return FALSE. -11. Return TRUE. - Source: req-029 -- cgit v1.2.3 From 519721cd14e31fcc6998b387a27eaf3ad34d2869 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 15 Jul 2025 15:09:31 +0100 Subject: add req-037 --- requirements/catalogue/req-030.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'requirements/catalogue/req-030.md') 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 -- cgit v1.2.3