public ExtractAndPPGModel CalculatePPG(GrainsToBeCalculated grainsInTable, string mashVolume) { double extractPPG = 0; double grainPPG = 0; double points = 0; //This loops through all items in the tableview that was passed in foreach (MashTableRowDataModel element in grainsInTable.ListViewOfGrains) { var grainNameLabel = element.SelectedGrain.GrainName; var ppg = element.SelectedGrain.PPG; var grainWeight = element.Pounds; //Calculate the points added to the gravity from ViewCell points = (ppg - 1) * 1000; //Depending on grain Type, add the points added to correct ppg type if (element.SelectedGrain.Type == "Extract") { extractPPG += Convert.ToDouble(grainWeight) * points / Convert.ToDouble(mashVolume); } else { grainPPG += Convert.ToDouble(grainWeight) * points / Convert.ToDouble(mashVolume); } } //return ExtractAndPPGModel containing the extract and grain ppg types return(new ExtractAndPPGModel() { extract = Convert.ToInt16(extractPPG), grain = Convert.ToInt16(grainPPG) }); }
public void CalculateSRM(object sender, EventArgs e) { var check = grainsAddedListView.ItemsSource as ObservableCollection <MashTableRowDataModel>; if (check.Count == 0) { DisplayAlert("No Grains", "You must add grains to calculate the color of your beer.", "OK"); } else if (mashVolumeEntry.Text != "0" || mashVolumeEntry.Text != "") { GrainsToBeCalculated grainsToBeCalculated = new GrainsToBeCalculated { ListViewOfGrains = grainsAddedListView.ItemsSource, MashVolume = mashVolumeEntry.Text }; MashCalculatedModel calculations = new MashCalculatedModel { PPGModel = calculateGravity.CalculatePPG(grainsToBeCalculated, mashVolumeEntry.Text), }; calculateSRM.MashCalculatedModelCalculator(calculations, grainsToBeCalculated, mashVolumeEntry.Text); Navigation.PushModalAsync(new MashCalculatedResultsPageXAML(calculations)); } else { DisplayAlert("Volume Error", "You must enter a mash volume.", "OK"); } }
public void MashCalculatedModelCalculator(MashCalculatedModel model, GrainsToBeCalculated calculate, string mashVolume) { double totalMCU = 0; double MCU = 0; //Loop through TableView to calculate srm color of all grains in TableView passed in from MashCalculatorPage foreach (MashTableRowDataModel element in calculate.ListViewOfGrains) { var srm = element.SelectedGrain.srmColor; var grainWeight = element.Pounds; //Calculate MCU of grain in ViewCell MCU = (Convert.ToDouble(srm) * Convert.ToDouble(grainWeight)) / Convert.ToDouble(mashVolume); //Add MCU from calculated grain ViewCell totalMCU += MCU; } //Calculate the exact SRM color double srmColor = 1.4922 * (Math.Pow(MCU, 0.6859)); //Convert the exact SRM to an integer Int16 srmInt = Convert.ToInt16(srmColor); //Convert srmInteger to a color Color finalColor = ConvertIntToColor(srmInt); //Set model srmInteger and srmColor model.srmInt = srmInt; model.srmColor = finalColor; }
void CalculateIBU(object sender, EventArgs e) { if (mashVolumeEntry.Text != "0") { GrainsToBeCalculated calculate = new GrainsToBeCalculated { MashVolume = mashVolumeEntry.Text, ListViewOfGrains = grainsAddedListView.ItemsSource }; MashCalculatedModel results = new MashCalculatedModel { PPGModel = calculateGravity.CalculatePPG(calculate, mashVolumeEntry.Text), }; calculateSRM.MashCalculatedModelCalculator(results, calculate, mashVolumeEntry.Text); Navigation.PushModalAsync(new MashCalculatedResultsPage(results)); } else { DisplayAlert("Volume Error", "You must enter a mash volume.", "OK"); } }