[Userscript] Leech training - beta testing the rewrite

If you’ve been using the Leech Training script, you may have encountered the occasional timeout, or bug that needs me to wipe out your progress from the database. Sorry about that! I’ve been meaning to rewrite it for some time now, and found a good amount of time over the festive period. So, if you use the leech trainer, and the phrase “Postman is an app I’m familiar with for debugging” is familiar to you, then read on! If the second part is nonsense to you, I’ll probably enlist your help at a later date.

There’s a newer version of the user script available to install, and within that, you’ll see we have a new URL for the API.

If you install that userscript, you’ll need to disable the existing one or else they’ll probably trample all over each other, but if you get it installed correctly you should see the familiar “Leeches” button appear at the top.

What’s Changed?

Externally, not all that much, but it should hopefully be a little faster to respond when refreshing your stats. The backend now makes use of the updated_after options in WK API so it’s only retrieving small chunks each time.

The length of a leeches training session is currently set to 3 because I was getting tired of typing while testing, so don’t worry if it seems short!

The leech score is currently set to 1.0, but you can now change it. That’s where postman comes in. If you take the URL linked to earlier, and send a PATCH request to /user with a JSON body of { leech_score: 1.2 } then you’ll set your leech score to 1.2. Refreshing your leeches count should then show you a lower number. To authenticate your request, use an Authorization header set to Bearer <YOUR API KEY>.

If things somehow get screwed up with your stats, you can send a DELETE request to '/leecheswith the same authorization and it'll clear out all of your cached stats. Sending a GET to/leeches` will then refresh it all.

If you’ve time to try it and find things I’ve missed from my single-user testing, that would be great. The data used by this version of the trainer has nothing to do with the current production setup, so you’ll not break that, and you might well see some differences in counts.

Still To Do For Parity

  • Adding in visually similar kanji to lessons
  • Caching trained leeches in the event you don’t finish the full quiz
6 Likes

Thanks for making the effort to update this script!

I’ve been using it A LOT as a way to tackle my leeches! ^^ I’m no techie though, so I’m not sure how much help I can be. :sweat_smile:

Don’t worry about it! I’ll try to get it to the point of being the de facto version as soon as possible!

Glad you’re finding it useful.

2 Likes

That shouldn’t happen. I just uninstalled and reinstalled the new script and I get a leech number. Are you using the new userscript or copying the URL into the old one? You’ll need the new one. Anything in the console?

The good news is that the /user endpoint will now work. It was a very difficult, very technical fix (it was a typo).

If you do an authenticated request to https://wk-leeches-dev.pun7u6s23ol8m.eu-west-2.cs.amazonlightsail.com/leeches do you get a list of leeches?

The github gist has been updated to version 3.1.0. All being well, it should now offer you the option to change your personal leech score from the Tampermonkey menu.

it’s hit or miss, sometimes i get a 500 Internal server error somtimes i get a response but now i can send the patch to /user(and change the leech score) but still nothing

Script updated to use the correct URL (really need to automate that, no manual process survives long). Tracked down the issue in the logs and I’m going to need to rework some of the storage to fix it. I’m using dynamodb for the first time and my test case of 1 (me!) wasn’t big enough. On it!

ouch, i do have too many leeches!

Thanks!
looking forward to it, btw enabling the scripts put’s a black veil on the self study window.

Took me a little longer than anticipated, but the latest userscript version should be a bit more reliable.

It’s not so much teh number of leeches that you have, but the number of unburned assignments, and therefore statistics. Because you’re of a higher level, you probably have more than I do, so I was hitting the row limit as I try to keep a cache of your relevant assignments and stats. Originally, those were both in a single row, but that’s limited to 400KB, so I’ve split it into two for now. A more robust solution will probably be required.

1 Like

Next on the list.

1 Like

Self study quiz clash is now resolved. Looking at the existing CSS, I think it was taken from the self study script so I’ve cleared it out and left behind just what I think is required. Self Study quiz now seems to be happy.

You can also change the number of items in a quiz. It’ll default to 10 so you’ll need to patch your profile if you want to change it. Sending a GET to /user will give you your current profile and you can then send back whichever fields (except username) that you want to change.

1 Like

so it works great right now, it’s only a bit slow. couldn’t find any other bug.

ALSO, thanks for making this. it must have taken a lot of time and energy!

Which bit are you finding slow? There’s not currently a cache of leeches on the client side, so it’s loading your data each time which is why you might see the “You have X leeches” message.

I’m going to convert the previous version’s “similar vocab” data so I can mix that in as well, and also offer an option to ignore leeches from certain levels. Then it should be good to go for a swap over.

the typing was slow this morning while the cpu usage was normal. now it’s working fine, i’ll keep testing

it happened again, the typing is so slow, but it seems random :confused:

I can’t think of anything in there that would slow down typing. Perhaps the wanakana library is being bound to the input multiple times, I can see if there’s a way of that being the case.

@rosshendry I’m not smart enough to help beta test your script (i.e. I can’t figure out how to load it! :stuck_out_tongue: ) but I am using your original Leech Trainer and I think it’s AWESOME. I love how it trains not only my leech, but it seems to also train other vocabulary that uses the leech in question. I’m assuming you did that on purpose; it really really really improves my understanding of the nuances of how a character is used in its many different ways. I just wanted to take a moment to say THANK YOU in a place where you might see it.

You’re very welcome! The original one that you’re using was written by another helpful WK user, and I inherited at one point when boring technical stuff happened.

The other vocab feature is the last bit of the original that I need to port across to the new setup. Where does the time go, though?!

How…how is it April!? Okay, time to get this finished off. Back on the todo list!

2 Likes