hranoprovod

package module
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2022 License: MIT Imports: 3 Imported by: 3

README

hranoprovod-cli GoDoc Go Report Card Documentation Status hranoprovod-cli

Description

Hranoprovod is command line diet tracking tool. It supports nested recipes and is agnostic to the metrics you choose to track, which makes it perfect for tracking calories, nutrition data, exercises and any other measurement that is accumulated on daily basis.

asciicast

Installation

asdf

asdf is an extendable version manager for linux and macOS.

hranoprovod can be installed using a plugin as follows:

asdf plugin add hranoprovod https://github.com/aquilax/asdf-hranoprovod.git
asdf install hranoprovod latest
from code

First make sure you have go (golang) installed.

https://go.dev/

Clone the repository and build/install the tool:

git clone https://github.com/aquilax/hranoprovod-cli.git
cd hranoprovod-cli/cmd/hranoprovod-cli/
go install

Docker

You can run hranoprovod-cli from Docker too

Building the image
docker build --pull --rm -f "Dockerfile" -t aquilax/hranoprovod-cli:latest .
Running a balance report
docker run --rm -it -v /path/to/data/files/:/data aquilax/hranoprovod-cli:latest -d /data/food.yaml -l /data/log.yaml bal

Help

Running the hranoprovod-cli command will show you the command line options

$ ./hranoprovod-cli --help
NAME:
   hranoprovod-cli - Diet tracker for the command line

USAGE:
   hranoprovod-cli [global options] command [command options] [arguments...]

VERSION:
   dev, commit none, built at unknown

DESCRIPTION:
   A command line tool to keep log of diet and exercise in text files

AUTHOR:
   aquilax <aquilax@gmail.com>

COMMANDS:
   register, reg  Shows the log register report
   balance, bal   Shows food balance as tree
   lint           Lints file for parsing errors
   report         Generates various reports
   csv            Generates csv exports
   stats          Provide stats information
   summary        Show summary for date
   print          Print log
   gen            Generate documentation
   help, h        Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --begin DATE, -b DATE      Beginning of period DATE
   --end DATE, -e DATE        End of period DATE
   --today DATE               Overwrite today's date DATE
   --database FILE, -d FILE   optional database file name FILE (default: "food.yaml") [$HR_DATABASE]
   --logfile FILE, -l FILE    log file name FILE (default: "log.yaml") [$HR_LOGFILE]
   --config FILE, -c FILE     Configuration file FILE (default: "/home/aquilax/.hranoprovod/config") [$HR_CONFIG]
   --date-format DATE_FORMAT  Date format for parsing and printing dates DATE_FORMAT (default: "2006/01/02") [$HR_DATE_FORMAT]
   --maxdepth DEPTH           Resolve depth DEPTH (default: 10) [$HR_MAXDEPTH]
   --no-color                 Disable color output (default: false)
   --no-database              Disables loading the database (even if database filename is set) (default: false)
   --help, -h                 show help (default: false)
   --version, -v              print the version (default: false)

Usage

Hranoprovod uses two files with very similar format to operate.

Database file (food.yaml)

Contains all the "recipes" in the following format:

$ cat examples/food.yaml
# daily nutrition budget
day/nonworking:
  calories: -1200
  fat: -124
  carbohydrate: -50
  protein: -104

bread/rye/100g:
  # barcode: 0000000000000
  calories: 259
  fat: 3.3
  carbohydrate: 48
  protein: 9

egg/boiled/100g:
  # boiling time: 12 min
  calories: 155
  fat: 11
  carbohydrate: 1.1
  protein: 13

vegetables/lettuce/romaine/100g:
  calories: 15
  fat: 0.5
  carbohydrate: 1.7
  protein: 0.9

sauce/mayonnaise/100g:
  calories: 680
  fat: 7.5
  carbohydrate: 0.6
  protein: 1

sandwich/egg/lettuce/100g:
  bread/rye/100g: 0.40
  egg/boiled/100g: 0.20
  vegetables/lettuce/romaine/100g: 0.20
  sauce/mayonnaise/100g: 0.20

candy/snickers/bar:
  calories: 280
  fat: 13.6
  carbohydrate: 35.1
  protein: 4.29


Hranoprovod is measure agnostic and it's up to the user to use or state the measurements.

Log journal file (log.yaml)

The log file contains dated usage of the recipes, defined in the database file.

$ cat examples/log.yaml
2021/01/24:
  day/nonworking: 1
  coffee/cup: 1
  sandwich/egg/lettuce/100g: 1.20
  candy/snickers/bar: 1

2021/01/25:
  day/nonworking: 1
  coffee/cup: 1
  sandwich/egg/lettuce/100g: 1.50
  coffee/cup: 1

Note: it's not mandatory to have the elements in the database file. Elements which are not found will be represented as they are. They can always be added later to the database.

Register

Given this example, the result will look like:

$ ./hranoprovod-cli -d examples/food.yaml -l examples/log.yaml --no-color reg
2021/01/24
	day/nonworking              :      1.00
		            calories   -1200.00
		        carbohydrate     -50.00
		                 fat    -124.00
		             protein    -104.00
	coffee/cup                  :      1.00
		          coffee/cup       1.00
	sandwich/egg/lettuce/100g   :      1.20
		            calories     328.32
		        carbohydrate      23.86
		                 fat       6.14
		             protein       7.90
	candy/snickers/bar          :      1.00
		            calories     280.00
		        carbohydrate      35.10
		                 fat      13.60
		             protein       4.29
	-- TOTAL  ----------------------------------------------------
		            calories     608.32   -1200.00 =   -591.68
		        carbohydrate      58.96     -50.00 =      8.96
		          coffee/cup       1.00       0.00 =      1.00
		                 fat      19.74    -124.00 =   -104.26
		             protein      12.19    -104.00 =    -91.81
2021/01/25
	day/nonworking              :      1.00
		            calories   -1200.00
		        carbohydrate     -50.00
		                 fat    -124.00
		             protein    -104.00
	coffee/cup                  :      2.00
		          coffee/cup       2.00
	sandwich/egg/lettuce/100g   :      1.50
		            calories     410.40
		        carbohydrate      29.82
		                 fat       7.68
		             protein       9.87
	-- TOTAL  ----------------------------------------------------
		            calories     410.40   -1200.00 =   -789.60
		        carbohydrate      29.82     -50.00 =    -20.18
		          coffee/cup       2.00       0.00 =      2.00
		                 fat       7.68    -124.00 =   -116.32
		             protein       9.87    -104.00 =    -94.13

Balance tree

You can also generate balance tree for single nutrition value:

$ ./hranoprovod-cli -d examples/food.yaml -l examples/log.yaml --no-color bal -s calories
    280.00 | candy
    280.00 |   snickers
    280.00 |     bar
  -2400.00 | day
  -2400.00 |   nonworking
    738.72 | sandwich
    738.72 |   egg
    738.72 |     lettuce
    738.72 |       100g
-----------|
  -1381.28 | calories

Same result in slightly more compact format:

$ ./hranoprovod-cli -d examples/food.yaml -l examples/log.yaml --no-color bal -s calories -c
    280.00 | candy/snickers/bar
  -2400.00 | day/nonworking
    738.72 | sandwich/egg/lettuce/100g
-----------|
  -1381.28 | calories

Documentation

Index

Constants

View Source
const (
	// Negative register
	Negative = 0
	// Positive register
	Positive = 1
)
View Source
const DefaultCategorySeparator = "/"

DefaultCategorySeparator the default string used to separate categories

Variables

This section is empty.

Functions

This section is empty.

Types

type AccValues

type AccValues []float64

AccValues contains accumulator values

type Accumulator

type Accumulator map[string]AccValues

Accumulator accumulates element values by name

func NewAccumulator

func NewAccumulator() Accumulator

NewAccumulator returns new accumulator

func (Accumulator) Add

func (acc Accumulator) Add(name string, val float64)

Add adds name/value to the accumulator

type DBNode

type DBNode struct {
	Header   string
	Elements Elements
	Metadata *Metadata
}

DBNode contains general node data

func NewDBNodeFromNode

func NewDBNodeFromNode(n *ParserNode) *DBNode

NewDBNodeFromNode creates DB Node from Parser node

type DBNodeMap

type DBNodeMap map[string]*DBNode

DBNodeMap contains list of general nodes

func NewDBNodeMap

func NewDBNodeMap() DBNodeMap

NewDBNodeMap creates new list of general nodes

func (*DBNodeMap) Push

func (db *DBNodeMap) Push(node *DBNode)

Push adds node to the node list

type Element

type Element struct {
	Name  string
	Value float64
}

Element contains single element data

func NewElement

func NewElement(name string, val float64) Element

NewElement creates new element

type Elements

type Elements []Element

Elements contains array of elements

func NewElements

func NewElements() Elements

NewElements creates new element list

func (*Elements) Add

func (el *Elements) Add(name string, val float64)

Add adds new element to the list

func (*Elements) Index

func (el *Elements) Index(name string) (int, bool)

Index returns the index of the element by name

func (Elements) Len

func (el Elements) Len() int

Len returns the length of the element list

func (Elements) Less

func (el Elements) Less(i, j int) bool

Less compares two elements

func (Elements) Sort

func (el Elements) Sort()

Sort sorts the element list

func (*Elements) SumMerge

func (el *Elements) SumMerge(left Elements, mult float64)

SumMerge merges the element list with new one multiplied by mult

func (Elements) Swap

func (el Elements) Swap(i, j int)

Swap swaps two elements

type LogNode

type LogNode struct {
	Time     time.Time
	Elements Elements
	Metadata *Metadata
}

LogNode contains log node data

func NewLogNode

func NewLogNode(time time.Time, elements Elements, metadata *Metadata) *LogNode

NewLogNode creates new log node

func NewLogNodeFromElements

func NewLogNodeFromElements(time time.Time, elements Elements, metadata *Metadata) (*LogNode, error)

NewLogNodeFromElements creates new LogNode from ParserNode elements and time

type Metadata

type Metadata []MetadataPair

Metadata contains list of metadata pairs

type MetadataPair

type MetadataPair struct {
	Name  string
	Value string
}

MetadataPair contains metadata key value pair

type ParserNode

type ParserNode struct {
	Header   string
	Elements Elements
	Metadata *Metadata
}

ParserNode contains general node data

func NewParserNode

func NewParserNode(header string) *ParserNode

NewParserNode creates new geneal node

type TreeNode

type TreeNode struct {
	Name     string
	Total    float64
	Children map[string]*TreeNode
}

TreeNode contains data for a single balance tree node

func NewTreeNode

func NewTreeNode(name string, sum float64) *TreeNode

NewTreeNode creates new tree node

func (*TreeNode) Add

func (tn *TreeNode) Add(child *TreeNode) *TreeNode

Add appends child node to the current tree node

func (*TreeNode) AddDeep

func (tn *TreeNode) AddDeep(el Element, separator string)

AddDeep adds recursive child nodes to the current node given an element

func (*TreeNode) FirstChild

func (tn *TreeNode) FirstChild() *TreeNode

FirstChild returns the first child of a TreeNode

func (*TreeNode) Keys

func (tn *TreeNode) Keys() []string

Keys returns sorted array of children keys

Directories

Path Synopsis
Package filter provides functions for filtering log nodes
Package filter provides functions for filtering log nodes
Package parser provides function to parse hranoprovod formatted files
Package parser provides function to parse hranoprovod formatted files
Package resolver resolves a food database
Package resolver resolves a food database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL