Skip to content

tmlmt/milk-tracker

Repository files navigation

Milk Tracker

GitHub License Release Coverage

Basic breastfeeding data analysis and tracking

Introduction

The idea of this app stemmed from the need to track and visualize breastfeeding meal statistics stored in a Pandas DataFrame. This was the opportunity to learn how to create and deploy a web app based on python-based nicegui, an alternative to streamlit with better state management and handling of user interaction. It quickly expanded to learn even more how to develop python applications with best development practices like:

  • formatting and linting with ruff
  • deploying with GitHub Actions
  • split code using a model-view-controller design pattern
  • validate data using pydantic models
  • keep track of changes using git-cliff
  • managing a python environment using micromamba
  • Testing the code prior to releasing using pytest
  • Calculating the coverage of tests using coverage
  • Typing python code and checking it with mypy

Huge thanks to the Open Source community for providing such great tools to the world.

Features

  • Protect access with password
  • Record meals start and end times
  • Lock start time of new meal
  • Keep track of meal rounds during ongoing meal
  • Reminders for daily intake of vitamins
  • See latest three days trends in graphs
  • See daily stats in a table
  • Keep a log of daily memories

Backlog

  • Edit and delete any meal

Tried without satisfactory result

  • Prediction of next meal's time and duration (Facebook Prophet couldn't really predict accurately -- see #15. Perhaps additional metadata would help, or another algorithm may be more addapted)

Self-hosting

The following instructions rely on the use of micromamba for managing python environment and nginx for the web server.

  1. Use env.yaml file to create your environment: micromamba env create -f env.yaml
  2. Copy milk_tracker folder in your web server area, e.g. /var/www/
  3. Create an .env file within that folder with the following content:
APP_PORT=<port_number>
PASSWORD=<argon2 password hash as login>
STORAGE_SECRET=<passphrase to protect your storage area>
  1. Customize the milk_tracker/config.yaml file
  2. Initialize the meal journal and memories log by renaming assets/journal.template.xlsx and resp. assets/memories.template.csv into assets/journal.xlsx and resp. assets/memories.csv
  3. Use scripts/milk-tracker.conf as example to configure the redirection of http requests to your app using nginx and your own domain
  4. Use scripts/milk-tracker.service as example to configure a systemd unit to manage the start/stop of the app
  5. Enable the unit, e.g. systemctl --user enable milk-tracker.service if you're running the app using a specific user and choose to run user units
  6. Start the app, e.g. systemctl --user start milk-tracker.service
  7. Go to https://<your_domain>:<port_number> and start tracking :-)

License

MIT License

Copyright (c) 2024 Thomas Lamant