# Path: brew/constants.py
# ABV_CONST = 131.25  # RATIO_C2H6O_TO_CO2 / ALCOHOL_SPECIFIC_GRAVITY * 100.0
# 
# Path: brew/constants.py
# ALCOHOL_SPECIFIC_GRAVITY = 0.7936
# 
# Path: brew/utilities/sugar.py
# def apparent_extract_to_real_extract(original_extract, apparent_extract):
#     """
#     Apparent Extract to Real Extract in degrees Plato
# 
#     :param float original_extract: Original degrees Plato
#     :param float apparent_extract: Apparent degrees Plato of finished beer
#     :return: Real degrees Plato of finished beer
#     :rtype: float
# 
#     Source:
# 
#     * Formula from Balling: De Clerck, Jean, A Textbook Of Brewing, Chapman & Hall Ltd., 1958
#     """  # noqa
#     attenuation_coeff = 0.22 + 0.001 * original_extract
#     real_extract = (attenuation_coeff * original_extract + apparent_extract) / (
#         1 + attenuation_coeff
#     )  # noqa
#     return real_extract


from ..constants import ABV_CONST
from ..constants import ALCOHOL_SPECIFIC_GRAVITY
from .sugar import apparent_extract_to_real_extract

    :math:`\\text{ABV} = \\big(\\text{og} - \\text{fg}\\big) \\times 131.25`

    This equation was created before the computer age.  It is easy to do by
    hand, and over time became the accepted formula for home brewers!

    Variations on this equation which report within tenths of each other
    come from The Joy of Homebrewing Method by Charlie Papazian, Bee Lee's
    Method, Beer Advocate Method. Some variations use 131 instead of 131.25.
    The resulting difference is pretty minor.

    Source:

    * http://www.brewersfriend.com/2011/06/16/alcohol-by-volume-calculator-updated/
    * http://www.brewmorebeer.com/calculate-percent-alcohol-in-beer/

    :math:`\\text{ABV} = \\frac{46.07 \\text{g/mol C2H6O}}{44.0095 \\text{g/mol CO2}} \\times \\frac{1.0}{0.7936} \\times 100 \\times (og - fg)`
    """  # noqa
    return (og - fg) * ABV_CONST / 100.0


def final_gravity_from_abv_standard(og, abv):
    """
    Final Gravity from ABV Standard

    :param float og: Original Gravity
    :param float abv: Alcohol by Volume decimal percentage
    :return: Final Gravity
    :rtype: float
    """

# Path: brew/constants.py
# ABV_CONST = 131.25  # RATIO_C2H6O_TO_CO2 / ALCOHOL_SPECIFIC_GRAVITY * 100.0
# 
# Path: brew/constants.py
# ALCOHOL_SPECIFIC_GRAVITY = 0.7936
# 
# Path: brew/utilities/sugar.py
# def apparent_extract_to_real_extract(original_extract, apparent_extract):
#     """
#     Apparent Extract to Real Extract in degrees Plato
# 
#     :param float original_extract: Original degrees Plato
#     :param float apparent_extract: Apparent degrees Plato of finished beer
#     :return: Real degrees Plato of finished beer
#     :rtype: float
# 
#     Source:
# 
#     * Formula from Balling: De Clerck, Jean, A Textbook Of Brewing, Chapman & Hall Ltd., 1958
#     """  # noqa
#     attenuation_coeff = 0.22 + 0.001 * original_extract
#     real_extract = (attenuation_coeff * original_extract + apparent_extract) / (
#         1 + attenuation_coeff
#     )  # noqa
#     return real_extract


# Path: brew/utilities/abv.py
from ..constants import ABV_CONST
from ..constants import ALCOHOL_SPECIFIC_GRAVITY
from .sugar import apparent_extract_to_real_extract


    :math:`\\text{ABV} = \\big(\\text{og} - \\text{fg}\\big) \\times 131.25`

    This equation was created before the computer age.  It is easy to do by
    hand, and over time became the accepted formula for home brewers!

    Variations on this equation which report within tenths of each other
    come from The Joy of Homebrewing Method by Charlie Papazian, Bee Lee's
    Method, Beer Advocate Method. Some variations use 131 instead of 131.25.
    The resulting difference is pretty minor.

    Source:

    * http://www.brewersfriend.com/2011/06/16/alcohol-by-volume-calculator-updated/
    * http://www.brewmorebeer.com/calculate-percent-alcohol-in-beer/

    :math:`\\text{ABV} = \\frac{46.07 \\text{g/mol C2H6O}}{44.0095 \\text{g/mol CO2}} \\times \\frac{1.0}{0.7936} \\times 100 \\times (og - fg)`
    """  # noqa
    return (og - fg) * ABV_CONST / 100.0


def final_gravity_from_abv_standard(og, abv):
    """
    Final Gravity from ABV Standard

    :param float og: Original Gravity
    :param float abv: Alcohol by Volume decimal percentage
    :return: Final Gravity
    :rtype: float
    """

    return og - (abv * 100.0) / ABV_CONST