# Path: brew/utilities/sugar.py
# def brix_to_plato(brix):
#     """
#     Degrees Brix to Degrees Plato
# 
#     :param float brix: Degrees Brix
#     :return: Degrees Plato
#     :rtype: float
# 
#     The difference between the degBx and degP as calculated from the respective
#     polynomials is:
# 
#     :math:`\\text{degP} - \\text{degBx} = \\big(\\big(\\big(-2.81615*sg + 8.79724\\big) \\times sg - 9.1626\\big) \\times sg + 3.18213\\big)`
# 
#     The difference is generally less than +/-0.0005 degBx or degP with the
#     exception being for weak solutions.
# 
#     Source:
# 
#     * https://en.wikipedia.org/wiki/Brix
#     """  # noqa
#     return sg_to_plato(brix_to_sg(brix))
# 
# Path: brew/utilities/sugar.py
# 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
# 
# Path: brew/utilities/sugar.py
# def plato_to_brix(plato):
#     """
#     Degrees Plato to Degrees Brix
# 
#     :param float brix: Degrees Plato
#     :return: Degrees Brix
#     :rtype: float
#     """
#     return sg_to_brix(plato_to_sg(plato))
# 
# Path: brew/utilities/sugar.py
# def plato_to_sg(deg_plato):
#     """
#     Degrees Plato to Specific Gravity
# 
#     :param float deg_plato: Degrees Plato
#     :return: Specific Gravity
#     :rtype: float
# 
#     The simple formula for S.G. is:
# 
#     :math:`\\text{SG} = 1 + 0.004 \\times \\text{Plato}`
# 
#     The more precise calculation of SG is:
# 
#     :math:`\\text{SG} = \\frac{Plato}{258.6 - \\big(\\frac{Plato}{258.2} \\times 227.1\\big)} + 1`
# 
#     Source:
# 
#     * http://www.learntobrew.com/page/1mdhe/Shopping/Beer_Calculations.html
#     """  # noqa
#     return (deg_plato / (258.6 - ((deg_plato / 258.2) * 227.1))) + 1.0
# 
# Path: brew/utilities/sugar.py
# 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")
#     return ((182.4601 * sg - 775.6821) * sg + 1262.7794) * sg - 669.5622
# 
# Path: brew/utilities/sugar.py
# def sg_to_plato(sg):
#     """
#     Specific Gravity to Degrees Plato
# 
#     :param float sg: Specific Gravity
#     :return: Degrees Plato
#     :rtype: float
# 
#     :math:`\\text{Plato} = \\frac{\\big(\\text{SG} - 1\\big) \\times 1000}{4}`
# 
#     The more precise calculation of Plato is:
# 
#     :math:`\\text{Plato} = -616.868 + 1111.14 \\times sg - 630.272 \\times sg^2 + 135.997 \\times sg^3`
# 
#     Source:
# 
#     * http://www.brewersfriend.com/2012/10/31/on-the-relationship-between-plato-and-specific-gravity/
#     """  # noqa
#     # return (sg - 1.0) * 1000 / 4
#     return ((135.997 * sg - 630.272) * sg + 1111.14) * sg - 616.868


import argparse
import sys
import textwrap
from brew.utilities.sugar import brix_to_plato
from brew.utilities.sugar import brix_to_sg
from brew.utilities.sugar import plato_to_brix
from brew.utilities.sugar import plato_to_sg
from brew.utilities.sugar import sg_to_brix
from brew.utilities.sugar import sg_to_plato
# -*- coding: utf-8 -*-



def get_sugar_conversion(brix_in, plato_in, sg_in, sugar_out):
    """
    Convert one sugar unit to another or print all.

    brix_in - Degrees Brix Input
    plato_in - Degrees Plato Input
    sg_in - Specific Gravity Input
    sugar_out - Type of conversion ('b', 'p', 's', or None)
    """
    brix, plato, sg = 0.0, 0.0, 0.0
    if brix_in:
        brix = brix_in
        plato = brix_to_plato(brix_in)
        sg = brix_to_sg(brix_in)
    elif plato_in:
        brix = plato_to_brix(plato_in)
        plato = plato_in
        sg = plato_to_sg(plato_in)
    elif sg_in:

# Path: brew/utilities/sugar.py
# def brix_to_plato(brix):
#     """
#     Degrees Brix to Degrees Plato
# 
#     :param float brix: Degrees Brix
#     :return: Degrees Plato
#     :rtype: float
# 
#     The difference between the degBx and degP as calculated from the respective
#     polynomials is:
# 
#     :math:`\\text{degP} - \\text{degBx} = \\big(\\big(\\big(-2.81615*sg + 8.79724\\big) \\times sg - 9.1626\\big) \\times sg + 3.18213\\big)`
# 
#     The difference is generally less than +/-0.0005 degBx or degP with the
#     exception being for weak solutions.
# 
#     Source:
# 
#     * https://en.wikipedia.org/wiki/Brix
#     """  # noqa
#     return sg_to_plato(brix_to_sg(brix))
# 
# Path: brew/utilities/sugar.py
# 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
# 
# Path: brew/utilities/sugar.py
# def plato_to_brix(plato):
#     """
#     Degrees Plato to Degrees Brix
# 
#     :param float brix: Degrees Plato
#     :return: Degrees Brix
#     :rtype: float
#     """
#     return sg_to_brix(plato_to_sg(plato))
# 
# Path: brew/utilities/sugar.py
# def plato_to_sg(deg_plato):
#     """
#     Degrees Plato to Specific Gravity
# 
#     :param float deg_plato: Degrees Plato
#     :return: Specific Gravity
#     :rtype: float
# 
#     The simple formula for S.G. is:
# 
#     :math:`\\text{SG} = 1 + 0.004 \\times \\text{Plato}`
# 
#     The more precise calculation of SG is:
# 
#     :math:`\\text{SG} = \\frac{Plato}{258.6 - \\big(\\frac{Plato}{258.2} \\times 227.1\\big)} + 1`
# 
#     Source:
# 
#     * http://www.learntobrew.com/page/1mdhe/Shopping/Beer_Calculations.html
#     """  # noqa
#     return (deg_plato / (258.6 - ((deg_plato / 258.2) * 227.1))) + 1.0
# 
# Path: brew/utilities/sugar.py
# 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")
#     return ((182.4601 * sg - 775.6821) * sg + 1262.7794) * sg - 669.5622
# 
# Path: brew/utilities/sugar.py
# def sg_to_plato(sg):
#     """
#     Specific Gravity to Degrees Plato
# 
#     :param float sg: Specific Gravity
#     :return: Degrees Plato
#     :rtype: float
# 
#     :math:`\\text{Plato} = \\frac{\\big(\\text{SG} - 1\\big) \\times 1000}{4}`
# 
#     The more precise calculation of Plato is:
# 
#     :math:`\\text{Plato} = -616.868 + 1111.14 \\times sg - 630.272 \\times sg^2 + 135.997 \\times sg^3`
# 
#     Source:
# 
#     * http://www.brewersfriend.com/2012/10/31/on-the-relationship-between-plato-and-specific-gravity/
#     """  # noqa
#     # return (sg - 1.0) * 1000 / 4
#     return ((135.997 * sg - 630.272) * sg + 1111.14) * sg - 616.868


# Path: brew/cli/sugar.py
import argparse
import sys
import textwrap
from brew.utilities.sugar import brix_to_plato
from brew.utilities.sugar import brix_to_sg
from brew.utilities.sugar import plato_to_brix
from brew.utilities.sugar import plato_to_sg
from brew.utilities.sugar import sg_to_brix
from brew.utilities.sugar import sg_to_plato

# -*- coding: utf-8 -*-



def get_sugar_conversion(brix_in, plato_in, sg_in, sugar_out):
    """
    Convert one sugar unit to another or print all.

    brix_in - Degrees Brix Input
    plato_in - Degrees Plato Input
    sg_in - Specific Gravity Input
    sugar_out - Type of conversion ('b', 'p', 's', or None)
    """
    brix, plato, sg = 0.0, 0.0, 0.0
    if brix_in:
        brix = brix_in
        plato = brix_to_plato(brix_in)
        sg = brix_to_sg(brix_in)
    elif plato_in:
        brix = plato_to_brix(plato_in)
        plato = plato_in
        sg = plato_to_sg(plato_in)
    elif sg_in:

        brix = sg_to_brix(sg_in)