Provided by: nutsqlite_2.0.6-3_all
NAME
nut - analyze meals with the USDA Nutrient Database
SYNOPSIS
nut
DESCRIPTION
NUT allows you to 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. 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. 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/. 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. 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. "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". 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. 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. "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. "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. "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. 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. 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. 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. 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. 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. 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. 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. 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. 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 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. 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. Record a recipe in exactly the same way as a meal, but press the "Save as a Recipe" button to add your recipe as a new food to the USDA database. Then, fill in the blanks with the recipe name, the number of servings, any volume measurement you want to use to measure a serving, such as cups, teaspoons or pieces, etc., and if you know the weight of a serving after preparation, the recipe will be adjusted for water gained or lost in preparation. Furthermore, you will be presented with the complete nutrient screens so you can adjust the nutrient values. This allows you to create a "recipe" that is actually just a processed food or food supplement, where the real ingredients are similar to the processed food or maybe just some water, but you are changing the nutrient .nfrmation to match the label on a 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 will match the nutrition labels; however, nutrient values can always be entered in grams. When you "Save" this new recipe, it becomes just like any other food in the database. A non-obvious use for recipes is to add a new serving size to an existing food to make portion control easier. Take one of my favorites, a roasted chicken wing. The meat weighs 34 grams in an average wing but there is 40% refuse, meaning that the wing weighed on the bone comes to almost 57 grams (34 / 0.6). So, you can make a recipe that is 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 and add it to the meal, and only the weight of the meat shows up in the meal. 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 many "[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 .nfrmation 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 are 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. "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 are 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. Either "Total Fat" or "Non-Fiber Carb" can be set to "Balance of Calories" and sometimes this option will automatically appear if 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 .nfammation, blood clotting, etc. Further .nfrmation about this biochemistry is on the NUT site at <A HREF="http://nut.sourceforge.net/">http://nut.sourceforge.net/</A>. (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 are 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 where you are going, and that's how you tell if it is working, because its predictions eventually do seem to be about right. Weight loss gurus often advise against daily weighing because they are afraid you will 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 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 have started a new strategy and therefore want to see the new trend. For instance, I tend 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 I am trying to find the right calorie level for my 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? I think 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 that 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 are 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 I look at "Foods Ranked per Daily Recorded Meals" and the food group "Breakfast Cereals" but I have eaten no breakfast cereal, I 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 I receive questions about it. The SQLite3 database can be queried independently of the use of NUT and indeed, that is one reason I wrote this version of the software. However, I doubt that knowledge of SQL is widespread, so first I will give an example of a question I asked my database: What date did I have the greatest amount of lean mass and how much was it? The table we will use is "wlog", and first we are curious about the schema, or what data is in "wlog". For this example, I will use the "sqlite3" commands that come with SQLite, but any third-party software for querying SQLite will work. I start up the software with the command "sqlite3 nut.sqlite" and get the output: SQLite version 3.7.13 2012-06-11 02:05:22 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> If I need to be reminded what table I am looking for, I ask to see a list of all the 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 (It should be noted that some of the views require Tcl procedures and thus can't be queried apart from NUT.) Now I ask what data is in the "wlog" table by asking to see the "schema": sqlite> .schema wlog CREATE TABLE wlog(weight real, bodyfat real, wldate int, cleardate int, primary key(wldate, cleardate)); This is the exact SQL that created the wlog table. Now I ask "what is the most lean mass I have had?" sqlite> select max(weight - weight * bodyfat / 100) as leanmass from wlog; 125.1486 (Don't be shocked if you think this is too low; I am not a bodybuilder or a big guy.) Now I ask, "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 Increasing lean mass is great, but as the sole measure of body composition it leads to obesity; decreasing fat mass is great, but as the sole measure of body composition it leads to frailty. What we need is an equation which increases in value as body composition improves. Perhaps the simplest is lean mass minus fat mass, or in other words, what is the "spread" between the lean mass and the fat mass quantities: 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 in the cases when fat mass is trending up and lean mass is trending down. This is a switch you can manipulate, and it is the wlpolarity column in the table options. "1" means favor lean mass gain, "0" means favor fat mass loss, and you would issue the command at the start of each Calorie Auto-Set cycle because the wlpolarity switches its state at the end of each cycle: sqlite> update options set wlpolarity = 1; Now, let's turn to a different task. I've created a bad recipe and I want to 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 When 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 will never need to do this, but it is possible that automatic portion control could write a completely awry meal that NUT is unable to 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 this: sqlite> delete from mealfoods where meal_date = 20150413 and meal = 3; Although you can update some of the NUT data manually as in the previous examples, do note that 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 as a consequence of the table joins done at load time to improve performance at runtime. Now a question which was difficult to answer with the legacy NUT program but fairly easy to answer with SQL. I was buying the most expensive eggs because they had more Omega-3, but decided to use cheaper eggs and just take a little more fish oil. 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 to see 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'); This says that 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 the columns you are using for a join between tables, and the database has been set up so that natural joins will work most of the time to get useful results. If I want to see the previous query every day but it is too much of a drag to type it in every time, 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 (see 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, although 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 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 I've been having too much and I cut back and other times I feel I could use more, so I increase it, but I do not have any 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 am going to do is to make a list of how much coconut oil I had per meal for the various days and then count the occurrences of each amount of coconut oil, to see what were my most popular amounts of coconut oil per meal. The first column is ounces of coconut oil and the second column is a count of the days when I had that much. 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 The next query concerns how non-fiber carb has varied in my diet, but I need to explain a few technicalities first. 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) 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. 2016.10.30 nut(1)