Esempio n. 1
0
        public RecipeProjectedOutcome GetRecipeProjectedOutcome(float recipeSize, List <IFermentableIngredient> fermentableIngredients,
                                                                List <IHopIngredient> hopIngredients,
                                                                BeerRecipeCore.Yeast.Yeast yeast, int extractionEfficiency)
        {
            if (recipeSize == 0)
            {
                throw new ArgumentException("Recipe size cannot be zero.", nameof(recipeSize));
            }
            if (fermentableIngredients.Count == 0)
            {
                throw new ArgumentException("There are no fermentable ingredients.", nameof(fermentableIngredients));
            }
            if (hopIngredients.Count == 0)
            {
                throw new ArgumentException("There are no hop ingredients.", nameof(hopIngredients));
            }

            var og = AlcoholUtility.GetOriginalGravity(fermentableIngredients, recipeSize, extractionEfficiency);
            var fg = AlcoholUtility.GetFinalGravity(og, yeast.Characteristics.Attenuation);

            return(new RecipeProjectedOutcome
            {
                Abv = AlcoholUtility.GetAlcoholByVolume(og, fg),
                ColorSrm = (int)Math.Round(ColorUtility.GetColorInSrm(fermentableIngredients, recipeSize), 0, MidpointRounding.ToEven),
                Ibu = BitternessUtility.GetBitterness(hopIngredients, recipeSize, og)
            });
        }
        public void GetGravityPointTest()
        {
            const double specificGravity = 1.037;
            var          gravityUnit     = AlcoholUtility.GetGravityUnit(specificGravity);

            gravityUnit.Should().Be(37);
        }
Esempio n. 3
0
 public void UpdateBatchOutcome()
 {
     if (m_recordedGravityReadings.Count > 1)
     {
         AlcoholByVolume = AlcoholUtility.GetAlcoholByVolume((float)m_recordedGravityReadings.First().Value, (float)m_recordedGravityReadings.Last().Value);
         AlcoholByWeight = AlcoholUtility.GetAlcoholByWeight(m_alcoholByVolume);
     }
 }
        public void GetAlcoholByVolumeTest()
        {
            const float originalGravity = 1.045f;
            const float finalGravity    = 1.006f;
            var         actualAbv       = AlcoholUtility.GetAlcoholByVolume(originalGravity, finalGravity);

            actualAbv.Should().Be(5.15f);
        }
Esempio n. 5
0
        public void UpdateRecipeOutcome()
        {
            if (m_size == 0)
            {
                return;
            }

            OriginalGravity = AlcoholUtility.GetOriginalGravity(m_fermentableIngredients, m_size, ExtractionEfficiency);
            if (OriginalGravityStyleComparison != null)
            {
                OriginalGravityStyleComparison.Compare(m_originalGravity);
            }

            if (m_yeastIngredient != null && m_yeastIngredient.YeastInfo != null)
            {
                FinalGravity = AlcoholUtility.GetFinalGravity(m_originalGravity, m_yeastIngredient.YeastInfo.Characteristics.Attenuation);
                if (FinalGravityStyleComparison != null)
                {
                    FinalGravityStyleComparison.Compare(m_finalGravity);
                }
            }

            if (m_finalGravity != 0)
            {
                AlcoholByVolume = AlcoholUtility.GetAlcoholByVolume(m_originalGravity, m_finalGravity);
                if (AbvStyleComparison != null)
                {
                    AbvStyleComparison.Compare(m_alcoholByVolume);
                }
            }

            AlcoholByWeight = AlcoholUtility.GetAlcoholByWeight(m_alcoholByVolume);
            Bitterness      = BitternessUtility.GetBitterness(m_hopsIngredients, m_size, m_originalGravity);
            if (BitternessStyleComparison != null)
            {
                BitternessStyleComparison.Compare(m_bitterness);
            }
            Color = ColorUtility.GetColorInSrm(m_fermentableIngredients, m_size);
            if (ColorStyleComparison != null)
            {
                ColorStyleComparison.Compare((float)m_color);
            }
        }
        public static Fermentable GetFermentable(XElement fermentableEntry)
        {
            var name              = GetNameFromRecord(fermentableEntry);
            var origin            = fermentableEntry.GetChildElementValue("ORIGIN");
            var notes             = GetNotesFromRecord(fermentableEntry);
            var type              = EnumConverter.Parse <FermentableType>(fermentableEntry.GetChildElementValue("TYPE"));
            var yieldValue        = Convert.ToSingle(fermentableEntry.GetChildElementValue("YIELD"));
            var yield             = type == FermentableType.Grain ? (float?)yieldValue : null;
            var color             = Convert.ToSingle(fermentableEntry.GetChildElementValue("COLOR"));
            var diastaticPower    = float.TryParse(fermentableEntry.GetChildElementValue("DIASTATIC_POWER"), out var diastaticPowerParsed) ? (float?)diastaticPowerParsed : null;
            var potential         = Convert.ToDouble(fermentableEntry.GetChildElementValue("POTENTIAL"));
            var maltCategoryValue = fermentableEntry.Element("malt-category")?.Value;
            var characteristics   = new FermentableCharacteristics(yield, color, diastaticPower)
            {
                Type          = type,
                YieldByWeight = type != FermentableType.Grain ? yieldValue : null,
                GravityPoint  = AlcoholUtility.GetGravityUnit(potential),
                MaltCategory  = maltCategoryValue != null?EnumConverter.Parse <MaltCategory>(maltCategoryValue) : null
            };

            return(new Fermentable(name, characteristics, notes, origin));
        }
        public void GetSpecificAndFinalGravityTest()
        {
            var crystal60InRecipe = new Mock <IFermentableIngredient>();

            crystal60InRecipe.Setup(f => f.Amount).Returns(0.50f);
            crystal60InRecipe.Setup(f => f.FermentableInfo).Returns(new Fermentable("Caramel/Crystal Malt - 60L",
                                                                                    new FermentableCharacteristics(74, 60, 0)
            {
                Type = FermentableType.Grain, GravityPoint = 34
            }, "Test Notes", "US"));

            var chocolateMaltInRecipe = new Mock <IFermentableIngredient>();

            chocolateMaltInRecipe.Setup(f => f.Amount).Returns(1);
            chocolateMaltInRecipe.Setup(f => f.FermentableInfo).Returns(new Fermentable("Chocolate Malt",
                                                                                        new FermentableCharacteristics(60, 350, 0)
            {
                Type = FermentableType.Grain, GravityPoint = 28
            }, "Test Notes", "US"));

            var marisOtterInRecipe = new Mock <IFermentableIngredient>();

            marisOtterInRecipe.Setup(f => f.Amount).Returns(8);
            marisOtterInRecipe.Setup(f => f.FermentableInfo).Returns(new Fermentable("Pale Malt, Maris Otter",
                                                                                     new FermentableCharacteristics(82.5f, 3, 120)
            {
                Type = FermentableType.Grain, GravityPoint = 38
            }, "Test Notes", "US"));

            var fermentablesInRecipe = new List <IFermentableIngredient> {
                crystal60InRecipe.Object, chocolateMaltInRecipe.Object, marisOtterInRecipe.Object
            };
            var actualSpecificGravity = AlcoholUtility.GetOriginalGravity(fermentablesInRecipe, 5, 70);

            actualSpecificGravity.Should().Be(1.049f);
            var actualFinalGravity = AlcoholUtility.GetFinalGravity(actualSpecificGravity, 75);

            actualFinalGravity.Should().Be(1.012f);
        }
Esempio n. 8
0
        internal static List <IHopIngredient> GetHopIngredients(RecipeGenerationInfo recipeGenerationInfo,
                                                                List <IFermentableIngredient> fermentableIngredients)
        {
            if (recipeGenerationInfo.Style.CommonHops.Count == 0)
            {
                throw new InvalidOperationException($"Style {recipeGenerationInfo.StyleName} is missing common hops");
            }

            var originalGravity = AlcoholUtility.GetOriginalGravity(fermentableIngredients, recipeGenerationInfo.Size);
            var hopIngredients  = new List <IHopIngredient>();

            foreach (var commonHop in recipeGenerationInfo.Style.CommonHops)
            {
                hopIngredients.Add(new HopIngredient
                {
                    HopInfo = commonHop.Hop,
                    Time    = commonHop.BoilAdditionTime,
                    Amount  = GetHopAmount(commonHop, recipeGenerationInfo, originalGravity)
                });
            }

            return(hopIngredients);
        }
        public void GetAlcoholByWeightTest()
        {
            var actualAbw = AlcoholUtility.GetAlcoholByWeight(5.12f);

            actualAbw.Should().Be(4.06f);
        }