Fix calculating nutritions
All checks were successful
Build and Deploy / build-and-push (push) Successful in 26s

This commit is contained in:
2026-03-27 23:08:54 +01:00
parent 02fb8a2754
commit 855d17374e
3 changed files with 33 additions and 15 deletions

View File

@@ -30,6 +30,7 @@ export const INGREDIENTS = {
name: 'Bułka grahamka',
category: 'pieczywo',
pantryUnit: 'szt',
weightPerPiece: 70,
purchasePack: { amount: 1, label: '1 bułka ~70 g' },
nutritionPer100g: { kcal: 260, protein: 9, fat: 3, carbs: 48 },
},
@@ -39,6 +40,7 @@ export const INGREDIENTS = {
name: 'Jajka',
category: 'nabial',
pantryUnit: 'szt',
weightPerPiece: 60,
nutritionPer100g: { kcal: 143, protein: 13, fat: 9.5, carbs: 1.1 },
},
mozzarella: {
@@ -104,6 +106,7 @@ export const INGREDIENTS = {
name: 'Pomidor',
category: 'warzywa',
pantryUnit: 'szt',
weightPerPiece: 130,
nutritionPer100g: { kcal: 18, protein: 0.9, fat: 0.2, carbs: 3.9 },
},
pomidorki_koktajlowe: {
@@ -119,6 +122,7 @@ export const INGREDIENTS = {
name: 'Papryka czerwona',
category: 'warzywa',
pantryUnit: 'szt',
weightPerPiece: 160,
nutritionPer100g: { kcal: 31, protein: 1, fat: 0.3, carbs: 6 },
},
ogorek: {
@@ -126,6 +130,7 @@ export const INGREDIENTS = {
name: 'Ogórek',
category: 'warzywa',
pantryUnit: 'szt',
weightPerPiece: 200,
nutritionPer100g: { kcal: 15, protein: 0.7, fat: 0.1, carbs: 3 },
},
czosnek: {
@@ -133,6 +138,7 @@ export const INGREDIENTS = {
name: 'Czosnek',
category: 'warzywa',
pantryUnit: 'szt',
weightPerPiece: 35,
nutritionPer100g: { kcal: 149, protein: 6.4, fat: 0.5, carbs: 33 },
},
kielki_rzodkiewki: {
@@ -343,7 +349,7 @@ export const RECIPES = {
image: 'images/recipes/jajecznica.png',
allowedSlots: ['sniadanie', 'drugie_sniadanie', 'kolacja'],
tags: ['szybkie', 'wysokobiałkowe'],
nutritionPerServing: { kcal: 548, protein: 36, fat: 28, carbs: 36 },
nutritionPerServing: { kcal: 571, protein: 38, fat: 30, carbs: 36 },
ingredients: [
{ ingredientId: 'jajko', amount: 4, unit: 'szt.' },
{ ingredientId: 'oliwa', amount: 5, unit: 'ml' },
@@ -418,7 +424,7 @@ export const RECIPES = {
image: 'images/recipes/serek_owoc.jpg',
allowedSlots: ['sniadanie', 'drugie_sniadanie', 'przekaska'],
tags: ['wegetariańskie', 'wysokobiałkowe', 'szybkie'],
nutritionPerServing: { kcal: 642, protein: 32, fat: 43, carbs: 41 },
nutritionPerServing: { kcal: 629, protein: 31, fat: 43, carbs: 40 },
ingredients: [
{ ingredientId: 'serek_wiejski', amount: 200, unit: 'g' },
{ ingredientId: 'miod', amount: 10, unit: 'g' },
@@ -456,7 +462,11 @@ export function pantryQtyStep(ingredientId) {
export function nutritionForStock(def, stockQty) {
const n = def.nutritionPer100g;
if (!n || !Number.isFinite(stockQty) || stockQty <= 0) return null;
const f = stockQty / 100;
let grams = stockQty;
if (def.pantryUnit === 'szt' && def.weightPerPiece) {
grams = stockQty * def.weightPerPiece;
}
const f = grams / 100;
return {
kcal: Math.round(n.kcal * f),
protein: Math.round(n.protein * f * 10) / 10,