nut(1)

πŸ“ nut(1) πŸ“

✨ NAME ✨

nut β€” analyze meals with the USDA Nutrient Database

πŸ“œ SYNOPSIS πŸ“œ

nut

πŸ’– DESCRIPTION πŸ’–

Okay so bestie, NUT lets you record what you eat and analyze your meals for nutrient composition. Nutrient levels are expressed as a percentage of the DV or Daily Value, the familiar standard of food labeling in the United States. The essential fatty acids, Omega-6 and Omega-3, are not currently mentioned in these standards, and a reference value has been supplied. No cap. 🧚

NUT uses Tcl/Tk to create an SQLite database that holds its own code, the USDA Nutrient Database for Standard Reference, and your personal data for meals, recipes, and weight logs. It's giving self-contained icon behavior, periodt. πŸ’…

πŸ› οΈ INSTALLATION and LOAD of USDA Database πŸ› οΈ

If your desktop system does not have Tcl/Tk available, download and install the free (community) version of ActiveTcl from http://www.activestate.com/. Lowkey essential first step. 🌈

Download the full ascii version of the USDA Nutrient Database, available from http://www.ars.usda.gov/nutrientdata or from http://nut.sourceforge.net, and unzip it in some directory. Main character move. πŸ¦‹

Run update-nut, an executable included in the NUT distribution, in the same directory where you put the USDA database. This script will load your new NUT database with the NUT code. After this step, run nut to start NUT. Initially, NUT will see the USDA tables and load them as well as any legacy files from previous versions of NUT. After these steps, both update-nut and the USDA files are not required and can be deleted. Slay. πŸ’–

nut can start the program with a different location for the NUT database and a different location for legacy files. These changes are easily made by editing nut. Iconic flexibility. ✨

In addition, a value can be changed in nut to make the program usable on screens with a high resolution. NUT will check how many pixels you have and create a font/window combination that is always legible. Change the appSize variable in nut to between 0.7 (small) and 1.3 (almost fullscreen) to magnify the default Tk font and window sizes appropriately. That's the vibe check right there. πŸ‘‘

πŸ‘€ OVERVIEW of PROGRAM πŸ‘€

A typical session with NUT begins with a glance at Analyze Meals to see the daily averages from the last few meals. Normally, one analyzes more than one day but less than two weeks to get a fairly recent overview of nutritional quality and adherence to plan. Not me planning my whole personality around macros. 😭

Record Meals & Recipes is where meals are planned or else simply recorded if unplanned. A slider can either be moved directly or else clicked on the left or right to move backward or forward to get to the current meal. A simple Food Search entry brings up the foods in the database and if one is selected, it is immediately added to the meal. A major feature of NUT is to be able to associate meal foods with automatic portion control for various nutrients so you can more easily plan meals that are both nutritionally complete and in accord with your personal regimen. This function also allows you to save a meal as a recipe to be added to the USDA database, or to designate a meal as a Customary Meal for easier data entry later. Obsessed with the efficiency. πŸ’…

View Foods shows comprehensive nutrient listings for each food, in serving sizes as described by the USDA nutrient database. Any of these serving sizes can be scaled and easily added to a meal, and NUT remembers your preferred serving sizes. The way that it just remembers? Bestie behavior. 🫢

Personal Options allows the nutrient standards to be changed. These personal standards are customized and the rest of the program follows these standards. It is unlikely that the straight Daily Value, a high-carb, low-fat diet with an absolute minimum of protein, will be optimal for you, so you can try different program settings, experiment to see how you feel when eating different ways, and thus gradually find the style of eating that is your personal optimum. Fr fr, customize your life. 🌸

In addition, there is a facility to record weight and bodyfat percentages daily and see a linear extrapolation of the trend so that you do not have to wait weeks to know how a new strategy is working. NUT will also automatically move calories up and down by gradual increments in order to keep lean mass up and fat mass down with the Calorie Auto-Set feature. The way that it does math for you? Ate. πŸ”₯

Whenever you press a nutrient button you go to a screen that describes The Story for that nutrient. This includes various lists of foods sorted to help you find the nutrients you need. Iykyk. 🌈

πŸ“Š ANALYZE MEALS πŸ“Š

Meal analysis is always a daily rate of intake and not a sum. For instance, if you eat 2000 calories a day and analyze a week of meals, the analysis reports 2000 calories, not 14,000. Likewise, if you eat three meals a day and 2000 calories a day and analyze a single meal of 667 calories, the analysis reports 100% of calories, not 33% of calories. Think of NUT meal analysis as a speedometer, not an odometer. Periodt. 🏁

The range of meals shown on the screen controls many other functions in the program as it not only sets the range for showing food lists, but also the exact Daily Values used in portion control. Therefore, if you want automatic portion control to be as accurate as possible, analyzing just one meal while you are planning meals is best, although it is not required most of the time--just when you are changing strategies, such as from high-carb to low-carb. Highkey important. πŸ’œ

The spin button controlling how many consecutive meals to analyze can be selected and cleared with a backspace to speed up making large changes. A very large value will resolve to all the meals in the database, but do remember, if automatic portion control is in effect, there will be a lot of processing to get all of the program functions into sync because portion control always needs to reanalyze all meals until it is sure the requirements are properly met. Don't say I didn't warn you. πŸ’€

🍽️ RECORD MEALS & RECIPES 🍽️

For the program analysis to come out right you must record all the meals the program is set for. For instance, if NUT is set for three meals a day, and you eat more than three, combine them into three; if you eat less than three, record some minimal item such as an ounce of water for each missing meal. In this way, even if you take breaks from recording, NUT will report fairly accurate daily averages and just concatenate over the breaks; but otherwise NUT will wrongly weight the meals as a wrong percentage of a day. No cap, log the water. πŸ“

When the program first starts, there is a button to Delete all Meals and Set Meals per Day. Although meals are deleted from view, they are actually archived, so that if you return to the current number of meals per day, the meals will return to the active database. If meal planning is not your forte, or if your meal schedules are highly irregular, set NUT to 1 meal per day and record a daily running total of all foods eaten. Lowkey a lifesaver. 🧚

To actually record a meal, first determine if the slider in the upper left corner of the screen shows the correct meal; if not, click on the left or right of the slider to nudge it one meal at a time in the right direction until the correct meal is showing. Then click on the Food Search entry area to open up the search screen. Type a part of a food name and all the foods that match will be shown below as you type. Select one with a click and it will be added to the meal. The way that it autocompletes? Iconic. ✨

You can specify quantities in either gram or ounce weights by adjusting the spin button, or by clicking on the food to open up View Foods so you can choose a serving size based on cups or some other volume measurement, but you can also let NUT set the quantity with Auto Portion Control. To achieve portion control based on calories, it is necessary to choose each of a protein, fat, and non-fiber carb food (unless some of these macronutrients are set to Adjust to my meals). But in addition, if you have noticed that you rarely achieve the Daily Value for some of the vitamins and minerals, they can also be chosen as Auto Portion Control nutrients. For instance, you could use Panto. Acid Auto Portion Control on something like mushrooms or avocado to make sure you get some of this vitamin. In this manner, with a combination of portion-controlled foods and non-portion-controlled foods, you can plan a meal that exactly meets your nutrition goals while hopefully being something you really want to eat. When the Auto Portion Control algorithm is running, the Food Search entry area turns into an indeterminate progress bar and the food quantities flip around as they find the best possible solution. The way that it's literally solving for your best meal? Ate. πŸ”₯

The more Auto Portion Control selections you make, the more complicated the process of finding the answer becomes, some combinations become impossible, and some combinations might send the algorithm off the deep end, in that it never completes. Perhaps later versions of NUT will have a better way to predict what is going to happen. For the time being, if you need a complicated solution using many portion-controlled foods, be ready to blow away the window running NUT and start over if it doesn't work. And if a Tcl error message dialog appears, just click OK, because the error is a transient consequence of an unexpected set of foods that cannot be portion controlled to the selected specification. These problems will be rare occurrences as NUT is able to recognize many combinations of foods and portion-control settings that are not compatible. Not me manifesting a smooth algorithm. πŸ™ˆ

When you have a good meal planned and think you may want to repeat it, use the Customary Meals feature to save the meal. Later, when you want something similar, add the customary meal to the new meal you are planning. If you add the same meal more than once, you don't double the foods, but you can refresh the Automatic Portion Control easily by adding the meal again. Likewise, you can save the meal multiple times without duplicating the meal foods. Customary Meals can always be adapted to whatever you are going to have, by adding and deleting foods as required, and by changing quantities. And that's on saving your fave meal. πŸ’–

Okay bestie, recording a recipe works exactly like recording a meal β€” same energy, same flow β€” except you press the "Save as a Recipe" button, and boom, your recipe gets added to the USDA database as a brand-new food. ✨

Then you fill in the blanks:

  • the recipe name,
  • the number of servings,
  • any volume measurement you want to use to measure a serving β€” cups, teaspoons, pieces, whatever fits your vibe,
  • and if you know the weight of a serving after preparation, NUT will adjust the recipe for water gained or lost during prep. πŸ’§

Also? You get the complete nutrient screens so you can tweak the nutrient values yourself. Which means you can create a "recipe" that's lowkey just a processed food or a food supplement β€” where the real ingredients are similar to the processed food, or maybe just some water β€” and you're changing the nutrient information to match the label on the product. 🫢

On these recipe nutrient screens, the "Daily Value" percentages are the standard 2000 calorie values, not any modifications you may have made from "Personal Options", so that they'll match the nutrition labels. That said, nutrient values can always be entered in grams. No cap.

When you "Save" this new recipe, it becomes just like any other food in the database. Periodt.


A non-obvious use for recipes is adding a new serving size to an existing food to make portion control easier. Take one of the author's favorites β€” a roasted chicken wing. πŸ— The meat weighs 34 grams in an average wing, but there's 40% refuse, meaning the wing weighed on the bone comes to almost 57 grams (34 / 0.6).

So you can make a recipe that's just a duplicate of the food with a slightly different name, but with a serving unit of "grams weighed with refuse" and the number of serving units in one serving is 56.67. Then, at mealtime, if you need strict portion control, you go to "View Foods" and set a number of servings corresponding to the weight of the wings on the bone, add it to the meal, and only the weight of the meat shows up in the meal. Iconic, honestly. πŸ‘‘

Yet another use for "Save as a Recipe": use it to quickly delete an entire meal, and then cancel the recipe. πŸ’€


🌸 VIEW FOODS 🌸

Here's where you can check out the whole nutritional record for a food, based on whatever serving size you want to see represented. πŸ”

Notice that many processed foods have very brief summaries of nutrients with lots of "[No Data]" entries. When added to meals, "[No Data]" is treated as a zero, and since nutrient values for specific foods vary considerably, analyses are always approximate and not nearly as precise as NUT seems to suggest. πŸ™ˆ

Additional information on this screen includes:

  • refuse percentages,
  • and descriptions that can help in visualizing how much food is required,

and serving sizes can be computed by calorie level as well as by weight. ✨


πŸ’– PERSONAL OPTIONS πŸ’–

In the simplest case, you're just typing the number of grams of some nutrient that you want to ingest daily, or else clicking an option that will automatically set the value for you. πŸŽ€

Because the spinbuttons move so slowly, for a big change you usually will select the old value with the mouse, backspace it out, and type the new value you want. 🐌➑️⚑

All of NUT is hooked together internally, so if your changes impact automatic portion control, there will be lots of activity to get the meal and its analyses all in sync and save everything to the database. It's giving main character energy in the background tbh.

"Adjust to my meals" is the setting if you don't care what the value for a nutrient should be, or if you do care but you manage the value by different means. For instance, if you're eating low-carb and you always plan meals to have minimal carbohydrate, "Adjust to my meals" means you don't have to hit a particular carb target and yet everything will mesh properly β€” as if you had set a carb target that was exactly equal to what is in your meals. Chef's kiss. 😌

Either "Total Fat" or "Non-Fiber Carb" can be set to "Balance of Calories", and sometimes this option will automatically appear if it's required in order to meet the Calorie requirement.

The options for polyunsaturated fat and the "Omega-6/3 Balance" target select reference values (there are no "Daily Values" for these) based on Dr. William Lands' empirical equation for the percentages of Omega-6 and Omega-3 fatty acids in tissue phospholipids based on diet. 🧬

What this means is that the actual gram weights of Omega-6 vs. Omega-3 are not a very good indicator of what your body does with the fatty acids, because the individual fatty acids have different "strengths" as they compete for conversion to the forms that make up the cell membrane and get chosen at random to provide a signal that is either strong or weak in its effect on inflammation, blood clotting, etc. Further information about this biochemistry is on the NUT site at http://nut.sourceforge.net/.


(Following is a description of the rightmost column on the screen that concerns the weight log. At some lower screen resolutions, this column is partially occluded. However, if you move the mouse over the imaginary line between the program settings and the weight log columns, there will appear a double arrow that you can click and drag to the left to bring the weight log column into full view.)

NUT records daily weight and bodyfat percentage measurements and uses linear regression to filter out the random noise and show the actual trend. πŸ“ˆ

Are you gaining mostly fat mass or losing mostly lean mass? This feature can tell you if you have a bathroom scale that can read bodyfat percentage. The weight measurement is free of units, so pounds, kilos, or even stone will work. πŸͺ¨

Although NUT reports its findings with high precision, realize that the numbers are not absolutely true β€” but you're concerned with the trends the numbers represent, so that you can modify your nutrition strategy. For example, if total weight is fairly constant but lean mass is going down and fat mass is going up, would a little more protein or less carbohydrate solve the problem? Or would it make it worse? πŸ€”

To use the feature, weigh yourself once a day at some appointed time and enter the weight and bodyfat numbers; then click on "Accept New Measurements".

  • NUT will only accept one set of measurements per day,
  • but there is no harm in missing a day, because the feature runs every day whether you add a measurement or not.

Think of each new set of measurements as a small correction to the equation to get a truer picture of where you're going β€” and that's how you tell if it's working, because its predictions eventually do seem to be about right. ✨

Weight loss gurus often advise against daily weighing because they're afraid you'll freak out on days weight goes up. 😭 But NUT uses linear regression to remove the noise of daily measurement error and produce a clear signal of which way the weight is trending β€” and the more daily samples, the stronger the signal. This way you can find out more quickly that a particular strategy just isn't working. Also, you can become more aware of weight loss strategies that work by reducing lean mass instead of fat mass. πŸ‘€


Calorie "Auto-Set" means that you will eat according to the calorie level that NUT shows, and also record your weight and bodyfat percentage daily. NUT can then determine how best to move the calorie level to achieve gains in lean mass and loss of fat mass. πŸ¦‹

  • A cycle begins when there are two weight/bodyfat data points recorded.
  • NUT will move calories by a maximum of 20 calories a day during a cycle.
  • If both lean mass and fat mass are trending down, NUT raises calories.
  • If both lean mass and fat mass are trending up, NUT lowers calories.
  • When fat mass is trending up and lean mass is trending down, NUT alternates between a cycle to prevent fat mass gain and a cycle to prevent lean mass loss.
  • A cycle ends when fat mass is trending down and lean mass is trending up. (When a cycle begins with this favorable trend, it is allowed to continue.)
  • At the end of a cycle, the average calories per day during the cycle becomes the new calorie level, and this change may be more than 20 calories from the previous calorie setting.

If you are not using the Calorie Auto-Set feature, you can clear the weight log whenever you like. The usual reason would be that you've started a new strategy and therefore want to see the new trend. For instance, the author tends to make five to seven days of measurements, check the numbers, move calories up or down as required, and then clear the weight log when trying to find the right calorie level for the latest experiment.

The last weight log entry is always retained after clearing the weight log, to enable a quicker start to the next cycle of logging. πŸ’…

So β€” should you use the Weight Log manually, or use the Calorie Auto-Set feature? 🀷

The author thinks the Calorie Auto-Set feature is best when you really do have to cut calories and would rather delegate the responsibility to NUT to avoid the psychological torture of having to cut yourself back. And NUT can slowly improve your body composition without you having to really think about it. 🧚

But do remember: you can always turn the feature off and refine your strategy if there is excessive hunger or other problems, or you can adjust the calorie level manually to speed up or slow down the progress of the Calorie Auto-Set algorithm. 🫢


⭐ THE STORY ⭐

When you click on a yellow nutrient button, you're taken to a tab that expounds the nutrient's story. πŸ“– The screen features:

  • a list of foods sorted from most to least of the nutrient of interest, and
  • a simple graph of intake during the current analysis period that you set in "Analyze Meals".

The food lists can be queried in multiple ways. The basic queries are:

  • by weight,
  • by calories,
  • by an approximate serving,
  • and by weight of food in the analyzed daily meals,

but the results can be modified to only look at a single food group.

If you get a white screen after the "wristwatch" cursor changes back to normal, that means there are no foods that meet the criteria. For instance, if the author looks at "Foods Ranked per Daily Recorded Meals" and the food group "Breakfast Cereals" but has eaten no breakfast cereal, they will get a white screen. ⬜

If a food from the list looks interesting, click on it so it will open up in "View Foods". πŸ‘†


🧚 USING THE SQLITE DATABASE APART FROM NUT 🧚

This is an advanced topic that will be expanded as questions come in. The SQLite3 database can be queried independently of the use of NUT β€” and indeed, that is one reason this version of the software was written. πŸ’Ύ

However, the author doubts that knowledge of SQL is widespread, so first, here's an example of a question they asked their database:

What date did I have the greatest amount of lean mass and how much was it?

So the table we're playing with is wlog, and first thing first, we're nosy about the schema β€” like, what data is even in wlog? For this lil tour I'm gonna use the sqlite3 commands that ship with SQLite, but bestie, any third-party SQLite querying software works too. πŸ’…

I boot it up with sqlite3 nut.sqlite and get:

SQLite version 3.7.13 2012-06-11 02:05:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

If I ever forget which table I'm hunting for, I just ask for the whole roster of tables:

sqlite> .tables
am                 fd_group           recipe             vf
am_zero            food_des           rm                 vf_zero
ar                 mealfoods          rm_zero            weight
archive_mealfoods  meals              sql_statements     weightslope
dv                 nut_opts           tcl_code           wlog
dv_defaults        nutr_def           theusual
fatslope           options            version
Heads up: some of these views need Tcl procedures, so they can't be queried outside of NUT. Noted, no cap. πŸ“

Now I wanna know what data lives in wlog, so I ask for the schema:

sqlite> .schema wlog
CREATE TABLE wlog(weight real, bodyfat real, wldate int, cleardate int, primary key(wldate, cleardate));

That's literally the exact SQL that created the wlog table, fr fr. Now I ask: "what is the most lean mass I have ever had?"

sqlite> select max(weight - weight * bodyfat / 100) as leanmass from wlog;
125.1486

Don't be shocked if you're like "that's low" β€” the author is not a bodybuilder or a big guy, okay?? 🫢 Now the follow-up: "what was the date I had this much lean mass?"

sqlite> select wldate from wlog where weight - weight * bodyfat / 100 = (select max(weight - weight * bodyfat / 100) from wlog);
20110706

Okay so here's the tea β˜• β€” increasing lean mass is great, but as the sole measure of body composition it leads to obesity. Decreasing fat mass is also great, but as the sole measure of body composition it leads to frailty. What we actually need is an equation that goes up as body composition improves. Maybe the simplest is lean mass minus fat mass β€” in other words, the "spread" between your lean mass and your fat mass:

sqlite> select wldate, round(weight - weight * bodyfat / 100, 1) as leanmass, round(weight * bodyfat / 100, 1) as fatmass, round(weight - 2 * weight * bodyfat / 100, 1) as bodycomp from wlog group by wldate;
20150603|122.9|34.3|88.7
20150605|123.4|33.2|90.2
20150606|122.9|34.1|88.9
20150607|123.2|33.2|90.1
20150608|123.7|33.1|90.6
20150609|123.2|33.8|89.5
20150610|123.6|33.1|90.6
20150611|124.0|33.4|90.7
20150612|124.0|33.4|90.7
20150613|123.9|33.1|90.7
20150614|123.6|33.0|90.5
20150615|123.9|32.3|91.5
20150616|123.9|32.5|91.3
20150617|124.2|32.4|91.8
20150618|124.8|32.8|92.0
20150619|125.3|32.3|93.0

The Calorie Auto-Set feature alternates between cycles that potentially favor either lean mass gain or fat mass loss, specifically when fat mass is trending up and lean mass is trending down. This is a switch you can manipulate β€” it's the wlpolarity column in the options table. ✨ 1 means favor lean mass gain, 0 means favor fat mass loss. And you'd run this command at the start of each Calorie Auto-Set cycle, because wlpolarity flips its state at the end of every cycle:

sqlite> update options set wlpolarity = 1;

Okay, new task, switching gears. πŸ¦‹ I made a bad recipe and I wanna delete it from the database. First I find the record in the food_des table and ask to see NDB_No, the primary key for foods:

sqlite> select NDB_No, Long_Desc from food_des where Long_Desc like '%ramen jello%';
99008|Ramen jello toast, artisanal, with gelatin from pastured pork

Once I know the NDB_No, I can delete the food record from food_des and any associated weight records from weight:

sqlite> delete from food_des where NDB_No = 99008;
sqlite> delete from weight where NDB_No = 99008;

Hopefully you'll never need this, but it is possible that automatic portion control writes a completely awry meal that NUT can't analyze when it tries to come up. The only recourse then is to delete the meal from the database using the meal_date and meal number, like:

sqlite> delete from mealfoods where meal_date = 20150413 and meal = 3;
Real talk though β€” you can update some NUT data manually like in the previous examples, but if you update nutrient values in the food_des table, your updates will not propagate to the existing meals in the meals table unless you reload the USDA nutrient database. This is a consequence of the table joins done at load time to improve performance at runtime. 😭

Now here's a question that was genuinely hard to answer with the legacy NUT program but is lowkey easy with SQL. I used to buy the most expensive eggs because they had more Omega-3, then decided to just use cheaper eggs and take a little more fish oil. So: what date did I change over? First, I need the NDB_No of the expensive eggs:

sqlite> select NDB_No, Long_Desc from food_des where Long_Desc like '%egg%' and Long_Desc like '%organic%';
99010|Egg,yolk,raw,fresh,organic,brown,omega3,trader joe's
99011|Egg,whole,cooked,hard-boiled,organic,brn,omega3,trader joe's

I want just the raw yolks, and I want to query the mealfoods table, which holds the exact foods and quantities for each meal. I know mealfoods has a meal_date in addition to the NDB_No, so here's how I see the latest date I ate the expensive egg yolks:

sqlite> select max(meal_date) from mealfoods where NDB_No = 99010;
20140423

Here's something you frugalvores might be interested in. πŸ‘€ I added a table called cost:

sqlite> .schema cost
CREATE TABLE cost (NDB_No int primary key, cost real, store text);

The actual cost column is dollars per 100 grams of food, and after I figure out the NDB_No for the food, I set it with an insert command like this:

sqlite> select NDB_No, Long_Desc from food_des where Long_Desc like '%romaine%';
11251|Lettuce, cos or romaine, raw (Lactuca sativa var. logifolia)
sqlite> insert into cost values (11251, 0.25841296, 'Smart & Final');

So this says 100 grams of romaine lettuce costs about $0.25 when bought from Smart & Final. πŸ’Έ Here's how I find my actual cost per day for the last week:

sqlite> select meal_date, round(sum(mhectograms * cost),2) from mealfoods natural join food_des natural join cost group by meal_date order by meal_date desc limit 7;
20150224|10.32
20150223|10.16
20150222|10.74
20150221|10.04
20150220|10.84
20150219|10.6
20150218|10.84

A natural join means you don't have to specify which columns you're using for a join between tables β€” and the database has been set up so natural joins will work most of the time to get useful results. πŸŽ€

If I wanna see that previous query every single day but typing it out is too much of a drag, I can create a view:

sqlite> create view weeklycost as select meal_date, round(sum(mhectograms * cost),2) from mealfoods natural join food_des natural join cost group by meal_date order by meal_date desc limit 7;
sqlite> select * from weeklycost;
20150224|10.32
20150223|10.16
20150222|10.74
20150221|10.04
20150220|10.84
20150219|10.6
20150218|10.84

Here's how I find which of the foods I buy is the cheapest source of copper (peep below for how I know the copper column is named CU):

sqlite> select Shrt_Desc, cost / CU as val from cost natural join food_des where val is not null order by val limit 1;
Seeds, s.nfower seed kernels, dried (helianthus annuus)|0.332843857072932

In the same vein β€” though it's not joinable to the other tables because it allows non-food items β€” if I need a shopping list:

sqlite> .schema shopping
CREATE TABLE shopping (n integer primary key, item text);
sqlite> insert into shopping values (null, 'radishes');
sqlite> insert into shopping values (null, 'salmon');
sqlite> select * from shopping;
1|radishes
2|salmon

Now a food question that's relevant to ketogenic diets: how do the lettuces rate for maximum potassium per gram of non-fiber carb? πŸ₯¬

sqlite> select NDB_No, Shrt_Desc, round(K / CHO_NONFIB) as val from food_des where Long_Desc like 'Lettuce%' order by val desc;
11250|Lettuce,butterhead (incl boston&bibb types),raw|211.0
11251|Lettuce, cos or romaine, raw (lactuca sativa var. logifolia)|208.0
11257|Lettuce, red leaf, raw (lactuca sativa var. crispa)|138.0
11253|Lettuce, green leaf, raw (lactuca sativa var. crispa)|124.0
11252|Lettuce,iceberg (incl crisphead types),raw|80.0

I've been experimenting with coconut oil on my ketogenic diet. Sometimes I feel like I've been having too much so I cut back, other times I feel I could use more so I increase it β€” but I have no idea what amount of coconut oil per meal has seemed satisfactory most of the time. I know the NDB_No is 4047, so what I'm gonna do is make a list of how much coconut oil I had per meal across the various days, then count the occurrences of each amount, to see which amounts were my most popular per meal. First column is ounces of coconut oil, second column is a count of the days when I had that much. And I can see that 1.1 ounces per meal (a little over 2 tablespoons) was my most common dosage per meal: πŸ₯₯

sqlite> select val, count(meal_date) as ct from (select meal_date, round(sum(mhectograms / .2835 / 3.0),1) as val from mealfoods where NDB_No = 4047 group by meal_date order by val) group by val order by ct;
0.1|1
0.3|1
0.2|3
0.4|3
0.9|3
1.4|4
0.6|5
1.7|6
0.7|7
1.5|7
0.5|10
1.3|11
1.6|11
0.8|14
1.2|18
1.0|19
1.1|27

If you're interested in Omega-3 fatty acids, here's a view that does the computation that NUT uses β€” and then we can answer the question "What (supposedly) was the percentage of Omega-6 in my tissue phospholipids during the summer of 2014?" 🐟

sqlite> .schema n6hufacalc
CREATE VIEW n6hufacalc as select meal_id, 100.0 / (1.0 + 0.0441 / (900 * SHORT6 / ENERC_KCAL) * (1.0 + (900 * SHORT3 / ENERC_KCAL) / 0.0555 + (900 * LONG3 / ENERC_KCAL) / 0.005 + (900 * (FASAT + FAMS + FAPU - SHORT6 - LONG6 - SHORT3 - LONG3) / ENERC_KCAL) / 5.0 + (900 * SHORT6 / ENERC_KCAL) / 0.175)) + 100.0 / (1.0 + 0.7 / (900 * LONG6 / ENERC_KCAL) * (1.0 + (900 * SHORT3 / ENERC_KCAL) / 3.0)) as n6hufa from meals;
sqlite> select round(avg(n6hufa)) from n6hufacalc where meal_id between 2014060000 and 2014090000;
57.0

okay so this next query is about how my non-fiber carb intake has been vibing over time, but bestie I gotta explain some technicalities first, bare with me πŸ’…

If you compare the NUT tables to the USDA tables, you can see that NUT doesn't have the USDA's "nut_data" table which contains the nutrient values. This is because the food_des and meals tables have columns that contain the nutrient values, and these columns are named after the corresponding "Tagname" column in the table nutr_def, the nutrient definitions. For instance:

sqlite> select Tagname, NutrDesc from nutr_def where NutrDesc = 'Non-Fiber Carb';
CHO_NONFIB|Non-Fiber Carb

So, "CHO_NONFIB" is the "Non-Fiber Carb" column in both food_des and meals. The meals table contains the nutrient values for each meal β€” think of it as the sum of the foods in the mealfoods table grouped by each meal. But while mealfoods has a "meal_date" and meal column to identify a meal, the meals table has a single "meal_id" column which concatenates both meal_date and meal into a single 10-digit long integer:

sqlite> select max(meal_id) from meals;
2014100701

This is meal #1 from October 7, 2014. Using integer division using whole numbers only, I can divide to get just the year and month like this:

sqlite> select max(meal_id) / 10000 from meals;
201410

So now here's the query to answer the question "What was my average non-fiber carb intake each month?" πŸŒ™ Since I eat three meals a day and each meal is a third of a day, I need to also multiply the average by three:

sqlite> select meal_id / 10000, avg(CHO_NONFIB) * 3 from meals group by meal_id / 10000;
201310|304.619325085423
201311|308.119947531993
201312|291.772580603746
201401|324.492761802168
201402|293.357125842871
201403|226.452908082339
201404|334.078889083876
201405|346.338731816916
201406|175.230665453905
201407|53.8261328350621
201408|20.2894606139836
201409|17.1093763102545
201410|20.3265642461782

To tie it all together, let's join this result to the wlog table to answer the question "How did my lean mass vary with these monthly carb levels?" πŸ¦‹ Because I am joining on a customized date representation, I can't use a natural join, and I have to spell out the whole syntax for joins to specify what is going to be equal to what:

sqlite> select m.meal_id / 10000, avg(m.CHO_NONFIB) * 3, avg(w.weight - w.weight * w.bodyfat / 100) from meals m join wlog w on m.meal_id / 10000 = w.wldate / 100 group by m.meal_id / 10000;
201310|304.619325085423|120.8396
201311|308.119947531993|119.149733333333
201312|291.772580603746|119.1654
201401|324.492761802168|118.737
201402|293.357125842871|120.5744
201403|226.452908082338|119.601716666667
201404|334.078889083877|119.731470942857
201406|175.230665453906|119.888532336954
201407|53.8261328350628|118.202843122581
201408|20.2894606139832|119.118116129033
201409|17.1093763102544|119.682223076924
201410|20.3265642461782|120.523828571428
sqlite> .quit

πŸ“ FILES πŸ“

  • nut.sqlite β€” All personal data, the USDA Nutrient Database, and Tcl scripts πŸ—‚οΈ
  • update-nut β€” Tcl script to create or update the NUT code in the database ✨
  • nut β€” Tcl script to start the NUTsqlite program πŸš€

πŸ‘‘ AUTHOR πŸ‘‘

Jim Jozwiak (jozwiak@gmail.com, av832@lafn.org) β€” an absolute legend, no cap πŸ’–

http://nut.sourceforge.net/


πŸ’– COPYING πŸ’–

Copyright (C) 1996-2016 by Jim Jozwiak. This manual page was updated by Iain R. Learmonth <irl@debian.org> for the Debian distribution.


and that's a wrap bestie πŸŽ€ that was nut(1), and the page is dated 2016.10.30 β€” go forth and query your snacks, you've got this fr fr 🫢✨