heikkilevanto / beertracker

Simple script to track the beers I drink
GNU General Public License v2.0
2 stars 1 forks source link

Day sum is wrong when back dating #270

Closed schafdog closed 6 months ago

schafdog commented 6 months ago

Added some beer from friday today. Changed the dates to friday They are shown correctly in the graph but is added today's daysum.

I think the open issue to use a hash will fix the sum.

They are also still shown after Saturday, I guess in the order that they were added to the file.

schafdog commented 6 months ago

https://github.com/heikkilevanto/beertracker/issues/142

schafdog commented 6 months ago

Perhaps an option to sort the file by date. That would fix both issues.

heikkilevanto commented 6 months ago

Yes, I see the problem. The code always just appends new lines to the file.

I did sort your data file manually. Seems to have fixed the current issue. I was afraid that it would mess with commented-out lines, but those seem to be in the right place anyway. Not quite sure how unix sort figured that out.

A better would be to change the logic that edits a line, make sure it writes the new line in its proper place.

heikkilevanto commented 6 months ago

At least a partial fix: When editing a record, it is now placed in the right spot in the file.

New records are still appended to the file, so it is possible to get data out of order. But editing such a line should fix it. I don't think I want to rewrite the whole data file on every insert, most of the time appending is just fine.

heikkilevanto commented 6 months ago

Now checking the time stamp of any new record, and if that is before the last seen time stamp, do the inserting update instead of appending. Now it should not be possible to get data out of order.