Home
Options

Bakers Percentage Formula including calculations preferments

edited January 7

Hi All, I'm not much of a programmer, and love baking bread.
I found this snippet of code here
https://codereview.stackexchange.com/questions/20328/bread-formula-object

I don't think the calculation is quite correct when it comes to preferments (see below ingredient 5 Pate fermentee)

Preferments like sourdough starter, biga, poolish, levain, pâte fermentée, or even desem are a ratio of flour and water that need to be taken into consideration for the total weight and the hydration of the dough.

I found this site that explains this

https://math.stackexchange.com/questions/4737129/extending-bakers-percentages-to-preferment-recipes

How can I modify the below code (I couldn't find code tags sorry and cant attach linq file) to take into account the preferment please to get a total weight as well as percentage hydration.

void Main()
{
    var formula = new Formula(new[] {
        new Ingredient("Flour, AP", 100m, true),
        new Ingredient("Water, Warm", 70.15m, false),
        new Ingredient("Salt", 3.04m, false),
        new Ingredient("Yeast", .24m, false),
        new Ingredient("Pate fermentee", 2.53m, false)
    });
    var weights = formula.GetWeights(10000m);
}

class Ingredient
{
    public string Name { get; private set; }
    public decimal Percentage { get; private set; }
    public bool IsFlour { get; private set; }

    public Ingredient(string _Name, decimal _Percent, bool _IsFlour)
    {
        this.Name = _Name;
        this.Percentage = _Percent;
        this.IsFlour = _IsFlour;
    }
}

class Formula
{
    private IEnumerable<Ingredient> Ingredients { get; set; }
    public decimal SumPercentages { get; private set; }

    public Formula(IEnumerable<Ingredient> _Ingredients)
    {
        this.Ingredients = _Ingredients;
        this.SumPercentages = _Ingredients.Sum(x => x.Percentage);
    }

    public Dictionary<Ingredient, decimal> GetWeights(decimal weightTotalDough)
    {
        return Ingredients.ToDictionary(k => k, v => (v.Percentage / this.SumPercentages) * weightTotalDough);
    }
}

Comments

  • Options

    Can I correct the code tags somehow?

  • Options

    Use markdown (like StackOverflow)

  • Options

    Thanks Joe, found markdown syntax, and just want to say thanks for your wonderful work and software, I have paid versions of 5,6,7 which has enabled a bumbling idiot like myself to automate some tedious, mundane , repetitive office tasks, albeit with ugly inefficient code but who cares no one can see it it and for the most part does what its told.

    So here is the code from stackexchange by the author Bobson

    void Main()
    {
        var formula = new Formula(new[] {
            new Ingredient("Flour, AP", 100m, true),
            new Ingredient("Water, Warm", 70.15m, false),
            new Ingredient("Salt", 3.04m, false),
            new Ingredient("Yeast", .24m, false),
            new Ingredient("Pate fermentee", 2.53m, false)
        });
        var weights = formula.GetWeights(10000m);
    }
    
    class Ingredient
    {
        public string Name { get; private set; }
        public decimal Percentage { get; private set; }
        public bool IsFlour { get; private set; }
    
        public Ingredient(string _Name, decimal _Percent, bool _IsFlour)
        {
            this.Name = _Name;
            this.Percentage = _Percent;
            this.IsFlour = _IsFlour;
        }
    }
    
    class Formula
    {
        private IEnumerable<Ingredient> Ingredients { get; set; }
        public decimal SumPercentages { get; private set; }
    
        public Formula(IEnumerable<Ingredient> _Ingredients)
        {
            this.Ingredients = _Ingredients;
            this.SumPercentages = _Ingredients.Sum(x => x.Percentage);
        }
    
        public Dictionary<Ingredient, decimal> GetWeights(decimal weightTotalDough)
        {
            return Ingredients.ToDictionary(k => k, v => (v.Percentage / this.SumPercentages) * weightTotalDough);
        }
    }
    
Sign In or Register to comment.