<commit_before>from draughtcraft.lib.units import InvalidUnitException
import math

class Calculations(object):

    def __init__(self, recipe):
        self.recipe = recipe

    #
    # Gravity and alcohol content calculations
    #
    @property
    def og(self):
        """
        Original gravity of the recipe.
        """

        points = 0
        volume = float(self.recipe.gallons)

        for a in self.recipe.additions:
            if a.fermentable:

                #
                # Default to the mash efficiency specified by the
                # recipe.
                efficiency = self.recipe.efficiency

                #
                # If the fermentable is extract, we don't take mash
                # efficiency into account - instead, we just use the
                # potential on record for the ingredient.
                #
                if a.fermentable.type == 'EXTRACT':
                    efficiency = 1

                try:
                    pounds = a.pounds
                    points += (pounds * a.fermentable.ppg * efficiency) / volume
                except InvalidUnitException:
                    #
                    # If we can't convert the addition to pounds,
                    # don't include it in the gravity calculations.
                    #
                    pass

        return round(points / 1000 + 1, 3)

    @property
    def fg(self):
        """
        (Estimated) final gravity of the recipe based on yeast attenuation.
        """

        # Default the attenuation to 75%
        attenuation = .75

        #
        # If one or more yeast addition is specified,
        # use the highest attenuation available.
        #
        yeast = [a.yeast.attenuation
                    for a in self.recipe.additions
                    if a.yeast]
        if yeast:
            attenuation = max(yeast)

        points = (self.og - 1) * 1000
        final = points - (points * attenuation)
        <commit_msg>Fixed a bug in FG calculation that occurs for yeast w/ no defined attenuation.<commit_after>from draughtcraft.lib.units import InvalidUnitException
import math

class Calculations(object):

    def __init__(self, recipe):
        self.recipe = recipe

    #
    # Gravity and alcohol content calculations
    #
    @property
    def og(self):
        """
        Original gravity of the recipe.
        """

        points = 0
        volume = float(self.recipe.gallons)

        for a in self.recipe.additions:
            if a.fermentable:

                #
                # Default to the mash efficiency specified by the
                # recipe.
                efficiency = self.recipe.efficiency

                #
                # If the fermentable is extract, we don't take mash
                # efficiency into account - instead, we just use the
                # potential on record for the ingredient.
                #
                if a.fermentable.type == 'EXTRACT':
                    efficiency = 1

                try:
                    pounds = a.pounds
                    points += (pounds * a.fermentable.ppg * efficiency) / volume
                except InvalidUnitException:
                    #
                    # If we can't convert the addition to pounds,
                    # don't include it in the gravity calculations.
                    #
                    pass

        return round(points / 1000 + 1, 3)

    @property
    def fg(self):
        """
        (Estimated) final gravity of the recipe based on yeast attenuation.
        """

        # Default the attenuation to 75%
        attenuation = .75

        #
        # If one or more yeast addition is specified,
        # use the highest attenuation available.
        #
        yeast = [a.yeast.attenuation
                    for a in self.recipe.additions
                    if a.yeast]
        if yeast:
            attenuation = max(yeast) or attenuation

        points = (self.og - 1) * 1000
        final = points - (points * attenuation)
        
{'fraction_non_alphanumeric': 0.06758756783423779, 'fraction_numerical': 0.008386778490379871, 'mean_word_length': 1.2909604519774012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4869923', 'n_tokens_mistral': 1099, 'n_tokens_neox': 945, 'n_words': 333}