Exemple #1
0
def get_abv(og, fg,
            og_temp=HYDROMETER_ADJUSTMENT_TEMP,
            fg_temp=HYDROMETER_ADJUSTMENT_TEMP,
            alternative=False,
            refractometer=False,
            units=IMPERIAL_UNITS,
            verbose=False):
    """
    Get Alcohol by Volume for CLI Utility

    og - Original Specific Gravity
    fg - Final Specific Gravity
    og_temp - Temperature of reading for og
    fg_temp - Temperature of reading for fg
    alternative - Use alternative ABV calculation
    refractometer - Adjust for using a refractometer for readings
    units - Type of units to use in calculations
    verbose - Return verbose information about calculations
    """
    # Gravity is required for calculation
    if not og:
        raise Exception(u"Original gravity required")
    if not fg:
        raise Exception(u"Final gravity required")

    # Ensure the gravity units are not mixed up
    if og < fg:
        raise Exception(u"Original Gravity must be higher than Final Gravity")

    if units not in [IMPERIAL_UNITS, SI_UNITS]:
        raise Exception(u"Units must be in either {} or {}".format(IMPERIAL_UNITS,  # noqa
                                                                   SI_UNITS))

    # Adjust the gravity based on temperature
    og = hydrometer_adjustment(og, og_temp, units=units)
    fg = hydrometer_adjustment(fg, fg_temp, units=units)

    # Adjust the final gravity if using a refractometer
    if refractometer:
        fg = refractometer_adjustment(og, fg)

    # Calculate the ABV
    if alternative:
        abv = alcohol_by_volume_alternative(og, fg)
    else:
        abv = alcohol_by_volume_standard(og, fg)

    if verbose:
        out = []
        t_unit = u'F' if units == IMPERIAL_UNITS else u'C'
        out.append(u"OG     : {:0.3f}".format(og))
        out.append(u"OG Adj : {:0.3f}".format(og))
        out.append(u"OG Temp: {:0.2f} {}".format(og_temp, t_unit))
        out.append(u"FG     : {:0.3f}".format(fg))
        out.append(u"FG Adj : {:0.3f}".format(fg))
        out.append(u"FG Temp: {:0.2f} {}".format(fg_temp, t_unit))
        out.append(u"ABV    : {:0.2%}".format(abv))
        return u'\n'.join(out)
    else:
        return abv
Exemple #2
0
    def test_hydrometer_adjustment_raises_bad_temp(self):
        with self.assertRaises(Exception):
            hydrometer_adjustment(1.050, -1.0)

        with self.assertRaises(Exception):
            hydrometer_adjustment(1.050, 213.0)

        with self.assertRaises(Exception):
            hydrometer_adjustment(1.050, -1.0, units=SI_UNITS)

        with self.assertRaises(Exception):
            hydrometer_adjustment(1.050, 101.0, units=SI_UNITS)
    def test_hydrometer_adjustment_raises_bad_temp(self):
        with self.assertRaises(SugarException) as ctx:
            hydrometer_adjustment(1.050, -1.0)
        self.assertEquals(str(ctx.exception),
                          u"Correction does not work outside temps 0 - 212F")

        with self.assertRaises(SugarException) as ctx:
            hydrometer_adjustment(1.050, 213.0)
        self.assertEquals(str(ctx.exception),
                          u"Correction does not work outside temps 0 - 212F")

        with self.assertRaises(SugarException) as ctx:
            hydrometer_adjustment(1.050, -1.0, units=SI_UNITS)
        self.assertEquals(str(ctx.exception),
                          u"Correction does not work outside temps 0 - 100C")

        with self.assertRaises(SugarException) as ctx:
            hydrometer_adjustment(1.050, 101.0, units=SI_UNITS)
        self.assertEquals(str(ctx.exception),
                          u"Correction does not work outside temps 0 - 100C")
Exemple #4
0
    def test_hydrometer_adjustment_raises_bad_temp(self):
        with self.assertRaises(SugarException) as ctx:
            hydrometer_adjustment(1.050, -1.0)
        self.assertEquals(
            str(ctx.exception), u"Correction does not work outside temps 0 - 212F"
        )

        with self.assertRaises(SugarException) as ctx:
            hydrometer_adjustment(1.050, 213.0)
        self.assertEquals(
            str(ctx.exception), u"Correction does not work outside temps 0 - 212F"
        )

        with self.assertRaises(SugarException) as ctx:
            hydrometer_adjustment(1.050, -1.0, units=SI_UNITS)
        self.assertEquals(
            str(ctx.exception), u"Correction does not work outside temps 0 - 100C"
        )

        with self.assertRaises(SugarException) as ctx:
            hydrometer_adjustment(1.050, 101.0, units=SI_UNITS)
        self.assertEquals(
            str(ctx.exception), u"Correction does not work outside temps 0 - 100C"
        )
Exemple #5
0
def get_abv(
    og,
    fg,
    og_temp=HYDROMETER_ADJUSTMENT_TEMP,
    fg_temp=HYDROMETER_ADJUSTMENT_TEMP,
    alternative=False,
    refractometer=False,
    units=IMPERIAL_UNITS,
    verbose=False,
):
    """
    Get Alcohol by Volume for CLI Utility

    og - Original Specific Gravity
    fg - Final Specific Gravity
    og_temp - Temperature of reading for og
    fg_temp - Temperature of reading for fg
    alternative - Use alternative ABV calculation
    refractometer - Adjust for using a refractometer for readings
    units - Type of units to use in calculations
    verbose - Return verbose information about calculations
    """
    # Gravity is required for calculation
    if not og:
        raise Exception(u"Original gravity required")
    if not fg:
        raise Exception(u"Final gravity required")

    # Ensure the gravity units are not mixed up
    if og < fg:
        raise Exception(u"Original Gravity must be higher than Final Gravity")

    if units not in [IMPERIAL_UNITS, SI_UNITS]:
        raise Exception(u"Units must be in either {} or {}".format(
            IMPERIAL_UNITS, SI_UNITS)  # noqa
                        )

    # Adjust the gravity based on temperature
    og = hydrometer_adjustment(og, og_temp, units=units)
    fg = hydrometer_adjustment(fg, fg_temp, units=units)

    # Adjust the final gravity if using a refractometer
    if refractometer:
        fg = refractometer_adjustment(og, fg)

    # Calculate the ABV
    if alternative:
        abv = alcohol_by_volume_alternative(og, fg)
    else:
        abv = alcohol_by_volume_standard(og, fg)

    if verbose:
        out = []
        t_unit = u"F" if units == IMPERIAL_UNITS else u"C"
        out.append(u"OG     : {:0.3f}".format(og))
        out.append(u"OG Adj : {:0.3f}".format(og))
        out.append(u"OG Temp: {:0.2f} {}".format(og_temp, t_unit))
        out.append(u"FG     : {:0.3f}".format(fg))
        out.append(u"FG Adj : {:0.3f}".format(fg))
        out.append(u"FG Temp: {:0.2f} {}".format(fg_temp, t_unit))
        out.append(u"ABV    : {:0.2%}".format(abv))
        return u"\n".join(out)
    else:
        return abv
Exemple #6
0
 def test_hydrometer_adjustment_raises_bad_units(self):
     with self.assertRaises(ValidatorException) as ctx:
         hydrometer_adjustment(1.050, 16.0, units=u"bad")
     self.assertEquals(
         str(ctx.exception), u"Unkown units 'bad', must use imperial or metric"
     )
Exemple #7
0
 def test_hydromter_adjustment_si_units(self):
     sg = hydrometer_adjustment(1.050, 16.0, units=SI_UNITS)
     self.assertEquals(round(sg, 3), 1.050)
Exemple #8
0
 def test_hydrometer_adjustment_no_adjustment(self):
     sg = hydrometer_adjustment(1.050, 59.0)
     self.assertEquals(round(sg, 3), 1.050)
Exemple #9
0
 def test_hydrometer_adjustment_raises_bad_units(self):
     with self.assertRaises(Exception):
         hydrometer_adjustment(1.050, 16.0, units=u'bad')
Exemple #10
0
 def test_hydromter_adjustment_si_units(self):
     sg = hydrometer_adjustment(1.050, 16.0, units=SI_UNITS)
     self.assertEquals(round(sg, 3), 1.050)
Exemple #11
0
 def test_hydrometer_adjustment_no_adjustment(self):
     sg = hydrometer_adjustment(1.050, 59.0)
     self.assertEquals(round(sg, 3), 1.050)
 def test_hydrometer_adjustment_raises_bad_units(self):
     with self.assertRaises(ValidatorException) as ctx:
         hydrometer_adjustment(1.050, 16.0, units=u'bad')
     self.assertEquals(str(ctx.exception),
                       u"Unkown units 'bad', must use imperial or metric")