prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Count of results displayed on the challenge card does not match leaderboard count
  **Describe the bug**
  The card for the node21 challenge currently notes there are 21 results.  Clicking on this brings you to the leaderboard where only 2 results are present.   It seems that the count is including submissions which failed and/or submissions where the evaluation failed, which is misleading.  
  
  **To Reproduce**
  Steps to reproduce the behavior:
   - Choose a challenge where the database includes many failed submissions or failed evaluations (e.g. node21 at present)
  - View the card for this challenge (currently it is on the GC front page)
   - Verify that the number of results shown on the card does not match the number of results on the leaderboard (click the number shown on the card).
  
  **Expected behavior**
  The number of reported results should match the number of results on the leaderboard
  
  **Screenshots**
  ![image](https://user-images.githubusercontent.com/6442576/139235716-012dc618-4fba-46e5-b510-2fbc81ae61b7.png)
  
  
  
  </issue>
  <code>
  [start of app/grandchallenge/challenges/tasks.py]
  1 from celery import shared_task
  2 from django.contrib.auth import get_user_model
  3 from django.core.mail import mail_managers
  4 from django.db.models import Count, Max
  5 from requests import exceptions, get
  6 
  7 from grandchallenge.challenges.models import Challenge, ExternalChallenge
  8 from grandchallenge.evaluation.models import Evaluation
  9 from grandchallenge.subdomains.utils import reverse
  10 
  11 
  12 @shared_task
  13 def update_challenge_results_cache():
  14     challenges = Challenge.objects.all()
  15     evaluation_info = (
  16         Evaluation.objects.filter(published=True)
  17         .values("submission__phase__challenge_id")
  18         .annotate(
  19             cached_num_results=Count("submission__phase__challenge_id"),
  20             cached_latest_result=Max("created"),
  21         )
  22     )
  23     evaluation_info_by_challenge = {
  24         str(v["submission__phase__challenge_id"]): v for v in evaluation_info
  25     }
  26     participant_counts = (
  27         get_user_model()
  28         .objects.values("groups__participants_of_challenge")
  29         .annotate(cached_num_participants=Count("pk"))
  30     )
  31     participant_counts_by_challenge = {
  32         str(v["groups__participants_of_challenge"]): v
  33         for v in participant_counts
  34     }
  35 
  36     for c in challenges:
  37         c.cached_num_results = evaluation_info_by_challenge.get(
  38             str(c.pk), {}
  39         ).get("cached_num_results", 0)
  40         c.cached_latest_result = evaluation_info_by_challenge.get(
  41             str(c.pk), {}
  42         ).get("cached_latest_result", None)
  43         c.cached_num_participants = participant_counts_by_challenge.get(
  44             str(c.pk), {}
  45         ).get("cached_num_participants", 0)
  46 
  47     Challenge.objects.bulk_update(
  48         challenges,
  49         [
  50             "cached_num_results",
  51             "cached_num_participants",
  52             "cached_latest_result",
  53         ],
  54     )
  55 
  56 
  57 @shared_task
  58 def check_external_challenge_urls():
  59     """
  60     Checks that all external challenge urls are reachable.
  61 
  62     Emails the managers if any of the challenges are not.
  63     """
  64     challenges = ExternalChallenge.objects.filter(hidden=False)
  65     errors = []
  66 
  67     for challenge in challenges:
  68         try:
  69             url = challenge.homepage
  70             if not url.startswith("http"):
  71                 url = "http://" + url
  72             r = get(url, timeout=60)
  73             # raise an exception when we receive a http error (e.g., 404)
  74             r.raise_for_status()
  75         except exceptions.RequestException as err:
  76             update_url = reverse(
  77                 "challenges:external-update",
  78                 kwargs={"short_name": challenge.short_name},
  79             )
  80             errors.append(
  81                 f"Error when trying to access '{challenge}': {err}. You can "
  82                 f"update it here: {update_url}"
  83             )
  84 
  85     if errors:
  86         mail_managers(
  87             subject=f"Unreachable external challenges ({len(errors)})",
  88             message="\n\n".join(errors),
  89         )
  90
  [end of app/grandchallenge/challenges/tasks.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/app/grandchallenge/challenges/tasks.py b/app/grandchallenge/challenges/tasks.py
  --- a/app/grandchallenge/challenges/tasks.py
  +++ b/app/grandchallenge/challenges/tasks.py
  @@ -13,7 +13,7 @@
   def update_challenge_results_cache():
       challenges = Challenge.objects.all()
       evaluation_info = (
  -        Evaluation.objects.filter(published=True)
  +        Evaluation.objects.filter(published=True, rank__gt=0)
           .values("submission__phase__challenge_id")
           .annotate(
               cached_num_results=Count("submission__phase__challenge_id"),
  
verification_info: {"golden_diff": "diff --git a/app/grandchallenge/challenges/tasks.py b/app/grandchallenge/challenges/tasks.py\n--- a/app/grandchallenge/challenges/tasks.py\n+++ b/app/grandchallenge/challenges/tasks.py\n@@ -13,7 +13,7 @@\n def update_challenge_results_cache():\n     challenges = Challenge.objects.all()\n     evaluation_info = (\n-        Evaluation.objects.filter(published=True)\n+        Evaluation.objects.filter(published=True, rank__gt=0)\n         .values(\"submission__phase__challenge_id\")\n         .annotate(\n             cached_num_results=Count(\"submission__phase__challenge_id\"),\n", "issue": "Count of results displayed on the challenge card does not match leaderboard count\n**Describe the bug**\r\nThe card for the node21 challenge currently notes there are 21 results.  Clicking on this brings you to the leaderboard where only 2 results are present.   It seems that the count is including submissions which failed and/or submissions where the evaluation failed, which is misleading.  \r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n - Choose a challenge where the database includes many failed submissions or failed evaluations (e.g. node21 at present)\r\n- View the card for this challenge (currently it is on the GC front page)\r\n - Verify that the number of results shown on the card does not match the number of results on the leaderboard (click the number shown on the card).\r\n\r\n**Expected behavior**\r\nThe number of reported results should match the number of results on the leaderboard\r\n\r\n**Screenshots**\r\n![image](https://user-images.githubusercontent.com/6442576/139235716-012dc618-4fba-46e5-b510-2fbc81ae61b7.png)\r\n\r\n\n", "before_files": [{"content": "from celery import shared_task\nfrom django.contrib.auth import get_user_model\nfrom django.core.mail import mail_managers\nfrom django.db.models import Count, Max\nfrom requests import exceptions, get\n\nfrom grandchallenge.challenges.models import Challenge, ExternalChallenge\nfrom grandchallenge.evaluation.models import Evaluation\nfrom grandchallenge.subdomains.utils import reverse\n\n\n@shared_task\ndef update_challenge_results_cache():\n    challenges = Challenge.objects.all()\n    evaluation_info = (\n        Evaluation.objects.filter(published=True)\n        .values(\"submission__phase__challenge_id\")\n        .annotate(\n            cached_num_results=Count(\"submission__phase__challenge_id\"),\n            cached_latest_result=Max(\"created\"),\n        )\n    )\n    evaluation_info_by_challenge = {\n        str(v[\"submission__phase__challenge_id\"]): v for v in evaluation_info\n    }\n    participant_counts = (\n        get_user_model()\n        .objects.values(\"groups__participants_of_challenge\")\n        .annotate(cached_num_participants=Count(\"pk\"))\n    )\n    participant_counts_by_challenge = {\n        str(v[\"groups__participants_of_challenge\"]): v\n        for v in participant_counts\n    }\n\n    for c in challenges:\n        c.cached_num_results = evaluation_info_by_challenge.get(\n            str(c.pk), {}\n        ).get(\"cached_num_results\", 0)\n        c.cached_latest_result = evaluation_info_by_challenge.get(\n            str(c.pk), {}\n        ).get(\"cached_latest_result\", None)\n        c.cached_num_participants = participant_counts_by_challenge.get(\n            str(c.pk), {}\n        ).get(\"cached_num_participants\", 0)\n\n    Challenge.objects.bulk_update(\n        challenges,\n        [\n            \"cached_num_results\",\n            \"cached_num_participants\",\n            \"cached_latest_result\",\n        ],\n    )\n\n\n@shared_task\ndef check_external_challenge_urls():\n    \"\"\"\n    Checks that all external challenge urls are reachable.\n\n    Emails the managers if any of the challenges are not.\n    \"\"\"\n    challenges = ExternalChallenge.objects.filter(hidden=False)\n    errors = []\n\n    for challenge in challenges:\n        try:\n            url = challenge.homepage\n            if not url.startswith(\"http\"):\n                url = \"http://\" + url\n            r = get(url, timeout=60)\n            # raise an exception when we receive a http error (e.g., 404)\n            r.raise_for_status()\n        except exceptions.RequestException as err:\n            update_url = reverse(\n                \"challenges:external-update\",\n                kwargs={\"short_name\": challenge.short_name},\n            )\n            errors.append(\n                f\"Error when trying to access '{challenge}': {err}. You can \"\n                f\"update it here: {update_url}\"\n            )\n\n    if errors:\n        mail_managers(\n            subject=f\"Unreachable external challenges ({len(errors)})\",\n            message=\"\\n\\n\".join(errors),\n        )\n", "path": "app/grandchallenge/challenges/tasks.py"}]}