protected override IList <FermentableStepDto> ResolveCore(BoilStep step)
        {
            var fermentableStepDtoList = new List <FermentableStepDto>();

            foreach (var item in step.Fermentables)
            {
                var fermentable = _fermentableElasticsearch.GetSingle(item.FermentableId);
                if (fermentable == null)
                {
                    fermentable = Mapper.Map <Fermentable, FermentableDto>(_fermentableRepository.GetSingle(item.FermentableId));
                }
                var fermentableStepDto = new FermentableStepDto();

                fermentableStepDto.FermentableId = item.FermentableId;
                fermentableStepDto.StepNumber    = item.StepNumber;
                fermentableStepDto.Amount        = item.Amount;
                fermentableStepDto.Supplier      = fermentable.Supplier;
                fermentableStepDto.Type          = fermentable.Type;
                fermentableStepDto.Name          = fermentable.Name;
                fermentableStepDto.PPG           = fermentable.PPG;
                fermentableStepDto.RecipeId      = item.RecipeId;
                if (item.Lovibond == 0)
                {
                    fermentableStepDto.Lovibond = item.Lovibond;
                }
                else
                {
                    fermentableStepDto.Lovibond = fermentable.Lovibond;
                }
                fermentableStepDtoList.Add(fermentableStepDto);
            }

            return(fermentableStepDtoList);
        }
        public double CalculateOGDto(RecipeDto recipe)
        {
            var og = 0.0;

            try
            {
                var fermentables =
                    recipe.Steps.OfType <MashStepDto>()
                    .SelectMany(mashStep => mashStep.Ingredients.OfType <FermentableStepDto>());
                foreach (var fermentable in fermentables)
                {
                    var temp      = (FermentableStepDto)fermentable;
                    var efficency = recipe.Efficiency;
                    //if (fermentable.PPG <= 0)
                    //{
                    var esFermentable = _fermentableElasticsearch.GetSingle(temp.FermentableId);
                    if (esFermentable != null && esFermentable.PPG > 0)
                    {
                        temp.PPG = esFermentable.PPG;
                        if (esFermentable.Type.Contains("Extract") || esFermentable.Type.Contains("Sugar"))
                        {
                            efficency = 100;
                        }
                        //og += Formulas.MaltOG(fermentable.Amount, esFermentable.PPG, recipe.Efficiency, recipe.Volume);
                    }
                    else
                    {
                        var efFermentable = _fermentableRepository.GetSingleAsync(temp.FermentableId).Result;
                        if (efFermentable.PPG != null)
                        {
                            temp.PPG = (int)efFermentable.PPG;
                            if (efFermentable.Type.Contains("Extract") || efFermentable.Type.Contains("Sugar"))
                            {
                                efficency = 100;
                            }
                        }
                        //og += Formulas.MaltOG(fermentable.Amount, (int)efFermentable.PPG, recipe.Efficiency, recipe.Volume);
                    }

                    //}
                    og += Formulas.MaltOG(temp.Amount, (int)temp.PPG, efficency, recipe.Volume);
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.ToString());
                throw;
            }

            return(Math.Round(1 + og / 1000, 4));
        }
示例#3
0
        public static double CalculateOG(Recipe recipe)
        {
            var og = 0.0;

            foreach (var fermentable in recipe.MashSteps.SelectMany(mashStep => mashStep.Fermentables))
            {
                var efficency = recipe.Efficiency;
                //if (fermentable.PPG <= 0)
                //{
                var esFermentable = _fermentableElasticsearch.GetSingle(fermentable.FermentableId);
                if (esFermentable != null && esFermentable.PPG > 0)
                {
                    fermentable.PPG = esFermentable.PPG;
                    if (esFermentable.Type.Contains("Extract") || esFermentable.Type.Contains("Sugar"))
                    {
                        efficency = 100;
                    }
                    //og += Formulas.MaltOG(fermentable.Amount, esFermentable.PPG, recipe.Efficiency, recipe.Volume);
                }
                else
                {
                    var efFermentable = _fermentableRepository.GetSingle(fermentable.FermentableId);
                    if (efFermentable != null && efFermentable.PPG != null)
                    {
                        fermentable.PPG = (int)efFermentable.PPG;
                        if (efFermentable.Type.Contains("Extract") || efFermentable.Type.Contains("Sugar"))
                        {
                            efficency = 100;
                        }
                    }
                    //og += Formulas.MaltOG(fermentable.Amount, (int)efFermentable.PPG, recipe.Efficiency, recipe.Volume);
                }

                //}
                og += Formulas.MaltOG(fermentable.Amount, (int)fermentable.PPG, efficency, recipe.Volume);
            }
            return(Math.Round(1 + og / 1000, 4));
        }