private void MenuItem_SettingsMashEfficiency(object sender, RoutedEventArgs e) { var meWindow = new MashEffeciency((int)(gfc.MashEfficiency * 100d)); meWindow.ShowDialog(); double me = 0; if (meWindow.Gravity != 0 && meWindow.Volume != 0) { var measuredPts = GravityAlgorithms.GetPoints(meWindow.Gravity, meWindow.Volume); var possiblePts = Grist.Where(x => x.Stage == FermentableStage.Mash). Sum(v => v.GU); me = measuredPts / possiblePts; MessageBox.Show(String.Format("Mash efficiency updated to {0:F0}%, will update settings", me * 100)); } else if (meWindow.MashEfficiency != 0) { me = (double)meWindow.MashEfficiency / 100d; } else { return; } gfc.MashEfficiency = me; WpfApplication1.Properties.Settings.Default["MashEfficiency"] = me; WpfApplication1.Properties.Settings.Default.Save(); recalculateGrainBill(); recalculateIbu(); }
private void recalculateIbu() { var Gravity = GravityAlgorithms.GetGravity(Volumes.PreBoilVolume, Grist.Where(x => x.Stage == FermentableStage.Mash).ToList(), GrainfatherCalculator.mashEfficiency); var ibu = IbuAlgorithms.CalcIbu(BoilHops.Where(x => x.Stage == HopAdditionStage.Boil), Gravity, Volumes.PostBoilVolume); var highIbu = ibu + IbuAlgorithms.IBU_TOLERANCE * ibu; var lowIbu = ibu - IbuAlgorithms.IBU_TOLERANCE * ibu; IbuLabel.Content = string.Format("IBU: {0:F0} - {1:F0} ({2:F0})", lowIbu, highIbu, ibu); }
private void recalculateGrainBill() { var sum = Grist.Sum(g => g.Amount); if (sum != 100) { sum = -1; GrainBillSize = 0; } else { var preBoilTappOffLoss = (Volumes.PreBoilTapOff / (Volumes.PreBoilVolume + Volumes.PreBoilTapOff)); var totalGravity = GravityAlgorithms.GetTotalGravity(Volumes.PostBoilVolume, OriginalGravity); Volumes.ColdSteepVolume = 0; var l = new List <GristPart>(); foreach (var grain in Grist) { grain.GU = totalGravity * ((double)grain.Amount / 100d); if (grain.Stage == FermentableStage.ColdSteep) { grain.AmountGrams = GravityAlgorithms.GetGrainWeight(grain.GU, grain.FermentableAdjunct.Potential, ColdSteep.COLDSTEEP_EFFICIENCY); Volumes.ColdSteepVolume += ColdSteep.GetColdSteepWaterContibution(grain.AmountGrams); } if (grain.Stage == FermentableStage.Mash) { grain.AmountGrams = GravityAlgorithms.GetGrainWeight(grain.GU, grain.FermentableAdjunct.Potential, gfc.MashEfficiency); grain.AmountGrams += (int)Math.Round(grain.AmountGrams * preBoilTappOffLoss); } if (grain.Stage == FermentableStage.Fermentor) { grain.AmountGrams = GravityAlgorithms.GetGrainWeight(grain.GU, grain.FermentableAdjunct.Potential, 1); var boilerLossPercent = GrainfatherCalculator.GRAINFATHER_BOILER_TO_FERMENTOR_LOSS / (Volumes.PostBoilVolume); grain.AmountGrams -= (int)Math.Round(boilerLossPercent * grain.AmountGrams); } if (grain.Stage == FermentableStage.Boil) { grain.AmountGrams = GravityAlgorithms.GetGrainWeight(grain.GU, grain.FermentableAdjunct.Potential, 1); } l.Add(grain); } GrainBillSize = Grist.Where(x => x.Stage == FermentableStage.Mash).Sum(x => x.AmountGrams); foreach (var grain in l) { Grist.Remove(grain); Grist.Add(grain); } if (GrainBillSize > GrainfatherCalculator.SMALL_GRAINBILL || GrainBillSize == 0) { TopUpMashWaterVolumeTextBox.Visibility = Visibility.Hidden; TopUpMashWaterVolumeLabel.Visibility = Visibility.Hidden; } else { TopUpMashWaterVolumeTextBox.Visibility = Visibility.Visible; TopUpMashWaterVolumeLabel.Visibility = Visibility.Visible; } foreach (GridViewColumn c in MaltsGridView.Columns) { c.Width = 0; //set it to no width c.Width = double.NaN; //resize it automatically } double ecb = ColorAlgorithms.CalculateColor(Grist.ToList(), Volumes); string refString = ColorAlgorithms.GetReferenceBeer(ecb); ColorLabel.Content = String.Format("Color [ECB]: {0:F1} eqv. to {1}", ecb, refString); recalculateIbu(); var ol = BoilHops.OrderBy(x => x).ToList(); BoilHops.Clear(); foreach (HopAddition h in ol) { hopsCompositionChanged(h); } } updateGuiText(); }
private void MenuItem_FilePrint(object sender, RoutedEventArgs e) { PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; // Display the dialog. This returns true if the user presses the Print button. Nullable <Boolean> print = pDialog.ShowDialog(); if (print == true) { FlowDocument doc = new FlowDocument(); doc.PageHeight = pDialog.PrintableAreaHeight; doc.PageWidth = pDialog.PrintableAreaWidth; doc.ColumnWidth = doc.PageWidth; doc.FontFamily = new FontFamily("Courier"); doc.FontSize = 11; #region Print mash part StringBuilder strbcs = new StringBuilder(); StringBuilder strbmash = new StringBuilder(); StringBuilder strbferm = new StringBuilder(); foreach (GristPart g in Grist) { switch (g.Stage) { case FermentableStage.ColdSteep: strbcs.Append("Add " + g.ToString() + "\n"); break; case FermentableStage.Mash: strbmash.Append("Add " + g.ToString() + "\n"); break; case FermentableStage.Fermentor: strbferm.Append("Add " + g.ToString() + "\n"); break; default: break; } } var recepieHeading = new Paragraph(new Bold(new Run(String.Format("Recipe for {0}, approx. {1:F1} L in fermentor", NameTextBox.Text, Volumes.FinalBatchVolume)))); var mashHeading = new Paragraph(new Bold(new Run("Mash"))); mashHeading.FontSize = recepieHeading.FontSize = 18; doc.Blocks.Add(recepieHeading); doc.Blocks.Add(mashHeading); if (Grist.Any(x => x.Stage == FermentableStage.ColdSteep)) { Paragraph pcs = new Paragraph(); pcs.Inlines.Add(new Bold(new Run("Cold steep, 24 before brew start:\n"))); pcs.Inlines.Add(new Run(strbcs.ToString())); doc.Blocks.Add(pcs); } Paragraph pcsw = new Paragraph(); pcsw.Inlines.Add(new Run(String.Format("Mix with {0:F1} cold water\n", (Volumes.ColdSteepVolume * (1 - ColdSteep.COLDSTEEP_VOLUME_TO_SPARGE_RATIO))))); Paragraph pm = new Paragraph(); pm.Inlines.Add(new Bold(new Run("Normal step mash:\n"))); pm.Inlines.Add(new Run(String.Format("Add {0:F1} liters of water to Grainfather for mashing\n\n", GrainfatherCalculator.CalcMashVolume(GrainBillSize)))); pm.Inlines.Add(new Run(strbmash.ToString())); doc.Blocks.Add(pm); StringBuilder strmp = new StringBuilder(""); foreach (Domain.MashProfileStep mss in MashProfileList) { strmp.Append("Mash at " + mss.ToString() + "\n"); } Paragraph pmp = new Paragraph(); pmp.Inlines.Add(new Bold(new Run("Mash profile:\n"))); pmp.Inlines.Add(new Run(strmp.ToString())); pmp.Inlines.Add(new Run(String.Format("\nSparge with {0:F1} liters of 78 C water\n", GrainfatherCalculator.CalcSpargeWaterVolume(GrainBillSize, (Volumes.PreBoilVolume), TopUpMashWater)))); var prbg = GravityAlgorithms.GetGravity( Grist.Where(x => x.Stage == FermentableStage.Mash).Sum(x => x.GU), Volumes.PreBoilVolume); var pobg = GravityAlgorithms.GetGravity(Grist.Where(x => x.Stage != FermentableStage.Fermentor).Sum(x => x.GU), Volumes.PostBoilVolume); pmp.Inlines.Add(new Run(String.Format("\nExpected post-mash gravity is {0:F3}. Post-mash volume shall be {1:F1} liters", prbg, Volumes.PreBoilVolume + Volumes.PreBoilTapOff))); if (Volumes.PreBoilTapOff > 0) { pmp.Inlines.Add(new Run(String.Format("\nTap off {0:F1} liters wort before boil start. Expected Pre-boil volume is {1:F1} liters.\n", Volumes.PreBoilTapOff, Volumes.PreBoilVolume))); } doc.Blocks.Add(pmp); #endregion #region Boiling part var boilingHeader = (new Paragraph(new Bold(new Run("Boiling")))); boilingHeader.FontSize = 16; doc.Blocks.Add(boilingHeader); StringBuilder strbboil = new StringBuilder(""); StringBuilder str_ferms_boil = new StringBuilder(""); foreach (GristPart g in Grist) { if (g.Stage == FermentableStage.Boil) { str_ferms_boil.Append("Add " + g.ToString() + "\n"); } } StringBuilder strbdry = new StringBuilder(""); foreach (HopAddition g in BoilHops) { switch (g.Stage) { case HopAdditionStage.Boil: strbboil.Append("Add " + g.ToString() + "\n"); break; case HopAdditionStage.Fermentation: strbboil.Append("Add " + g.ToString() + "\n"); break; default: break; } } Paragraph pbh = new Paragraph(); pbh.Inlines.Add(new Bold(new Run("Hop additions:\n"))); pbh.Inlines.Add(new Run(strbboil.ToString())); var vm = Volumes.PreBoilVolume; var vcs = Volumes.ColdSteepVolume; foreach (GristPart g in Grist) { if (g.Stage == FermentableStage.ColdSteep) { pbh.Inlines.Add(new Run(String.Format("Add the runnings of {0} to the boil 10 minutes before end\n", g.FermentableAdjunct.Name))); } } if (Grist.Any(x => x.Stage == FermentableStage.ColdSteep)) { pbh.Inlines.Add(new Run(String.Format("\nSparge all runnings with {0:F1}L water.\n", Volumes.ColdSteepVolume * (ColdSteep.COLDSTEEP_VOLUME_TO_SPARGE_RATIO)))); } pbh.Inlines.Add(new Run(String.Format("Expected post-boil gravity is {0:F3}. Post-boil volume shall be {1:F1} liters", pobg, Volumes.PostBoilVolume))); doc.Blocks.Add(pbh); #endregion #region Print others part StringBuilder strbo = new StringBuilder(""); foreach (OtherIngredient g in OtherIngredientsList) { strbo.Append(String.Format("Add " + g.ToString() + "\n")); } if (OtherIngredientsList.Any()) { var othersHeading = new Paragraph(new Bold(new Run("Others"))); othersHeading.FontSize = 16; doc.Blocks.Add(othersHeading); Paragraph po = new Paragraph(new Run(strbo.ToString())); doc.Blocks.Add(po); } #endregion doc.Name = "FlowDoc"; // Create IDocumentPaginatorSource from FlowDocument IDocumentPaginatorSource idpSource = doc; // Call PrintDocument method to send document to printer pDialog.PrintDocument(idpSource.DocumentPaginator, NameTextBox.Text); } }
private void updateGuiText() { EstAttenTextBox.Text = EstAtten.ToString(); MashVolumeLabel.Content = new StringBuilder() .AppendFormat("Mash water volume: {0:F1} liters", GrainfatherCalculator.CalcMashVolume(GrainBillSize)).ToString(); SpargeVolumeLabel.Content = new StringBuilder() .AppendFormat("Sparge water volume: {0:F1} liters", GrainfatherCalculator.CalcSpargeWaterVolume(GrainBillSize, (Volumes.PreBoilVolume + Volumes.PreBoilTapOff), TopUpMashWater)) .ToString(); PreBoilDataLabel.Content = new StringBuilder() .AppendFormat("Expected pre-boil gravity is {0:F3}, preboil volume {1:F1} liters", GravityAlgorithms.GetGravity( Grist.Where(x => (x.Stage != FermentableStage.Fermentor && x.Stage != FermentableStage.ColdSteep)).Sum(x => x.GU), Volumes.PreBoilVolume), Volumes.PreBoilVolume).ToString(); PostBoilDataLabel.Content = new StringBuilder() .AppendFormat("Expected post-boil gravity is {0:F3}, postboil volume {1:F1} liters", OriginalGravity, Volumes.PostBoilVolume).ToString(); AbvDataLabel.Content = new StringBuilder().AppendFormat("Expected ABV is {0:F2} %", Abv.CalculateAbv(OriginalGravity, ((OriginalGravity - 1) * (1 - ((double)EstAtten / 100))) + 1)).ToString(); }