Logging Stats Across Sessions

So it’s been a while since I’ve made a blog post, but I’ve been working on my wordcounter/writing tracker app, and what I’ve been tooling around with recently is the question: how do I track information across sessions? By which I mean, if I run the program in Terminal once, how do I make sure that whatever information I log that time is still there the next time I run the program?

The answer on its face has been pretty simple: read and write to a CSV file. I haven’t done this in a long time, so I had to look up the methods and practice them a little bit (documentation here), but given that they have examples in the documentation, that part wasn’t so difficult. The problem was the questions this raised, which I don’t really have answers for right now.

  • When I add an update and check whether the update’s date is the same as the most recent update (ie, have I already added an update today?) do I want to:
    • log the date every time (so for three updates on the same day, 12-14-2021, 12-14-2021, 12-14-2021)?
    • log the date and the number of times that day I’ve updated (12-14-2021, 3 updates)?
    • not reflect the number of updates in a day at all (12-14-2021, no further information)?
    • (If I choose option 1, how do I efficiently turn that information into something meaningful for the user? If I choose option #2, how do I store that information neatly?)
  • Where/how do I save my writing streak and my total words counted?
    • If I save the information in my date log CSV, how do I keep this information from getting messy?
    • If I save the information in separate CSVs, how do I preserve relationships between the data?
  • How do I efficiently log and retrieve my data?
    • Do I try to record dates in reverse chronological order, most recent first (aka not what these functions are designed to do)? If so, how do I retrieve only the first row?
    • If I go with the flow and record dates in chronological order, appending the newest date to the bottom, is it possible to retrieve only the most recent row, or do I have to read through the entire file?

I’m pretty sure the answers to at least some of these questions can be solved with some careful Googling, but I’m a little worried that one or more of them may be “Go learn SQL, you doof”. Which is definitely possible. It’s just a pain.

And eventually, the looming/haunting question: how am I supposed to turn this into a web app? But that’s way too big to tackle for now, so we’ll build that bridge when we get to it.

[Super secret end-of-post sidebar: should I have a Git repository that I push to? Should I be pushing alongside every blog post? Would that be elegant/thoughtful/informative? So many questions today.]

Leave a Reply

Your email address will not be published.