rawsonj / triviabot

A simple IRC trivia bot written in python using twisted.
GNU General Public License v3.0
41 stars 52 forks source link

Question: Multiple data files? #83

Closed za3k closed 3 years ago

za3k commented 3 years ago

Is there any reason the question data is in multiple files? Is this to reduce RAM usage or something?

Was considering doing a Python3 port (to fix https://github.com/rawsonj/triviabot/issues/78) and saw some unrelated stuff that might be worth cleaning up.

rawsonj commented 3 years ago

Not really.

In the initial design of the program, I struggled with a simple, flexible way to store 300000 collected trivia questions.

A sqlite database was considered, but then users would have to know something about sqlite in order to edit questions.

So I decided on a stupid format for the files, but then I didn't want a monolithic file that was 300000 lines long, so we broke them up.

The algorithm for question selection picks a random file, then picks a random line from the selected file, which seemed like a good randomization.

But as I've grown up, I think a monolithic file would have been fine. I also think it would make it simpler to have different game modes, like 'sequential' (ie: start at the beginning of the file and walk each question to the end and repeat) or random, but I was learning python and programming at the time so it is what it is.

I've also been considering a python 3 port, just haven't found the time yet for this hobby program. Got a 3d printer and been messing with that for a bit. :)

rawsonj commented 3 years ago

Oh, and the algorithm I used is very sparing on memory. One should not load the whole file into memory, that's just a waste.

za3k commented 3 years ago

No, the algorithm you've used loads the entire file into memory (lines = fd.read().splitlines()), which is why I thought you might have split the file into many files.

za3k commented 3 years ago

(P.S. have fun with your 3d printer!)

rawsonj commented 3 years ago

lol, goes to show you how long it's been since I've read my own code.

Then yeah, ram usage would be a problem then. Wasn't my intention, but like I said, I was a student at the time.