def compute(self, **kwargs):
        """
        Compute the competitiveness.

        @keyword plan: A L{Plan} whose set of districts should be 
            evaluated for competitiveness.
        @keyword version: Optional. The version of the plan, defaults to 
            the most recent version.
        """
        if not 'plan' in kwargs:
            return

        plan = kwargs['plan']
        version = kwargs['version'] if 'version' in kwargs else plan.version
        districts = plan.get_districts_at_version(version, include_geom=False)
        try:
            difference = float(self.get_value('range'))
            low = .5 - difference
            high = .5 + difference
        except:
            low = .45
            high = .55

        
        fair = 0
        for district in districts:
            if district.district_id == 0:
                continue

            tmpdem = self.get_value('democratic',district)
            tmprep = self.get_value('republican',district)

            if tmpdem is None or tmprep is None:
                continue

            dem = float(tmpdem)
            rep = float(tmprep)

            if dem == 0.0 and rep == 0.0:
                continue

            pidx = dem / (dem + rep)
            if pidx > low and pidx < high:
                fair += 1

        self.result = { 'value': fair }
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/calculators.py/Competitiveness.compute/original