HOP_TYPE_PELLET = u"pellet" HOP_TYPE_PLUG = u"plug" HOP_TYPE_WHOLE = u"whole" HOP_TYPE_WHOLE_WET = u"whole wet" HOP_UTILIZATION_SCALE_PELLET = 1.1  # 110% HOP_WHOLE_DRY_TO_WET = 5.5 HOPS_CONSTANT_IMPERIAL = MG_PER_OZ * GAL_PER_LITER HOPS_CONSTANT_SI = 1.0 IMPERIAL_TYPES = {
    u"volume": u"gallon",
    u"weight_large": u"lbs",
    u"weight_small": u"oz",
    u"temperature": u"degF",
} IMPERIAL_UNITS = u"imperial" SI_TYPES = {
    u"volume": u"liter",
    u"weight_large": u"kg",
    u"weight_small": u"mg",
    u"temperature": u"degC",
} SI_UNITS = u"metric" 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)
    )
import math
from ..constants import HOP_TYPE_PELLET
from ..constants import HOP_TYPE_PLUG
from ..constants import HOP_TYPE_WHOLE
from ..constants import HOP_TYPE_WHOLE_WET
from ..constants import HOP_UTILIZATION_SCALE_PELLET
from ..constants import HOP_WHOLE_DRY_TO_WET
from ..constants import HOPS_CONSTANT_IMPERIAL
from ..constants import HOPS_CONSTANT_SI
from ..constants import IMPERIAL_TYPES
from ..constants import IMPERIAL_UNITS
from ..constants import SI_TYPES
from ..constants import SI_UNITS
from ..validators import validate_units
# -*- coding: utf-8 -*-


__all__ = [
    u"hop_type_weight_conversion",
    u"HopsUtilization",
    u"HopsUtilizationJackieRager",
    u"HopsUtilizationGlennTinseth",
]


def hop_type_weight_conversion(weight, old_type, new_type):
    """
    Convert weight of hops between one type and another

    :param float weight: Weight of the hops
    :param str old_type: The old hop type to convert from
    :param str new_type: The new hop type to convert to
    :return: New weight of the hops
    :rtype: float
    """
    # If same type then no change
    if old_type == new_type:
        return weight

    # If hop types are equivalent then no change
    equivalent_types = [HOP_TYPE_PLUG, HOP_TYPE_WHOLE]
    if old_type in equivalent_types and new_type in equivalent_types:
        return weight

    conversion = 1.0
    if old_type == HOP_TYPE_WHOLE_WET:
        conversion /= HOP_WHOLE_DRY_TO_WET
    elif new_type == HOP_TYPE_WHOLE_WET:
        conversion *= HOP_WHOLE_DRY_TO_WET

    if old_type == HOP_TYPE_PELLET:
        conversion *= HOP_UTILIZATION_SCALE_PELLET
    elif new_type == HOP_TYPE_PELLET:
        conversion /= HOP_UTILIZATION_SCALE_PELLET

    return weight * conversion


class HopsUtilization(object):
    """
    http://www.boondocks-brewing.com/hops
    """

    def __init__(self, hop_addition, units=IMPERIAL_UNITS):
        """
        :param HopAddition hop_addition: A hop addition
        :param str units: The units
        """
        self.hop_addition = hop_addition

        # Manage units
        self.set_units(units)

    def set_units(self, units):
        """
        Set the units and unit types

        :param str units: The units
        """
        self.units = validate_units(units)

        if self.units == IMPERIAL_UNITS: