Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling unfermentables; adding cara-pils and lactose. #65

Merged
merged 3 commits into from
Jan 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions src/com/biermacht/brews/utils/BrewCalculator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.biermacht.brews.utils;

import android.util.Log;

import com.biermacht.brews.ingredient.Fermentable;
import com.biermacht.brews.ingredient.Hop;
import com.biermacht.brews.ingredient.Ingredient;
Expand All @@ -10,6 +12,14 @@

public class BrewCalculator {

// Fermentable and unfermentable PPGs for unfermentable - lactose,
// dextrin malt (carapils) and malto-dextrin sugar
// This is only an estimate, assuming unfermentable contributes 30ppg,
// 5 ppg will be fermented and 25ppg will remain in the beer post fermentation

private static final double UNFERMENTABLE_FERMENTABLE_PPG = 5;
private static final double UNFERMENTABLE_UNFERMENTABLE_PPG = 25;

/**
* Beer details calculations http://www.howtobrew.com/section1/chapter5-5.html
* http://homebrew.stackexchange.com/questions/1434/wiki-how-do-you-calculate-original-gravity
Expand Down Expand Up @@ -83,7 +93,10 @@ public static double OriginalFermentableGravityPoints(Recipe r) {
ArrayList<Ingredient> ingredientsList = r.getIngredientList();

for (Ingredient i : ingredientsList) {
gravity_points += FermentableGravityPoints(r, i);
double gp = FermentableGravityPoints(r, i);
//gravity_points += FermentableGravityPoints(r, i);
gravity_points += gp;
Log.v("BEER", "Calling fermentable GP for " + i.getName() + " returned: " + gp);
}
return gravity_points;
}
Expand All @@ -94,7 +107,10 @@ public static double NonFermentableGravityPoints(Recipe r) {
ArrayList<Ingredient> ingredientsList = r.getIngredientList();

for (Ingredient i : ingredientsList) {
gravity_points += NonFermentableGravityPoints(r, i);
//gravity_points += NonFermentableGravityPoints(r, i);
double gp = NonFermentableGravityPoints(r, i);
gravity_points += gp;
Log.v("BEER", "Calling non-fermentable GP for " + i.getName() + " returned: " + gp);
}
return gravity_points;
}
Expand Down Expand Up @@ -149,7 +165,12 @@ public static double FermentableGravityPoints(Recipe r, Ingredient i) {
pts = Units.kilosToPounds(f.getBeerXmlStandardAmount()) * f.getPpg() / Units.litersToGallons(r.getBeerXmlStandardBatchSize());
}
else if (f.getFermentableType().equals(Fermentable.TYPE_SUGAR)) {
pts = Units.kilosToPounds(f.getBeerXmlStandardAmount()) * f.getPpg() / Units.litersToGallons(r.getBeerXmlStandardBatchSize());
if (isUnfermentable(i.getName())) {
pts = UNFERMENTABLE_FERMENTABLE_PPG * Units.kilosToPounds(f.getBeerXmlStandardAmount()) /
Units.litersToGallons(r.getBeerXmlStandardBatchSize());
} else {
pts = Units.kilosToPounds(f.getBeerXmlStandardAmount()) * f.getPpg() / Units.litersToGallons(r.getBeerXmlStandardBatchSize());
}
}
else if (f.getFermentableType().equals(Fermentable.TYPE_GRAIN)) {
if (r.getType().equals(Recipe.EXTRACT)) {
Expand All @@ -163,8 +184,14 @@ else if (f.getFermentableType().equals(Fermentable.TYPE_GRAIN)) {
}
}
else {
// Either a partial mash or all grain recipe
pts = r.getEfficiency() * Units.kilosToPounds(f.getBeerXmlStandardAmount()) * f.getPpg() / Units.litersToGallons(r.getBeerXmlStandardBatchSize()) / 100;

if (isUnfermentable(i.getName())) {
pts = UNFERMENTABLE_FERMENTABLE_PPG * Units.kilosToPounds(f.getBeerXmlStandardAmount())
/ Units.litersToGallons(r.getBeerXmlStandardBatchSize());
} else {
// Either a partial mash or all grain recipe
pts = r.getEfficiency() * Units.kilosToPounds(f.getBeerXmlStandardAmount()) * f.getPpg() / Units.litersToGallons(r.getBeerXmlStandardBatchSize()) / 100;
}
}
}
else {
Expand All @@ -174,12 +201,22 @@ else if (f.getFermentableType().equals(Fermentable.TYPE_GRAIN)) {
return pts;
}

private static boolean isUnfermentable(String name) {
if (name.equalsIgnoreCase("Malto-Dextrine") ||
name.equalsIgnoreCase("Dextrine Malt") ||
name.equalsIgnoreCase("Cara-pils") ||
name.equalsIgnoreCase("Milk Sugar (Lactose)")) {
return true;
}
return false;
}

// Returns the number of non fermentable gravity points for the given ingredient
public static double NonFermentableGravityPoints(Recipe r, Ingredient i) {
if (i.getName().equalsIgnoreCase("Malto-Dextrine") || i.getName().equalsIgnoreCase("Dextrine Malt")) {
return Units.kilosToPounds(i.getBeerXmlStandardAmount()) * 40 / Units.litersToGallons(r.getBeerXmlStandardBatchSize());
if (isUnfermentable(i.getName())) {
return UNFERMENTABLE_UNFERMENTABLE_PPG * Units.kilosToPounds(i.getBeerXmlStandardAmount()) /
Units.litersToGallons(r.getBeerXmlStandardBatchSize());
}

else {
return 0;
}
Expand Down