Quantified self using Python

Last updated on 2022-02-19 Tagged under  # python  # programming

I keep a text file that acts as my "daily log". Anything of interest gets added, with the entries headed by a datetime stamp (using a keycode shortcut in neovim).

One item I track is my weight, and I have more than a thousand measurements taken over several years. To analyse this data, I created track, a Python program that scans a text file and matches regex values with corresponding calendar dates, and returns results as a dictionary, a two-column display, or generates a scatter plot viewable in a web browser ...

$ track.py -h
usage: track.py [-h] [-d regex] [-v regex] [-m num] [-q] [-r type] [-t title] [-l label] FILE

Scan FILE and match regex values with corresponding calendar dates

positional arguments:
  FILE                  A readable file

optional arguments:
  -h, --help            show this help message and exit
  -d regex, --date regex
                        A regex pattern to find dates (default: ^20\d\d-\d\d-\d\d)
  -v regex, --value regex
                        A regex pattern to find values (default: ^\d)
  -m num, --matchgroup num
                        0 matches entire value regex; > 0 is which part of regex, enclosed in parentheses, to match (default: 0)
  -q, --quiet           suppress non-error messages (default: False)
  -r type, --results type
                        Display results as: dictionary, columns, scatterplot (default: dictionary)
  -t title, --title title
                        A title for match results (default: Matches)
  -l label, --label label
                        Subtitle for values (default: Values)

With all the heavy lifting done by track, it becomes easy to import this module into scripts and create a second tracking program, a third, etc. by changing options and regex search patterns.

Sources: track.py


» Later: Upgrade a home router with OpenWrt

« Earlier: Migrating away from a Google-hosted custom email address