habit-tracker
habit-tracker copied to clipboard
Reduce space requirements for the entries property
I've been thinking about how it'll look when you've tracked your progress for some time, with how many rows you'll get in the entries
property of a given habit. Today it occurred to me that this could be drastically used by switching the format slightly, and start using binary numbers for tracking if a habit has been done in a given month.
The gist of the idea is that you store one 32-bit number for each month you're tracking, where each bit corresponds to whether you've done it that particular day. I don't know if you know binary numbers, but the first 7 numbers are; 000 = 0, 001 = 1, 010 = 2, 011 = 3, 100 = 4, 101 = 5, 110 = 6 and 111 = 7. In our interpretation we'd store 7, aka 111, to indicate that we've done the habit the first three days of the month. If we didn't do it the second day we'd store 5, aka 101.
The actual setting/handling of the binary numbers can be easily done using bitwise operators, and this would mean that a given month could be stored in a single number. The only thing to decide then would be which of the following format would be most beneficial:
entries:
- 2024-02: 123098
- 2024-03: 65535
entries-2024-02: 123098
entries-2024-03: 65535
The main difference between these two is how they'll look natively with Obsidian:
Where the former is just going to be a data/json block, and the second variant will show the months and some seemingly random number after it.
Do this sound interesting? Do you want me to do a pull request implementing this? If so, which format would you like, and how do you suggest we tackle old data?