Transition smoothly when people are added and removed
We have an easy tickbox now, "active," that can be checked or unchecked for Uptwinkles people. This tickbox determines whether the person should be assigned to dinners/chores. It's good for when people go on vacation or become unable to do the chores for whatever reason.
The assignment algorithm works based off day one being January 1st, 1970, the Unix epoch. The difference between today and the epoch is then chopped up into weeks. Then, the list of people is rotated once per each week since the first one.
Thus, on Monday, 1969-12-29 (WEEK 0) we have https://api.uptwinkles.co/chore-assignments/1969-12-29/
- Alex should wash the dishes
- Mary Kate should take out the trash
- Chad should clean the kitchen
- Jacqueline should sweep the house
The following week, on Monday 1970-01-05 (WEEK 1) we have https://api.uptwinkles.co/chore-assignments/1970-01-05/
- Mary Kate should wash the dishes
- Chad should take out the trash
- Jacqueline should clean the kitchen
- Alex should sweep the house
As you can see, the people have been rotated one up. This pattern continues forever. Presently we are on week 2476, so the list of people has been rotated up 2476 times, wrapping back around each time after a full sequence.
The problem happens when someone is removed. Rather than determine the best thing to do in that moment, based on how the chores looked before the change was made, the whole thing is just recalculated from January 1st, 1970. This time there is a different number of people, so it's calculated differently.
I'm wondering if we need a manual "offset" global setting that can be changed manually, and that is automatically set when people objects are saved (and the "active" field is modified). This "offset" value could add or remove from the calculated offset. Right now the offset is only the number of weeks since 1970-01-01, but it could also add our custom offset value to that number. This way, we can take into account the position of the person being changed and adjust the offset as needed so it distributes the chores fairly as a result. But I haven't thought this completely through and am not sure if we also need a historical record to keep this fair in the long term.
First we should probably write out test cases for how the chores should look after people are added/removed. Eg,
Say we have:
- Mary Kate should wash the dishes
- Chad should take out the trash
- Jacqueline should clean the kitchen
- Alex should sweep the house
And then "Alex" gets removed. What should the next week look like?