# req-037 Schist must implement the procedure, described below as `update_budget_drips_for_bucket`. Sources: req-030, req-097 Satisfied by: task-001, task-006, task-054, req-117 ## update_budget_drips_for_bucket Inputs: - A bucket, `bucket` 1. Let `prev_drip` be a drip `d` with a most recent value for the property `date` such that `d.bucket_id = bucket.id` 2. For each calendar date `d` in the range `(prev_drip.date, today]`, let `pipe` be the result of `get_current_pipe_for_bucket_on_date(bucket, d)` as described in req-117, and insert a new drip with these properties: - `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`.