def abv(ctx, og, fg, adjust): """ Calculates the ABV from the original and final gravity readings. By default the wort and alcohol correction factor is not applied. If you are using a hydrometer add the ``adjust`` flag to automatically correct the final gravity. """ # These prompts are used instead of using the `prompt` attribute in the # click options so that it is possible to add units to the end of the # prompt based on the requested unit format. if not og: og = inputs.get_gravity_input("Original Gravity: ") if not fg: fg = inputs.get_gravity_input("Final Gravity: ") # If passed in via options we need to check valid range valid_range = inputs.between(1.0, 1.2) if not valid_range(og) or not valid_range(fg): sys.exit(1) if fg > og: print("Final gravity cannot be higher than original gravity") sys.exit(1) print("Estimated ABV: {0:.2f}%".format(bm.abv(og, fg, adjust)))
def adjust_gravity(ctx, og, vol, ng): """ Calculate the amount of liquid to boil off/dilute with to achieve a desired gravity. """ if not og: og = inputs.get_gravity_input("Original Gravity: ") if not ng: ng = inputs.get_gravity_input("Desired Gravity: ") if not vol: vol = inputs.get_unit_input(ctx.obj["units"]["vol"], "Current volume of wort") valid_range = inputs.between(1.0, 1.2) if not valid_range(og) or not valid_range(ng): sys.exit(1) vol_adj = bm.adjust_gravity_volume(vol, og, ng) print("\nNew volume of wort will be {0:.2f}".format(vol_adj)) diff = vol - vol_adj if diff >= 0: print("Boil off {0:.2f} {1} of wort".format(diff, ctx.obj["units"]["vol"])) else: print("Dilute wort with {0:.2f} {1} of water".format( diff * -1, ctx.obj["units"]["vol"]))
def attenuation(ctx, og, fg): """ Calculates the apparent and real attenuation from the provided original and final/current gravity. Real attenuation is the adjusted value taking into account the alcohol in the beer """ if not og: og = inputs.get_gravity_input("Original Gravity: ") if not fg: fg = inputs.get_gravity_input("Current Gravity: ") # If passed in via options we need to check valid range valid_range = inputs.between(1.0, 1.2) if not valid_range(og) or not valid_range(fg): sys.exit(1) if fg > og: print("Final gravity cannot be higher than original gravity") sys.exit(1) print("Apparent attenuation: {0:.2f}%".format( bm.apparent_attenuation(og, fg) * 100)) print("Real attenuation: {0:.2f}%".format( bm.real_attenuation(og, fg) * 100))
def adjust_volume(ctx, og, vol, newvol): """ Calculate the new gravity after a change in wort volume either through dilution or boil off """ if not og: og = inputs.get_gravity_input("Original Gravity: ") if not vol: vol = inputs.get_unit_input(ctx.obj["units"]["vol"], "Current volume of wort") if not newvol: newvol = inputs.get_unit_input(ctx.obj["units"]["vol"], "New volume of wort") valid_range = inputs.between(1.0, 1.2) if not valid_range(og): sys.exit(1) new_grav = bm.adjust_volume_gravity(vol, og, newvol) print("The new gravity will be {0:.3f}".format(new_grav))
def fg_from_att(ctx, og, att): """ Given a starting gravity and a desired attenuation level, will return the specific gravity for that percentage of attenuation. Useful if you have to action something at a given attenuation point and need to know what the gravity is when that point is reached """ if not og: og = inputs.get_gravity_input("Original Gravity: ") if not att: att = inputs.get_input("Desired attenuation in %: ", lambda x: float(x)) # If passed in via options we need to check valid range valid_range = inputs.between(1.0, 1.2) if not valid_range(og): sys.exit(1) print("FG for {0}% attenuation: {1:.3f}".format( att, bm.fg_from_attenuation(og, att)))