# Path: brew/constants.py
# HYDROMETER_ADJUSTMENT_TEMP = 59.0
# 
# Path: brew/constants.py
# IMPERIAL_UNITS = u"imperial"
# 
# Path: brew/constants.py
# SI_UNITS = u"metric"
# 
# Path: brew/exceptions.py
# class SugarException(BrewdayException):
#     pass
# 
# Path: brew/validators.py
# def validate_units(units):
#     """
#     Validate units
# 
#     :param str units: Unit type
#     :return: units
#     :rtype: str
#     :raises ValidatorException: If units is unknown
#     """
#     if units in [IMPERIAL_UNITS, SI_UNITS]:
#         return units
#     raise ValidatorException(
#         u"Unkown units '{}', must use {} or {}".format(units, IMPERIAL_UNITS, SI_UNITS)
#     )
# 
# Path: brew/utilities/temperature.py
# def celsius_to_fahrenheit(temp):
#     """
#     Convert degrees Celsius to degrees Fahrenheit
# 
#     :param float temp: The temperature in Celsius
#     :return: The temperature in Fahrenheit
#     :rtype: float
#     """
#     return (temp * 1.8) + 32.0


from ..constants import HYDROMETER_ADJUSTMENT_TEMP
from ..constants import IMPERIAL_UNITS
from ..constants import SI_UNITS
from ..exceptions import SugarException
from ..validators import validate_units
from .temperature import celsius_to_fahrenheit

def brix_to_sg(brix):
    """
    Degrees Brix to Specific Gravity

    :param float brix: Degrees Brix
    :return: Specific Gravity
    :rtype: float

    Source:

    * http://www.brewersfriend.com/brix-converter/
    """
    return (brix / (258.6 - ((brix / 258.2) * 227.1))) + 1


def sg_to_brix(sg):
    """
    Specific Gravity to Degrees Brix

    :param float sg: Specific Gravity
    :return: Degrees Brix
    :rtype: float

    Source:

    * http://en.wikipedia.org/wiki/Brix
    * http://www.brewersfriend.com/brix-converter/
    """
    if sg > 1.17874:

# Path: brew/constants.py
# HYDROMETER_ADJUSTMENT_TEMP = 59.0
# 
# Path: brew/constants.py
# IMPERIAL_UNITS = u"imperial"
# 
# Path: brew/constants.py
# SI_UNITS = u"metric"
# 
# Path: brew/exceptions.py
# class SugarException(BrewdayException):
#     pass
# 
# Path: brew/validators.py
# def validate_units(units):
#     """
#     Validate units
# 
#     :param str units: Unit type
#     :return: units
#     :rtype: str
#     :raises ValidatorException: If units is unknown
#     """
#     if units in [IMPERIAL_UNITS, SI_UNITS]:
#         return units
#     raise ValidatorException(
#         u"Unkown units '{}', must use {} or {}".format(units, IMPERIAL_UNITS, SI_UNITS)
#     )
# 
# Path: brew/utilities/temperature.py
# def celsius_to_fahrenheit(temp):
#     """
#     Convert degrees Celsius to degrees Fahrenheit
# 
#     :param float temp: The temperature in Celsius
#     :return: The temperature in Fahrenheit
#     :rtype: float
#     """
#     return (temp * 1.8) + 32.0


# Path: brew/utilities/sugar.py
from ..constants import HYDROMETER_ADJUSTMENT_TEMP
from ..constants import IMPERIAL_UNITS
from ..constants import SI_UNITS
from ..exceptions import SugarException
from ..validators import validate_units
from .temperature import celsius_to_fahrenheit


def brix_to_sg(brix):
    """
    Degrees Brix to Specific Gravity

    :param float brix: Degrees Brix
    :return: Specific Gravity
    :rtype: float

    Source:

    * http://www.brewersfriend.com/brix-converter/
    """
    return (brix / (258.6 - ((brix / 258.2) * 227.1))) + 1


def sg_to_brix(sg):
    """
    Specific Gravity to Degrees Brix

    :param float sg: Specific Gravity
    :return: Degrees Brix
    :rtype: float

    Source:

    * http://en.wikipedia.org/wiki/Brix
    * http://www.brewersfriend.com/brix-converter/
    """
    if sg > 1.17874:

        raise SugarException(u"Above 40 degBx this function no longer works")