def completion(self):
        """
        Return fraction of case/env combos that have a completed result.

        Have to specify deleted_on=None for the through, because the
        default manager doesn't go through our MT model manager.
        """
        total = RunCaseVersion.environments.through.objects.filter(
            runcaseversion__run=self,
            runcaseversion__deleted_on=None,
            ).count()
        skipped = Result.objects.filter(
            runcaseversion__run=self,
            is_latest=True,
            status=Result.STATUS.skipped).count()
        completed = Result.objects.filter(
            status__in=Result.COMPLETED_STATES,
            is_latest=True,
            runcaseversion__run=self).values(
            "runcaseversion", "environment").distinct().count()

        try:
            return float(completed) / (total - skipped)
        except ZeroDivisionError:
            return 0
dataset/ETHPy150Open mozilla/moztrap/moztrap/model/execution/models.py/Run.completion/original