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

        @keyword plan: A L{Plan} whose set of districts should be 
            evaluated for representational fairness.
        @keyword version: Optional. The version of the plan, defaults to 
            the most recent version.
        """
        if '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)

        else:
            return

        dems = 0
        reps = 0
        for district in districts:
            dem = self.get_value('democratic',district)
            rep = self.get_value('republican',district)
            if dem is None or rep is None:
                continue

            dem = float(dem)
            rep = float(rep)

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

            dem_pi = dem / (rep + dem)
            if dem_pi > .5:
                dems += 1
            else:
                rep_pi = rep / (rep + dem)
                if rep_pi > .5:
                    reps += 1

        self.result = { 'value': dems - reps }
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/calculators.py/RepresentationalFairness.compute/original