Closed heikkilevanto closed 1 month ago
The first step would be to define a routine to split a data line into a hash with named elements. Use them everywhere instead of splitting values into (global?) variables. Once rid of the variables, it should not be too hard to add an optional line type, defaulting to old beer line.
Then define new line types, and routines to split and collect them
Finally change the UI to allow entering different types of lines
Quite some work before we can start to see the difference, but will pay off in the long run
Started to code this, in its own branch datafile
. Didn't get very far yet.
Make it parameter driven, so that each type of data file has a list of field names, and they get automatically mapped to fields in the record hash.
Make also a simple routine that returns the current variables in the same order, to replace explicit calls to split
Made the parameter system, and changed all split()'s to use a helper function. Can read line type "Beer" with the same old fields. Placed the type right after the time stamp.
Made the file reading routine use the new style record hash. Was somewhat slower, at least until I could delete the old style parsing of the lines. Still, all these hash references do take a little bit time. Running on the same machine even the about page takes over 500ms, since it too reads the file.
Ok, using a record type all the way through. Moved many global variables to be local to the record POST routine, not needed anywhere else. Added use strict
and killed a large pile of errors.
Next steps:
I think this is almost complete now. Adding more data types will be easy if needed.
I already make many hacks for wines, restaurants, etc. Design a better data format that handles all those, and has room for future extensions like whom I drink with, comments about the evening, etc.
I would still keep the one-line format, in best Unix tradition. But allow for a line type, and variable fields depending on the type.
Keep the general fields at the beginning of the line:
Then, depending on the type, we can have variable fields:
This will need a new major version, and a way to convert old data files. Lucky I don't have many users, so I can just do a batch conversion.