accotron devlog for 2022W49
Journal annotations
Kicking off this week with a fun side note:
I realised that the journal_number
field (e.g. for Journal #2110, 2110 is the journal_number
) is stored a string, and when I sorted the list on this field the #2110 entry would come before #5, in turn, what I initially thought was an algorithmic error that failed for journal trails that end with a deletion, was just a sorting problem. Quick fix.
Another fix was the sorting for the journals and interleaving them with the notes on the underlying resource (such as log messages indicating that a document was edited at one point, or a comment added to point out a file attachment). Journals can occasionally have different ordering based on their number and their creation date. For example, journal #3 can in fact have an earlier creation date than #2, and this is seemingly the normal case anyway! So, when I sort the chained iterators for journals and history entries on their creation dates, the sorting fails and journal #3 appears before #2.
Because I created the report, I know of this annoying problem, but I also know that it can be done better and how annoying it is when it isn’t done better.
So, I used the functools.cmp_to_key
method to add a custom comparator which behaves differently and sorts on journal_number
when it’s comparing two journals, and creation date otherwise. Much cleaner, and easier to understand!