prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Most Beloved Book on Instance has zero local reviews
  **Describe the bug**
  On the About this Instance page there's a cool section that shows various books, like Most Beloved, Most Contentious, Most Wanted to Read. The Most Beloved category, however, appears to be driven by federated statistics and not local statistics. A book with no local ratings is listed as the most Beloved Book because *other* instances have rated it highly. 
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Don't have a lot of ratings on your instance.
  2. Import a book that is highly rated from another (in this case 3 reviews, all 5 stars) 
  3. Go to instancedomain/about and view the Most Beloved book
  
  I'm really only guessing on these steps to reproduce, it's just something I stumbled across.
  
  **Expected behavior**
  I expect the most beloved book to be beloved by my instance, not other instances. Federated statistics would also be cool, but it doesn't seem like this section is meant to represent the network. 
  
  **Instance**
  https://tankie.ml/
  
  ---
  
  **Smartphone (please complete the following information):**
      - Device: Samsung Galaxy A52 5G
      - OS: Android 12
      - Browser: Firefox
      - Version: 97.2.0
      
  
  </issue>
  <code>
  [start of bookwyrm/templatetags/landing_page_tags.py]
  1 """ template filters """
  2 from django import template
  3 from django.db.models import Avg, StdDev, Count, F, Q
  4 
  5 from bookwyrm import models
  6 
  7 register = template.Library()
  8 
  9 
  10 @register.simple_tag(takes_context=False)
  11 def get_book_superlatives():
  12     """get book stats for the about page"""
  13     total_ratings = models.Review.objects.filter(local=True, deleted=False).count()
  14     data = {}
  15     data["top_rated"] = (
  16         models.Work.objects.annotate(
  17             rating=Avg(
  18                 "editions__review__rating",
  19                 filter=Q(editions__review__local=True, editions__review__deleted=False),
  20             ),
  21             rating_count=Count(
  22                 "editions__review",
  23                 filter=Q(editions__review__local=True, editions__review__deleted=False),
  24             ),
  25         )
  26         .annotate(weighted=F("rating") * F("rating_count") / total_ratings)
  27         .filter(rating__gt=4, weighted__gt=0)
  28         .order_by("-weighted")
  29         .first()
  30     )
  31 
  32     data["controversial"] = (
  33         models.Work.objects.annotate(
  34             deviation=StdDev(
  35                 "editions__review__rating",
  36                 filter=Q(editions__review__local=True, editions__review__deleted=False),
  37             ),
  38             rating_count=Count(
  39                 "editions__review",
  40                 filter=Q(editions__review__local=True, editions__review__deleted=False),
  41             ),
  42         )
  43         .annotate(weighted=F("deviation") * F("rating_count") / total_ratings)
  44         .filter(weighted__gt=0)
  45         .order_by("-weighted")
  46         .first()
  47     )
  48 
  49     data["wanted"] = (
  50         models.Work.objects.annotate(
  51             shelf_count=Count(
  52                 "editions__shelves", filter=Q(editions__shelves__identifier="to-read")
  53             )
  54         )
  55         .order_by("-shelf_count")
  56         .first()
  57     )
  58     return data
  59 
  60 
  61 @register.simple_tag(takes_context=False)
  62 def get_landing_books():
  63     """list of books for the landing page"""
  64     return list(
  65         set(
  66             models.Edition.objects.filter(
  67                 review__published_date__isnull=False,
  68                 review__deleted=False,
  69                 review__user__local=True,
  70                 review__privacy__in=["public", "unlisted"],
  71             )
  72             .exclude(cover__exact="")
  73             .distinct()
  74             .order_by("-review__published_date")[:6]
  75         )
  76     )
  77
  [end of bookwyrm/templatetags/landing_page_tags.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/bookwyrm/templatetags/landing_page_tags.py b/bookwyrm/templatetags/landing_page_tags.py
  --- a/bookwyrm/templatetags/landing_page_tags.py
  +++ b/bookwyrm/templatetags/landing_page_tags.py
  @@ -16,11 +16,15 @@
           models.Work.objects.annotate(
               rating=Avg(
                   "editions__review__rating",
  -                filter=Q(editions__review__local=True, editions__review__deleted=False),
  +                filter=Q(
  +                    editions__review__user__local=True, editions__review__deleted=False
  +                ),
               ),
               rating_count=Count(
                   "editions__review",
  -                filter=Q(editions__review__local=True, editions__review__deleted=False),
  +                filter=Q(
  +                    editions__review__user__local=True, editions__review__deleted=False
  +                ),
               ),
           )
           .annotate(weighted=F("rating") * F("rating_count") / total_ratings)
  @@ -33,11 +37,15 @@
           models.Work.objects.annotate(
               deviation=StdDev(
                   "editions__review__rating",
  -                filter=Q(editions__review__local=True, editions__review__deleted=False),
  +                filter=Q(
  +                    editions__review__user__local=True, editions__review__deleted=False
  +                ),
               ),
               rating_count=Count(
                   "editions__review",
  -                filter=Q(editions__review__local=True, editions__review__deleted=False),
  +                filter=Q(
  +                    editions__review__user__local=True, editions__review__deleted=False
  +                ),
               ),
           )
           .annotate(weighted=F("deviation") * F("rating_count") / total_ratings)
  
verification_info: {"golden_diff": "diff --git a/bookwyrm/templatetags/landing_page_tags.py b/bookwyrm/templatetags/landing_page_tags.py\n--- a/bookwyrm/templatetags/landing_page_tags.py\n+++ b/bookwyrm/templatetags/landing_page_tags.py\n@@ -16,11 +16,15 @@\n         models.Work.objects.annotate(\n             rating=Avg(\n                 \"editions__review__rating\",\n-                filter=Q(editions__review__local=True, editions__review__deleted=False),\n+                filter=Q(\n+                    editions__review__user__local=True, editions__review__deleted=False\n+                ),\n             ),\n             rating_count=Count(\n                 \"editions__review\",\n-                filter=Q(editions__review__local=True, editions__review__deleted=False),\n+                filter=Q(\n+                    editions__review__user__local=True, editions__review__deleted=False\n+                ),\n             ),\n         )\n         .annotate(weighted=F(\"rating\") * F(\"rating_count\") / total_ratings)\n@@ -33,11 +37,15 @@\n         models.Work.objects.annotate(\n             deviation=StdDev(\n                 \"editions__review__rating\",\n-                filter=Q(editions__review__local=True, editions__review__deleted=False),\n+                filter=Q(\n+                    editions__review__user__local=True, editions__review__deleted=False\n+                ),\n             ),\n             rating_count=Count(\n                 \"editions__review\",\n-                filter=Q(editions__review__local=True, editions__review__deleted=False),\n+                filter=Q(\n+                    editions__review__user__local=True, editions__review__deleted=False\n+                ),\n             ),\n         )\n         .annotate(weighted=F(\"deviation\") * F(\"rating_count\") / total_ratings)\n", "issue": "Most Beloved Book on Instance has zero local reviews\n**Describe the bug**\nOn the About this Instance page there's a cool section that shows various books, like Most Beloved, Most Contentious, Most Wanted to Read. The Most Beloved category, however, appears to be driven by federated statistics and not local statistics. A book with no local ratings is listed as the most Beloved Book because *other* instances have rated it highly. \n\n**To Reproduce**\nSteps to reproduce the behavior:\n1. Don't have a lot of ratings on your instance.\n2. Import a book that is highly rated from another (in this case 3 reviews, all 5 stars) \n3. Go to instancedomain/about and view the Most Beloved book\n\nI'm really only guessing on these steps to reproduce, it's just something I stumbled across.\n\n**Expected behavior**\nI expect the most beloved book to be beloved by my instance, not other instances. Federated statistics would also be cool, but it doesn't seem like this section is meant to represent the network. \n\n**Instance**\nhttps://tankie.ml/\n\n---\n\n**Smartphone (please complete the following information):**\n    - Device: Samsung Galaxy A52 5G\n    - OS: Android 12\n    - Browser: Firefox\n    - Version: 97.2.0\n    \n", "before_files": [{"content": "\"\"\" template filters \"\"\"\nfrom django import template\nfrom django.db.models import Avg, StdDev, Count, F, Q\n\nfrom bookwyrm import models\n\nregister = template.Library()\n\n\n@register.simple_tag(takes_context=False)\ndef get_book_superlatives():\n    \"\"\"get book stats for the about page\"\"\"\n    total_ratings = models.Review.objects.filter(local=True, deleted=False).count()\n    data = {}\n    data[\"top_rated\"] = (\n        models.Work.objects.annotate(\n            rating=Avg(\n                \"editions__review__rating\",\n                filter=Q(editions__review__local=True, editions__review__deleted=False),\n            ),\n            rating_count=Count(\n                \"editions__review\",\n                filter=Q(editions__review__local=True, editions__review__deleted=False),\n            ),\n        )\n        .annotate(weighted=F(\"rating\") * F(\"rating_count\") / total_ratings)\n        .filter(rating__gt=4, weighted__gt=0)\n        .order_by(\"-weighted\")\n        .first()\n    )\n\n    data[\"controversial\"] = (\n        models.Work.objects.annotate(\n            deviation=StdDev(\n                \"editions__review__rating\",\n                filter=Q(editions__review__local=True, editions__review__deleted=False),\n            ),\n            rating_count=Count(\n                \"editions__review\",\n                filter=Q(editions__review__local=True, editions__review__deleted=False),\n            ),\n        )\n        .annotate(weighted=F(\"deviation\") * F(\"rating_count\") / total_ratings)\n        .filter(weighted__gt=0)\n        .order_by(\"-weighted\")\n        .first()\n    )\n\n    data[\"wanted\"] = (\n        models.Work.objects.annotate(\n            shelf_count=Count(\n                \"editions__shelves\", filter=Q(editions__shelves__identifier=\"to-read\")\n            )\n        )\n        .order_by(\"-shelf_count\")\n        .first()\n    )\n    return data\n\n\n@register.simple_tag(takes_context=False)\ndef get_landing_books():\n    \"\"\"list of books for the landing page\"\"\"\n    return list(\n        set(\n            models.Edition.objects.filter(\n                review__published_date__isnull=False,\n                review__deleted=False,\n                review__user__local=True,\n                review__privacy__in=[\"public\", \"unlisted\"],\n            )\n            .exclude(cover__exact=\"\")\n            .distinct()\n            .order_by(\"-review__published_date\")[:6]\n        )\n    )\n", "path": "bookwyrm/templatetags/landing_page_tags.py"}]}