From b48f7a8667535bd215465b8ddce6722acaf7d863 Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:43:47 +0530 Subject: [PATCH] fix(import): Lose It amounts are portions, not servings Lose It's Calories and nutrient columns are the totals for the logged amount, but the importer stored that amount (50 grams) as the serving count, which the diary multiplies by: 50 g of oats came in as 9,250 kcal. Store one serving with the amount and unit as the portion, like the Cronometer and spreadsheet importers. --- scripts/nutrition-import-loseit.test.js | 21 +++++++++++++++++++++ server/lib/nutrition-import/loseit.js | 9 ++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 scripts/nutrition-import-loseit.test.js diff --git a/scripts/nutrition-import-loseit.test.js b/scripts/nutrition-import-loseit.test.js new file mode 100644 index 00000000..b65a17a2 --- /dev/null +++ b/scripts/nutrition-import-loseit.test.js @@ -0,0 +1,21 @@ +/** + * Lose It! food-log export. Calories and nutrients are the totals for the + * logged amount (50 g of oats is 185 kcal), so the amount must not become the + * serving count that the diary multiplies by. + */ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { parseLoseit } from '../server/lib/nutrition-import/loseit.js'; + +const CSV = [ + 'Date,Name,Icon,Type,Quantity,Units,Calories,Deleted,Fat (g),Protein (g),Carbohydrates (g),Saturated Fat (g),Sugars (g),Fiber (g),Cholesterol (mg),Sodium (mg)', + '08/27/2025,Porridge Oats,Cereal,Breakfast,50.0,Grams,185,0,3.90,6,29.50,0.60,0.45,4.40,0,15', +].join('\n') + '\n'; + +test('the logged amount is the portion, not the number of servings', () => { + const [item] = parseLoseit(CSV); + assert.equal(item.quantity, 1); + assert.equal(item.portion, 50); + assert.equal(item.unit, 'Grams'); + assert.equal(item.nutrition.calories, 185); +}); diff --git a/server/lib/nutrition-import/loseit.js b/server/lib/nutrition-import/loseit.js index 356680e7..b7bd15a9 100644 --- a/server/lib/nutrition-import/loseit.js +++ b/server/lib/nutrition-import/loseit.js @@ -39,7 +39,9 @@ export function parseLoseit(text) { const calories = parseNumber(getField(row, 'calories')); if (calories == null) continue; - const quantity = parseNumber(getField(row, 'quantity')) ?? 1; + // Calories and nutrients are the totals for the logged amount, so the item is one + // serving with the amount as its portion (as the other importers do). + const amount = parseNumber(getField(row, 'quantity')); const unit = getField(row, 'units') || null; const nutrition = { calories }; @@ -58,8 +60,9 @@ export function parseLoseit(text) { mealLabel: getField(row, 'type') || '', name, brand: null, - quantity, - portion: unit ? `${quantity} ${unit}` : null, + quantity: 1, + portion: amount, + unit, nutrition, notes: null, sourceRow: row._rowNum,