示例#1
0
        public static SRM CalculateSRM(Recipe recipe)
        {
            var srm = new SRM{SrmId = recipe.RecipeId};
            foreach (var mashStep in recipe.MashSteps)
            {
                var volume = recipe.Volume;
                if (mashStep.Volume > 0)
                    volume = mashStep.Volume;
                foreach (var fermentable in mashStep.Fermentables)
                {
                    srm.Standard += Math.Round(Formulas.MaltColourUnits(fermentable.Amount, fermentable.Lovibond, volume), 0);
                    srm.Morey += Math.Round(Formulas.Morey(fermentable.Amount, fermentable.Lovibond, volume), 0);
                    srm.Mosher += Math.Round(Formulas.Morey(fermentable.Amount, fermentable.Lovibond, volume), 0);
                    srm.Daniels += Math.Round(Formulas.Daniels(fermentable.Amount, fermentable.Lovibond, volume), 0);
                }
            }

            return srm;
        }
示例#2
0
 public static IBU CalculateIBU(Recipe recipe)
 {
     var og = recipe.OG;
     var ibu = new IBU {IbuId = recipe.RecipeId};
    
     var tinseth = 0.0;
     var rager = 0.0;
     foreach (var boilStep in recipe.BoilSteps)
     {
         var tinsethUtilisation = Formulas.TinsethUtilisation(og, boilStep.Length);
         var ragerUtilisation = Formulas.RangerUtilisation(boilStep.Length);
         foreach (var hop in boilStep.Hops)
         {
             var tinasethMgl = Formulas.TinsethMgl(hop.Amount, hop.AAValue, recipe.Volume);
             tinseth += Formulas.TinsethIbu(tinasethMgl, tinsethUtilisation);
             rager += Formulas.RangerIbu(hop.Amount, ragerUtilisation, hop.AAValue, recipe.Volume, og);
         }
     }
     
     ibu.Tinseth = Math.Round(tinseth, 1);
     ibu.Standard = Math.Round(tinseth, 1);
     ibu.Rager = Math.Round(rager, 1);
     return ibu;
 }
        private static void AddRecipe(Recipe recipe, DbConnection context, DbTransaction transaction)
        {

            context.Execute("INSERT Recipes(RecipeId,Volume,Notes,OG,FG,Efficiency,TotalBoilTime) " +
                            "VALUES(@RecipeId,@Volume,@Notes,@OG,@FG,@Efficiency,@TotalBoilTime);",
                new
                {
                    recipe.RecipeId,
                    recipe.Volume,
                    recipe.Notes,
                    recipe.OG,
                    recipe.FG,
                    recipe.Efficiency,
                    recipe.TotalBoilTime
                }, transaction);

            SetStepNumber(recipe);
            if (recipe.MashSteps != null)
            {
                foreach (var mashStep in recipe.MashSteps)
                {
                    mashStep.RecipeId = recipe.RecipeId;
                    AddMashStep(context, transaction, mashStep);
                }
            }
            if (recipe.BoilSteps != null)
            {
                foreach (var boilStep in recipe.BoilSteps)
                {
                    boilStep.RecipeId = recipe.RecipeId;
                    AddBoilStep(context, transaction, boilStep);
                }
            }

            if (recipe.FermentationSteps != null)
            {
                foreach (var fermentationStep in recipe.FermentationSteps)
                {
                    fermentationStep.RecipeId = recipe.RecipeId;
                    AddFermentationStep(context, transaction, fermentationStep);
                }
            }
        }
        private void GetMashSteps(DbConnection context, Recipe recipe)
        {
            var mashSteps = context.Query<MashStep>(
                "SELECT * FROM MashSteps WHERE RecipeId = @RecipeId;", new { recipe.RecipeId });
            foreach (var mashStep in mashSteps)
            {
                var mashStepFermentables = context.Query<MashStepFermentable, Fermentable, MashStepFermentable>(
                    "SELECT * FROM MashStepFermentables m " +
                    "LEFT JOIN Fermentables f ON m.FermentableId = f.FermentableId " +
                    "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (mashStepFermentable, fermentable) =>
                    {
                        mashStepFermentable.Fermentable = fermentable;
                        return mashStepFermentable;
                    }, new { recipe.RecipeId, mashStep.StepNumber }, splitOn: "FermentableId");
                mashStep.Fermentables = mashStepFermentables.ToList();

                var mashStepHops = context.Query<MashStepHop, Hop, MashStepHop>(
                   "SELECT * FROM MashStepHops m " +
                   "LEFT JOIN Hops h ON m.HopId = h.HopId " +
                   "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (mashStepHop, hop) =>
                   {
                       mashStepHop.Hop = hop;
                       return mashStepHop;
                   }, new { recipe.RecipeId, mashStep.StepNumber }, splitOn: "HopId");
                mashStep.Hops = mashStepHops.ToList();

                var mashStepOthers = context.Query<MashStepOther, Other, MashStepOther>(
                  "SELECT * FROM MashStepOthers m " +
                  "LEFT JOIN Others o ON m.OtherId = o.OtherId " +
                  "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (mashStepOther, other) =>
                  {
                      mashStepOther.Other = other;
                      return mashStepOther;
                  }, new { recipe.RecipeId, mashStep.StepNumber }, splitOn: "OtherId");
                mashStep.Others = mashStepOthers.ToList();
            }
            recipe.MashSteps = mashSteps.ToList();
        }
        private void GetBoilSteps(DbConnection context, Recipe recipe)
        {
            var boilSteps = context.Query<BoilStep>(
                "SELECT * FROM BoilSteps WHERE RecipeId = @RecipeId;", new { recipe.RecipeId });
            foreach (var boilStep in boilSteps)
            {
                var boilStepFermentables = context.Query<BoilStepFermentable, Fermentable, BoilStepFermentable>(
                    "SELECT * FROM BoilStepFermentables b " +
                    "LEFT JOIN Fermentables f ON b.FermentableId = f.FermentableId " +
                    "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (boilStepFermentable, fermentable) =>
                    {
                        boilStepFermentable.Fermentable = fermentable;
                        return boilStepFermentable;
                    }, new { recipe.RecipeId, boilStep.StepNumber }, splitOn: "FermentableId");
                boilStep.Fermentables = boilStepFermentables.ToList();

                var boilStepHops = context.Query<BoilStepHop, Hop, BoilStepHop>(
                   "SELECT * FROM BoilStepHops b " +
                   "LEFT JOIN Hops h ON b.HopId = h.HopId " +
                   "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (boilStepHop, hop) =>
                   {
                       boilStepHop.Hop = hop;
                       return boilStepHop;
                   }, new { recipe.RecipeId, boilStep.StepNumber }, splitOn: "HopId");
                boilStep.Hops = boilStepHops.ToList();

                var boilStepOthers = context.Query<BoilStepOther, Other, BoilStepOther>(
                  "SELECT * FROM BoilStepOthers b " +
                  "LEFT JOIN Others o ON b.OtherId = o.OtherId " +
                  "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (boilStepOther, other) =>
                  {
                      boilStepOther.Other = other;
                      return boilStepOther;
                  }, new { recipe.RecipeId, boilStep.StepNumber }, splitOn: "OtherId");
                boilStep.Others = boilStepOthers.ToList();
            }
            recipe.BoilSteps = boilSteps.ToList();
        }
        private void GetFermentationSteps(DbConnection context, Recipe recipe)
        {
            var fermentationSteps = context.Query<FermentationStep>(
               "SELECT * FROM FermentationSteps WHERE RecipeId = @RecipeId;", new { recipe.RecipeId });
            foreach (var fermentationStep in fermentationSteps)
            {
                var fermentationStepFermentables = context.Query<FermentationStepFermentable, Fermentable, FermentationStepFermentable>(
                    "SELECT * FROM FermentationStepFermentables fs " +
                    "LEFT JOIN Fermentables f ON fs.FermentableId = f.FermentableId " +
                    "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (fermentationStepFermentable, fermentable) =>
                    {
                        fermentationStepFermentable.Fermentable = fermentable;
                        return fermentationStepFermentable;
                    }, new { recipe.RecipeId, fermentationStep.StepNumber }, splitOn: "FermentableId");
                fermentationStep.Fermentables = fermentationStepFermentables.ToList();

                var fermentationStepHops = context.Query<FermentationStepHop, Hop, FermentationStepHop>(
                   "SELECT * FROM FermentationStepHops fs " +
                   "LEFT JOIN Hops h ON fs.HopId = h.HopId " +
                   "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (fermentationStepHop, hop) =>
                   {
                       fermentationStepHop.Hop = hop;
                       return fermentationStepHop;
                   }, new { recipe.RecipeId, fermentationStep.StepNumber }, splitOn: "HopId");
                fermentationStep.Hops = fermentationStepHops.ToList();

                var fermentationStepOthers = context.Query<FermentationStepOther, Other, FermentationStepOther>(
                  "SELECT * FROM FermentationStepOthers fs " +
                  "LEFT JOIN Others o ON fs.OtherId = o.OtherId " +
                  "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (fermentationStepOther, other) =>
                  {
                      fermentationStepOther.Other = other;
                      return fermentationStepOther;
                  }, new { recipe.RecipeId, fermentationStep.StepNumber }, splitOn: "OtherId");
                fermentationStep.Others = fermentationStepOthers.ToList();

                var fermentationStepYeasts = context.Query<FermentationStepYeast, Yeast, FermentationStepYeast>(
                 "SELECT * FROM FermentationStepYeasts f " +
                 "LEFT JOIN Yeasts y ON f.YeastId = y.YeastId " +
                 "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (fermentationStepYeast, yeast) =>
                 {
                     fermentationStepYeast.Yeast = yeast;
                     return fermentationStepYeast;
                 }, new { recipe.RecipeId, fermentationStep.StepNumber }, splitOn: "YeastId");
                fermentationStep.Yeasts = fermentationStepYeasts.ToList();
            }
            recipe.FermentationSteps = fermentationSteps.ToList();
        }
 private void GetSpargeStep(DbConnection context, Recipe recipe)
 {
     var spargeSteps = context.Query<SpargeStep>(
         "SELECT * FROM SpargeSteps WHERE RecipeId = @RecipeId;", new { recipe.RecipeId });
     var spargeStep = spargeSteps.SingleOrDefault();
     if (spargeStep == null) return;
     var spargeStepHops = context.Query<SpargeStepHop, Hop, SpargeStepHop>(
          "SELECT * FROM SpargeStepHops fs " +
          "LEFT JOIN Hops h ON fs.HopId = h.HopId " +
          "WHERE RecipeId = @RecipeId and StepNumber = @StepNumber;", (spargeStepHop, hop) =>
          {
              spargeStepHop.Hop = hop;
              return spargeStepHop;
          }, new { recipe.RecipeId, spargeStep.StepNumber }, splitOn: "HopId");
     spargeStep.Hops = spargeStepHops.ToList();
     recipe.SpargeStep = spargeStep;
 }
 private void GetRecipeSteps(DbConnection context, Recipe recipe)
 {
     GetMashSteps(context, recipe);
     GetBoilSteps(context, recipe);
     GetFermentationSteps(context, recipe);
     GetSpargeStep(context, recipe);
 }
 private static void UpdateFermentationSteps(DbConnection context, DbTransaction transaction, Recipe recipe)
 {
     //Remove mash steps 
     context.Execute("DELETE FROM FermentationSteps WHERE RecipeId = @RecipeId;", new { recipe.RecipeId }, transaction);
     context.Execute("DELETE FROM FermentationStepFermentables WHERE RecipeId = @RecipeId;", new { recipe.RecipeId }, transaction);
     context.Execute("DELETE FROM FermentationStepHops WHERE RecipeId = @RecipeId;", new { recipe.RecipeId }, transaction);
     context.Execute("DELETE FROM FermentationStepOthers WHERE RecipeId = @RecipeId ;", new { recipe.RecipeId }, transaction);
     //Add mash steps
     foreach (var fermentationStep in recipe.FermentationSteps)
     {
         fermentationStep.RecipeId = recipe.RecipeId;
         AddFermentationStep(context, transaction, fermentationStep);
     }
 }
        private static void SetStepNumber(Recipe recipe)
        {
            var stepNumber = 1;
            foreach (var mashStep in recipe.MashSteps)
            {
                mashStep.StepNumber = stepNumber;
                stepNumber++;
            }

            //TODO: Validate that this is null on insert/update
            if (recipe.SpargeStep != null)
            {
                recipe.SpargeStep.StepNumber = stepNumber;
                stepNumber++;
            }

            foreach (var boilStep in recipe.BoilSteps.OrderByDescending(b => b.Length))
            {
                boilStep.StepNumber = stepNumber;
                stepNumber++;
            }
            foreach (var fermentationStep in recipe.FermentationSteps.OrderByDescending(f => f.Length))
            {
                fermentationStep.StepNumber = stepNumber;
                stepNumber++;
            }
        }
 private static void UpdateRecipe(DbConnection context, DbTransaction transaction, Recipe recipe)
 {
     context.Execute("UPDATE Recipes set Volume = @Volume, Notes = @Notes,OG = @OG,FG = @FG, Efficiency = @Efficiency, TotalBoilTime = @TotalBoilTime " +
                    "WHERE RecipeId = @RecipeId", recipe, transaction);
     SetStepNumber(recipe);
     UpdateMashSteps(context, transaction, recipe);
     UpdateBoilSteps(context, transaction, recipe);
     UpdateFermentationSteps(context, transaction, recipe);
 }
        public void Add_Gets_Added()
        {
            var newBeer = new Beer
            {
                Name = "TestBeer" + DateTime.Now.Ticks,
                BeerStyleId = 1,
                ForkeOfId = 17,
                SRM = new SRM
                {
                    Daniels = 1,
                    Morey = 1,
                    Mosher = 1,
                    Standard = 1
                },
                ABV = new ABV
                {
                    Advanced = 2,
                    AdvancedAlternative = 2,
                    AlternativeSimple = 2,
                    Miller = 2,
                    Simple = 2,
                    Standard = 2,
                },
                IBU = new IBU
                {
                    Rager = 20,
                    Standard = 20,
                    Tinseth = 25
                },

            };
            var newRecipe = new Recipe
            {
                Volume = 20,
                Notes = "SOmething",
                Efficiency = 75,
                MashSteps = new List<MashStep>
                {
                    new MashStep
                    {
                        StepNumber = 1,
                        Temperature = 56,
                        Type = "Infusion",
                        Notes = "Notes",
                        Length = 10,
                        Volume = 20,
                        Fermentables = new List<MashStepFermentable>
                        {
                             new MashStepFermentable{Amount = 1000,Lovibond = 23,PPG = 12, FermentableId = 2},
                             new MashStepFermentable{Amount = 1000,Lovibond = 23,PPG = 12, FermentableId = 1},
                        },
                        Hops = new List<MashStepHop>
                        {
                            new MashStepHop
                            {
                                Amount = 30,
                                AAValue = 5,
                                HopFormId = 1,
                                HopId = 1,
                            }
                        },
                        Others = new List<MashStepOther>
                        {
                            new MashStepOther
                            {
                                Amount = 10,
                                OtherId = 1,
                            }
                        }

                    },
                     new MashStep
                    {
                        StepNumber = 2,
                        Temperature = 56,
                        Type = "Infusion",
                        Notes = "Notes",
                        Length = 10,
                        Volume = 20
                    }
                },
                BoilSteps = new List<BoilStep>
                {
                    new BoilStep
                    {
                        StepNumber = 3,
                        Volume = 21,
                        Notes = "Notes",
                        Length = 60,
                              Fermentables = new List<BoilStepFermentable>
                        {
                             new BoilStepFermentable{Amount = 1000,Lovibond = 23,PPG = 12, FermentableId = 2},
                             new BoilStepFermentable{Amount = 1000,Lovibond = 23,PPG = 12, FermentableId = 1},
                        },
                        Hops = new List<BoilStepHop>
                        {
                            new BoilStepHop
                            {
                                Amount = 30,
                                AAValue = 5,
                                HopFormId = 1,
                                HopId = 1,
                            }
                        },
                        Others = new List<BoilStepOther>
                        {
                            new BoilStepOther
                            {
                                Amount = 10,
                                OtherId = 1,
                            }
                        }
                    }
                },
                FermentationSteps = new List<FermentationStep>
                {
                    new FermentationStep
                    {
                        StepNumber = 4,
                        Length = 14,
                        Temperature = 21,
                        Notes = "Somehting more",
                        Volume = 19,
                               Fermentables = new List<FermentationStepFermentable>
                        {
                             new FermentationStepFermentable{Amount = 1000,Lovibond = 23,PPG = 12, FermentableId = 2},
                             new FermentationStepFermentable{Amount = 1000,Lovibond = 23,PPG = 12, FermentableId = 1},
                        },
                        Hops = new List<FermentationStepHop>
                        {
                            new FermentationStepHop
                            {
                                Amount = 30,
                                AAValue = 5,
                                HopFormId = 1,
                                HopId = 1,
                            }
                        },
                        Others = new List<FermentationStepOther>
                        {
                            new FermentationStepOther
                            {
                                Amount = 10,
                                OtherId = 1,
                            }
                        },
                        Yeasts = new List<FermentationStepYeast>
                        {
                            new FermentationStepYeast
                            {
                                Amount = 1,
                                YeastId = 1,
                            }
                        } 
                    }
                }

            };
            newBeer.Recipe = newRecipe;
            _beerRepository.Add(newBeer);
            var beer = _beerRepository.GetSingle(newBeer.BeerId);
            Assert.NotNull(beer);
            Assert.True(beer.Name.Any());
        }
示例#13
0
        public static ABV CalculateABV(Recipe recipe)
        {
            var abv = new ABV
            {
                AbvId = recipe.RecipeId,
                Miller = Math.Round(Formulas.MillerABV(recipe.OG, recipe.FG), 2),
                Simple = Math.Round(Formulas.SimpleABV(recipe.OG, recipe.FG), 2),
                Advanced = Math.Round(Formulas.AdvancedABV(recipe.OG, recipe.FG), 2),
                AdvancedAlternative = Math.Round(Formulas.AdvancedAlternativeABV(recipe.OG, recipe.FG), 2),
                AlternativeSimple = Math.Round(Formulas.SimpleAlternativeABV(recipe.OG, recipe.FG), 2),
                Standard = Math.Round(Formulas.MicrobrewitABV(recipe.OG, recipe.FG), 2)
            };

            return abv;
        }
示例#14
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);
        }