Tag: wordcounter project

  • Reclaim Cloud & Troubleshooting Dates

    I actually did this work on Friday, but I didn’t have the opportunity to write it up – just took a couple of notes so I could put this out today.

    As of Friday, I’ve figured out, at least for now, how I want to store and retrieve dates. When I retrieve dates, I want them to be reverse chronological, so the most recent date can be accessed easily. For now, that means that my retrieval function reads the CSV where the dates are stored into a list, then reverses the list & returns it. Whatever asked for the dates to be retrieved receives a list in reverse chronological order. (My write function appends the date to the CSV, simple enough.)

    During the initial working-out-the-kinks phase, the retrieval function actually iterated over the reversed list, printing off the dates rather than returning them. But after that caused some issues with redundancy, that got revised to returning a list.

    I also ended up setting up a helper function for the printing which essentially iterates over the list, appends each item to a string with a new line at the end (so, 2022-12-17 \n), and returns that very long string (which gets longer with every update), which can then be printed by whatever requested the dates. This is super inelegant, obviously, so a priority is going to be to figure out a nicer way of handling this.

    Another priority is going to be just… figuring out how to denote updates that happen on the same date. Every time I run the program to test it, it’s counted as a separate update and logged to the CSV. This is good! This is what I want! But I ran this program twenty-three times on Friday, so now the datelog reads (reverse chronologically):

    2022-12-17
    2022-12-17
    2022-12-17
    2022-12-17
    2022-12-17
    ...

    … and so on. You see the issue.

    I put together some questions to ask myself about how to solve this. Still haven’t answered them yet, but essentially they consist of: how do I denote the number of updates on a particular day? How do I store that information as separate from the date, and access it easily to update it?

    One way, which sounds very clunky to me, would be to store the date alongside a number of updates (so, 2022-12-17 for the first update, and then edit that to 2022-12-17 (2) for the second update, and so on. The formatting is still under consideration). The second way, which is even worse, is to store the information as above (every date listed neatly for every time updated, which will get super long very fast), and then every time I would need to return or display a list of previous dates, iterate over the information so that I can return it in a nicer format. No, thank you.

    I think the next step might be MySQL, which means that I’ll have to (re-learn) SQL and how to use it in Python. I’ll also have to pick a database, which will probably be MariaDB, mostly because I picked it randomly from the available MySQL databases when I was setting up the Reclaim Cloud environment which I’m hoping to test this on.

    Oh, right, I have some Reclaim Cloud environments now. The environment for this project isn’t currently online and won’t be for the foreseeable future, unless it turns out I absolutely require the MariaDB from Reclaim Cloud to store the information. Which I probably will.

    For the other environment, I’ve also been poking around a little bit with Ghost — not much yet, as I’m still working on getting it updated to the newest edition from 4.5.0, which is what I’m currently on. Once I do, I’ll be experimenting with the blogging features, as Reclaim is considering using it for our newsletter, which start being released at the end of January 2022. That environment is also offline for now until I figure out what I’m missing trying to update from the command line. Currently I’m dealing with this error:

    A very frustrating error.

    What that sums up to is mostly “You need to update using Ghost-CLI, but you can’t, because you didn’t install this using Ghost-CLI” (I used a one-click installer). Once I get the answer I’ll be able to write this up better, maybe as an article for our support docs, but in the meantime: still working on it.

  • 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.]

  • Refactoring & Rewriting

    So in the past couple of days I’ve been making a lot of… I suppose I’d call them tweaks, because nothing feels big enough to consider it a major change. Could I even make major changes in a two day timespan without just hunkering down and doing nothing else? Probably not.

    So what have I been doing? Mostly refactoring, honestly. Initially I had a couple of methods for updating the wordcount, checking whether to update the day, etc., but I was running a lot of them in multiple lines the __main__ function rather than calling a single clean method. So I wrote a method, getUpdate(), and then subsequently retooled that method to make it more versatile.

    Before getUpdate() would ask you for how many words you’d added to your total, then staple those on to whatever your current total was already (right now it’s always 0, because the program doesn’t retain information between sessions). Now the method will ask you whether you want to add words or give your new total (so, stapling words onto the preexisting total, or replacing that preexisting number entirely); then it calls one of two helper methods based on that, in order to do what you want.

    Those helper methods also ended up having me refactor and split off more helper methods, which has honestly been a good exercise in thinking through what each line is doing and where it might end up getting reused.

    The other biggest “change” has mostly been clearing up my comments, which refactoring has also helped with. Python doesn’t render multi-line comments natively, so the convention is to enclose them in “””s (triple quotation marks), which causes it to register as a multi line string that the computer will just sort of ignore when it comes time to parse. I’ve been using my pre-method comments both as a place to describe what a method is supposed to do — this is good practice — and a place to keep notes about questions/concerns/functionality I might add (this is messy practice). But hey, this project is only for me, right?

    Well, a different problem arose, and it feels a little superficial. My text editor, Atom, color-codes everything in order to help with readability, and it renders all of Python’s strings in a bright green. This works great to offset strings from other things, but when I have lines and lines and lines of green, it makes it hard to see anything else, because it draws the eye so much. Refactoring and tweaking has been as much a way for me to strip down my notes to a point where I can use one or two single-line comments and get rid of the green, as it is to improve my code.

    The next big questions (that I’m scared to answer) will probably be: how do I store information between sessions? And how do I test multi-day streaks? The multi-day streaks will have to come after the storing-between-sessions question, just on account of I can’t have multi-day updates if I can’t store between sessions, but once I’ve got that… hopefully more things will start falling into place.

    More potential avenues for the future, non-immediate: can I/should I practice test driven development with this (might be a bit close to my Model/View/Controller thoughts from last time, haha)? How do I integrate a Python app with Javascript (am I going to need to figure out Flask, which I don’t even know what that is)? Is it possible that I’ll have to “finish” the program, then rewrite it in Java to make it compatible (eek, but I sort of miss Java’s structure compared to Python’s spaghetti-noodle flexibility)? How do cookies work? Should I take a day to just work on building really basic HTML sites with interactive fields and buttons (yes)?

    And, just for the sake of long-term organization and consistency, I should probably a) make a more structured planning document and b) get a GitHub where I can keep better records of what I’ve been doing day-to-day.

  • Messing Around with Python

    In my ongoing saga of “How do I build a web app?” I decided that a good first start would be to build just a regular program that does the things I’d ideally like my first web app to do. In this case, in the spirit of National Novel Writing Month, I’ve been thinking about what’s needed to make a wordcounter/streak tracker/maybe some other things. You know, a cohesive idea like that.

    The wordcounter and streak tracker will probably be fairly easy to implement just on my machine, as it’s pretty much all numbers, so I’m starting there (famous last words?). I’ve actually already started with them. Once I’m happy with them, I’ll try setting them up to work as a really basic, no-styling web app locally, and then we’ll take a crack at deploying using Docker. Probably still without styling, because the longer I can put off untangling the horrible spaghetti that is CSS, the better.

    Why Python? Some pretty superficial reasons, honestly:

    1. I have prior experience in it, though not for a while;
    2. I own a textbook that’s designed to teach you programming using the Python language, which should be useful considering it’s been a while since I’ve really made any significant projects;
    3. and I don’t have to install any new languages on my computer to make it work.

    I considered Java, which fulfills condition 1 and makes up for condition 2 by having JavaDocs (JavaDocs is a work of art), but which doesn’t fulfill condition 3; then I considered Ruby, which is something that I’ve wanted to become proficient in for a while, but which doesn’t actually fulfill any of those conditions. Sad face. Better, I think, not to try to learn two things at once if I don’t have to (especially when I’ll need one to learn the other).

    So far I’ve only implemented three methods: one for getting an updated wordcount & changing the total, one for setting the most recent day updated if needed, and one for checking whether the most recent update requires the most recent day to also be updated. (That’s a lot of recents and updates – I may need to adopt better terminology.) There’s also a main function for getting input through the command line & using it to update the words total & most recent day.

    Plans for the future:

    • methods for tracking the total number of days a person has updated their wordcount
    • methods for tracking the number of days in a row a person has updated their wordcount
    • working out how to make this work with HTML/Javascript to create a local web app
    • Potentially: working out how to effectively backdate updates and integrate them into the streak; working out how to store all this w/ cookies on the user’s machine

    Questions for the future:

    • How/where am I going to store info in between sessions?
    • Can I implement this using the MVC model, or is that too much while I’m getting back in the swing of things? (Potentially I could do the whole thing, then refactor all of it into MVC, but that sounds like a huge pain.)
    • What even is the relationship between Python & Javascript for this stuff? It’s been a very long time since I used Javascript.
    • Probably more things that’ll come up soon!
css.php