def compute(self, **kwargs):
        """
        Calculate the convex hull ratio of a district or a plan.

        @keyword district: A L{District} whose convex hull ratio should be 
            computed.
        @keyword plan: A L{Plan} whose district convex hull ratios should be 
            averaged.
        @keyword version: Optional. The version of the plan, defaults to 
            the most recent version.
        """
        districts = []
        if 'district' in kwargs:
            districts = [kwargs['district']]
            if districts[0].geom.empty:
                return

        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=True)

        else:
            return
            
        num = 0
        ratios = 0.0
        for district in districts:
            if district.geom.empty or district.geom.length == 0 or district.district_id == 0:
                continue

            ratios += district.geom.area / district.geom.convex_hull.area
            num += 1

        self.result = { 'value': (ratios / num) if num > 0 else 0 }
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/calculators.py/ConvexHullRatio.compute/original