def compute(self, **kwargs):
        """
        Calculate a percentage.

        @keyword district: A L{District} whose percentage should be 
            calculated.
        @keyword plan: A L{Plan} whose set of districts should be 
            calculated.
        @keyword version: Optional. The version of the plan, defaults to 
            the most recent version.
        """
        district = None

        if 'district' in kwargs:
            district = kwargs['district']

            num = self.get_value('numerator',district)
            den = self.get_value('denominator',district)

        elif 'plan' in kwargs:
            plan = kwargs['plan']
            version = kwargs['version'] if 'version' in kwargs else plan.version
            districts = plan.get_districts_at_version(version, include_geom=False)
            num = 0
            den = 0
            for district in districts:
                if district.district_id == 0:
                    continue

                tmpnum = self.get_value('numerator',district)
                tmpden = self.get_value('denominator',district)

                # If either the numerator or denominator don't exist,
                # we have to skip it.
                if tmpnum is None or tmpden is None:
                    continue

                den += tmpden
                num += tmpnum

        else:
            return

        if num is None or den is None or den == 0:
            return
    
        try:
            self.result = { 'value': num / den }
        except:
            # TODO: temporary fix
            if den['value'] == 0:
                self.result = { 'value': 0 }
            else:
                self.result = { 'value': num / den['value'] }
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/calculators.py/Percent.compute/original