4.2. More change options
Prev | Chapter 4. More Pantry usage | Next

## 4.2. More change options

### 4.2.1. Using the `--auto-order` option

Often you will find that you enter foods into Pantry in the same order in which you eat them. You might find it handy to have Pantry show those foods to you in the same order in which you entered them. The `--auto-order` option is handy for this.

When you add foods to a file and you have chosen the `--auto-order`, Pantry will automatically change the `order` trait of the added foods. To find what the new `order` trait should be, Pantry first searches the file that the food is being added to for other foods with values for the `date` and `meal` traits that are identical to the ones in the food that is being added. Pantry then sorts these foods in ascending order by their `order` trait.

Pantry then checks to see if the highest food's `order` trait matches the regular expression `^[0-9]{4}$`. Examples of values for which this would be true include `0010`, `2338`, and `0100`. Pantry then takes that value, removes any leading zeroes, removes the last digit, and increments the result by one. A trailing zero is added to the result, and the result is left-padded with zeroes if necessary in order to make it four digits. Thus, if the previously highest `order` trait was `0010`, the resulting `order` is `0020`. `2338` yields a new order of `2340`, and `0100` leads to `0110`.

If the highest food's `order` trait does not match the regular expression `^[0-9]{4}$`, then the new food's `order` trait is set to `0010`.

As always, an example helps. We'll use the same foods as we did in a previous example, but let's say you ate the exact same thing one day later:

Example 4.3. Using --auto-order

    $ pantry --ignore-case --name "apples, raw, with skin" --c-qty \
    > 1 --c-unit large --c-date "May 9" --c-meal Breakfast --auto- \
    > order --add diary master

    $ pantry --ignore-case --name "kellogg's corn flakes" \
    > --c-qty 1 --c-unit cup --c-date "May 9" --c-meal Breakfast \
    > --auto-order --add diary master

    $ pantry --ignore-case --name "milk, reduced fat, fluid, 2% \
    > milkfat, with added vitamin A" --c-qty 1 --c-unit cup --c-date \
    > "May 9" --c-meal Breakfast --auto-order --add diary master

    $ pantry --ignore-case --name "carrots, raw" --c-qty 1 \
    > --c-unit ^large --c-date "May 9" --c-meal Lunch --auto-order \
    > --add diary master

    $ pantry --ignore-case --name "Chicken, broilers or fryers, wing, \
    > meat and skin, cooked, roasted" --c-date "May 9" \
    > --c-unit wing --c-qty 3 --c-meal Lunch --auto-order --add diary master

    $ pantry --ignore-case --name "ice creams, chocolate, rich" \
    > --c-qty .5 --c-unit cup --c-date "May 9" --c-meal \
    > "Lunch" --auto-order --add diary master

    $ pantry --ignore-case --name "mcdonald's, cheeseburger" \
    > --c-unit item --c-qty 1 --c-date "May 9" --c-meal \
    > "Dinner" --auto-order --add diary master

    $ pantry --ignore-case --name "mcdonald's, french fries" \
    > --c-qty 1 --c-unit large --c-date "May 9" --c-meal Dinner \
    > --auto-order --add diary master

    $ pantry --ignore-case --name "popcorn, oil-popped, unsalted" \
    > --c-qty "2 1/2" --c-unit oz --c-date "May 9" \
    > --c-meal Dinner --auto-order --add diary master

Now you can sort the foods by their `order` traits:

Example 4.4. Using --sort with foods that have been automatically ordered

    $ pantry --date "May 9" --print traits-blank --sort dmo diary
    Apples, raw, with skin
    Group: Fruits and Fruit Juices
    Date: May 9 Meal: Breakfast Order: 0010
    Refuse: 8 percent Core and stem
    1 large (3-1/4" dia) (approx 2 per lb) (212g)

    Cereals ready-to-eat, KELLOGG, KELLOGG'S Corn Flakes
    Group: Breakfast Cereals
    Date: May 9 Meal: Breakfast Order: 0020
    1 cup (1 NLEA serving) (28g)

    Milk, reduced fat, fluid, 2% milkfat, with added vitamin A
    Group: Dairy and Egg Products
    Date: May 9 Meal: Breakfast Order: 0030
    1 cup (244g)

    McDONALD'S, Cheeseburger
    Group: Fast Foods
    Date: May 9 Meal: Dinner Order: 0010
    1 item (119g)

    McDONALD'S, French Fries
    Group: Fast Foods
    Date: May 9 Meal: Dinner Order: 0020
    1 large serving (170g)

    Snacks, popcorn, oil-popped, unsalted
    Group: Snacks
    Date: May 9 Meal: Dinner Order: 0030
    2 1/2 oz (71g)

    Carrots, raw
    Group: Vegetables and Vegetable Products
    Date: May 9 Meal: Lunch Order: 0010
    Refuse: 11 percent Crown, tops and scrapings
    1 large (7-1/4" to 8-/1/2" long) (72g)

    Chicken, broilers or fryers, wing, meat and skin, cooked, roasted
    Group: Poultry Products
    Date: May 9 Meal: Lunch Order: 0020
    Refuse: 48 percent Bone
    3 wing, bone removed (102g)

    Ice creams, chocolate, rich
    Group: Sweets
    Date: May 9 Meal: Lunch Order: 0030
    .5 cup (74g)

The results are a bit different if we set only the `date` trait when we use `--auto-order`:

Example 4.5. Using `--auto-order` with only the `date` trait changed

    $ pantry --ignore-case --name "apples, raw, with skin" --c-qty \
    > 1 --c-unit large --c-date "May 10" --auto-order --add diary \
    > master

    $ pantry --ignore-case --name "kellogg's corn flakes" \
    > --c-qty 1 --c-unit cup --c-date "May 10" --auto-order --add \
    > diary master

    $ pantry --ignore-case --name "milk, reduced fat, fluid, 2% \
    > milkfat, with added vitamin A" --c-qty 1 --c-unit cup --c-date \
    > "May 10" --auto-order --add diary master

    $ pantry --ignore-case --name "carrots, raw" --c-qty 1 \
    > --c-unit ^large --c-date "May 10" --auto-order --add diary \
    > master

    $ pantry --ignore-case --name "Chicken, broilers or fryers, wing, \
    > meat and skin, cooked, roasted" --c-date "May 10" \
    > --c-unit wing --c-qty 3 --auto-order --add diary master

    $ pantry --ignore-case --name "ice creams, chocolate, rich" \
    > --c-qty 1 --c-unit cup --c-date "May 10" --auto-order --add \
    > diary master

    $ pantry --ignore-case --name "mcdonald's, cheeseburger" \
    > --c-unit item --c-qty 1 --c-date "May 10" --auto-order --add \
    > diary master

    $ pantry --ignore-case --name "mcdonald's, french fries" \
    > --c-qty 1 --c-unit large --c-date "May 10" --auto-order \
    > --add diary master

    $ pantry --ignore-case --name "popcorn, oil-popped, unsalted" \
    > --c-qty 2 --c-unit oz --c-date "May 10" --auto-order --add \
    > diary master

    $ pantry --date "May 10" --print traits-blank --sort o diary
    Apples, raw, with skin
    Group: Fruits and Fruit Juices
    Date: May 10 Order: 0010
    Refuse: 8 percent Core and stem
    1 large (3-1/4" dia) (approx 2 per lb) (212g)

    Cereals ready-to-eat, KELLOGG, KELLOGG'S Corn Flakes
    Group: Breakfast Cereals
    Date: May 10 Order: 0020
    1 cup (1 NLEA serving) (28g)

    Milk, reduced fat, fluid, 2% milkfat, with added vitamin A
    Group: Dairy and Egg Products
    Date: May 10 Order: 0030
    1 cup (244g)

    Carrots, raw
    Group: Vegetables and Vegetable Products
    Date: May 10 Order: 0040
    Refuse: 11 percent Crown, tops and scrapings
    1 large (7-1/4" to 8-/1/2" long) (72g)

    Chicken, broilers or fryers, wing, meat and skin, cooked, roasted
    Group: Poultry Products
    Date: May 10 Order: 0050
    Refuse: 48 percent Bone
    3 wing, bone removed (102g)

    Ice creams, chocolate, rich
    Group: Sweets
    Date: May 10 Order: 0060
    1 cup (148g)

    McDONALD'S, Cheeseburger
    Group: Fast Foods
    Date: May 10 Order: 0070
    1 item (119g)

    McDONALD'S, French Fries
    Group: Fast Foods
    Date: May 10 Order: 0080
    1 large serving (170g)

    Snacks, popcorn, oil-popped, unsalted
    Group: Snacks
    Date: May 10 Order: 0090
    2 oz (57g)

You might complain that the previous examples took a lot of typing. We'll learn how you can cut down the amount of typing in a later section.

### 4.2.2. Changing food quantities by refuse amount

Internally, Pantry's nutrient amounts are recorded as amount of nutrient for a given amount of edible food. More specifically, Pantry tracks each of its foods by recording the amount of each nutrient per 100 grams of edible food. How Pantry converts from nutrient per 100 grams of edible food to the total amount of nutrient in your foods varies depending upon the unit of your food.

The units `g`, `oz`, and `lb` are available for every food. For foods using one of these available units, it is simple for Pantry to convert from nutrients per 100 grams to nutrients per ounce or nutrients per pound.

Any of a food's other avaialble units are recorded in Pantry with their total grams of edible portion. Pantry then uses this gram weight and the amount of nutrient per 100 grams of edible portion to compute the total nutrients in your food.

An example will prove helpful. Let' take some apples:

Example 4.6. Traits and available units for an apple

    $ pantry --name "Apples, raw, with skin" --print names-units \
    > master
    Apples, raw, with skin
       cup, quartered or chopped
       large (3-1/4" dia) (approx 2 per lb)
       NLEA serving
       medium (2-3/4" dia) (approx 3 per lb)
       cup slices
       small (2-1/2" dia) (approx 4 per lb)

By now this looks familiar to you. This way, if you eat a large apple, you change the unit of the food to `large (3-1/4" dia) (approx 2 per lb)`. Pantry knows how many grams a large apple weighs. To find out how many grams correspond to each unit, use the `measures` report, which shows the weight in grams of each measure:

Example 4.7. Using the `measures` report

    $ pantry --name "Apples, raw, with skin" --print names- \
    > measures master
    Apples, raw, with skin
       cup, quartered or chopped (125g)
       lb (454g)
       g (1g)
       large (3-1/4" dia) (approx 2 per lb) (212g)
       oz (28g)
       NLEA serving (154g)
       medium (2-3/4" dia) (approx 3 per lb) (138g)
       cup slices (110g)
       small (2-1/2" dia) (approx 4 per lb) (106g)

The weights in grams correspond to the edible portion of the food. Thus, in this example, a typical large apple weighs 212 grams, without the inedible portions (such as the core).

But perhaps you eat an apple and you want to use the `g`, `oz`, or `lb` unit. This is especially likely if, for example, you have a kitchen scale and you wish to precisely measure the amount of all the food you eat. If you wish to weigh your own apples rather than using the approximations given in the available units, you have a few options.

One option is to simply cut up the apple, cut out the core, and then weigh the resulting chunks. That is fine if you usually cut up your apples (as I do) but not so good if you do not want to chop up your apples all the time.

Another option is to weigh the entire apple, whole, and record that you ate (for example) a seven-ounce apple. The only problem with this is that the nutrient amounts in Pantry are for the edible portion of the food. Thus, if you do not account for the fact that a fraction of the apple is a core and a stem, you will overestimate how much apple you ate.[6] To compensate for this, you could weigh the entire apple, eat it, and then weigh the leftover core and stem. You would subtract the weight of the core and stem from the weight of the entire apple, and then figure that you ate the difference. That would get tedious.

A third option is to use the `--refuse` option. It uses the `refuse` trait to reduce your food's quantity by the percentage of refuse. As you saw in the example above, an apple is 8 percent refuse. So, assuming you have an eight-ounce apple:[7]

Example 4.8. Using the `--refuse` option

    $ pantry --name "Apples, raw, with skin" --c-qty 8 --c-unit oz \
    > --print traits-nuts --refuse master
    Apples, raw, with skin
    Group: Fruits and Fruit Juices
    Refuse: 8 percent Core and stem
    7.36 oz (209g)
    Nutrient                  Amount         %G     %TOT
    -------------------------------------------------------
    Calories                  109  kcal       5      100
    Total Fat                 0    g          1      100
    Saturated Fat             0    g          0      100
    Cholesterol               0    mg         0      0
    Sodium                    2    mg         0      100
    Total Carbohydrate        29   g          10     100
    Dietary Fiber             5    g          20     100
    Sugars                    22   g          NA     100
    Protein                   1    g          1      100
    Vitamin A                 113  IU         2      100
    Vitamin C                 10   mg         16     100
    Calcium                   13   mg         1      100
    Iron                      0    mg         1      100

As you can see, the `--refuse` option reduces the quantity of the apple by eight percent. This way, you can weigh the entire apple (including the core) and still get a good estimate of which portion of the apple was actually edible.

It only makes sense to use the `--refuse` option when you are using the `g`, `oz`, or `lb` units. Every other unit in the `master` file already accounts for refuse--for example, with the apple, the `large (3-1/4" dia) (approx 2 per lb)` already accounts for the eight percent refuse.

When using the `--refuse` option, every food in the buffer will have its quantity reduced by its corresponding refuse percentage. This of course does not affect foods with zero percent refuse or foods whose `pctRefuse` trait is empty.

[6] To which you might say: "big deal! It's just an apple core." The problem is minor with an apple, but consider the same issue with an ear of corn on the cob, or a pork sparerib...

[7] Nowadays I frequently see single apples that weigh nearly a pound!

Prev | Up | Next
Chapter 4. More Pantry usage | Home | 4.3. Configuring Pantry