prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Wrong progress in collaborative annotation ('Share annotations across all users')
  How to reproduce the behaviour
  ---------
  Progress is shown as individual progress instead of total progress when 'Share annotations across all users' is ticked in project setting.
  
  Your Environment
  ---------
  <!-- Include details of your environment.-->
  *   Operating System: wsl2+ubuntu20.04
  *   Python Version Used: 3.8
  *   When you install doccano: 20220403
  *   How did you install doccano (Heroku button etc): source
  
  
  </issue>
  <code>
  [start of backend/metrics/views.py]
  1 import abc
  2 
  3 from rest_framework import status
  4 from rest_framework.permissions import IsAuthenticated
  5 from rest_framework.response import Response
  6 from rest_framework.views import APIView
  7 
  8 from examples.models import Example, ExampleState
  9 from label_types.models import CategoryType, LabelType, RelationType, SpanType
  10 from labels.models import Category, Label, Relation, Span
  11 from projects.models import Member
  12 from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly
  13 
  14 
  15 class ProgressAPI(APIView):
  16     permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)]
  17 
  18     def get(self, request, *args, **kwargs):
  19         examples = Example.objects.filter(project=self.kwargs["project_id"]).values("id")
  20         total = examples.count()
  21         complete = ExampleState.objects.count_done(examples, user=self.request.user)
  22         data = {"total": total, "remaining": total - complete, "complete": complete}
  23         return Response(data=data, status=status.HTTP_200_OK)
  24 
  25 
  26 class MemberProgressAPI(APIView):
  27     permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)]
  28 
  29     def get(self, request, *args, **kwargs):
  30         examples = Example.objects.filter(project=self.kwargs["project_id"]).values("id")
  31         members = Member.objects.filter(project=self.kwargs["project_id"])
  32         data = ExampleState.objects.measure_member_progress(examples, members)
  33         return Response(data=data, status=status.HTTP_200_OK)
  34 
  35 
  36 class LabelDistribution(abc.ABC, APIView):
  37     permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)]
  38     model = Label
  39     label_type = LabelType
  40 
  41     def get(self, request, *args, **kwargs):
  42         labels = self.label_type.objects.filter(project=self.kwargs["project_id"])
  43         examples = Example.objects.filter(project=self.kwargs["project_id"]).values("id")
  44         members = Member.objects.filter(project=self.kwargs["project_id"])
  45         data = self.model.objects.calc_label_distribution(examples, members, labels)
  46         return Response(data=data, status=status.HTTP_200_OK)
  47 
  48 
  49 class CategoryTypeDistribution(LabelDistribution):
  50     model = Category
  51     label_type = CategoryType
  52 
  53 
  54 class SpanTypeDistribution(LabelDistribution):
  55     model = Span
  56     label_type = SpanType
  57 
  58 
  59 class RelationTypeDistribution(LabelDistribution):
  60     model = Relation
  61     label_type = RelationType
  62
  [end of backend/metrics/views.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/backend/metrics/views.py b/backend/metrics/views.py
  --- a/backend/metrics/views.py
  +++ b/backend/metrics/views.py
  @@ -1,5 +1,6 @@
   import abc
   
  +from django.shortcuts import get_object_or_404
   from rest_framework import status
   from rest_framework.permissions import IsAuthenticated
   from rest_framework.response import Response
  @@ -8,7 +9,7 @@
   from examples.models import Example, ExampleState
   from label_types.models import CategoryType, LabelType, RelationType, SpanType
   from labels.models import Category, Label, Relation, Span
  -from projects.models import Member
  +from projects.models import Member, Project
   from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly
   
   
  @@ -18,7 +19,11 @@
       def get(self, request, *args, **kwargs):
           examples = Example.objects.filter(project=self.kwargs["project_id"]).values("id")
           total = examples.count()
  -        complete = ExampleState.objects.count_done(examples, user=self.request.user)
  +        project = get_object_or_404(Project, pk=self.kwargs["project_id"])
  +        if project.collaborative_annotation:
  +            complete = ExampleState.objects.count_done(examples)
  +        else:
  +            complete = ExampleState.objects.count_done(examples, user=self.request.user)
           data = {"total": total, "remaining": total - complete, "complete": complete}
           return Response(data=data, status=status.HTTP_200_OK)
  
verification_info: {"golden_diff": "diff --git a/backend/metrics/views.py b/backend/metrics/views.py\n--- a/backend/metrics/views.py\n+++ b/backend/metrics/views.py\n@@ -1,5 +1,6 @@\n import abc\n \n+from django.shortcuts import get_object_or_404\n from rest_framework import status\n from rest_framework.permissions import IsAuthenticated\n from rest_framework.response import Response\n@@ -8,7 +9,7 @@\n from examples.models import Example, ExampleState\n from label_types.models import CategoryType, LabelType, RelationType, SpanType\n from labels.models import Category, Label, Relation, Span\n-from projects.models import Member\n+from projects.models import Member, Project\n from projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly\n \n \n@@ -18,7 +19,11 @@\n     def get(self, request, *args, **kwargs):\n         examples = Example.objects.filter(project=self.kwargs[\"project_id\"]).values(\"id\")\n         total = examples.count()\n-        complete = ExampleState.objects.count_done(examples, user=self.request.user)\n+        project = get_object_or_404(Project, pk=self.kwargs[\"project_id\"])\n+        if project.collaborative_annotation:\n+            complete = ExampleState.objects.count_done(examples)\n+        else:\n+            complete = ExampleState.objects.count_done(examples, user=self.request.user)\n         data = {\"total\": total, \"remaining\": total - complete, \"complete\": complete}\n         return Response(data=data, status=status.HTTP_200_OK)\n", "issue": "Wrong progress in collaborative annotation ('Share annotations across all users')\nHow to reproduce the behaviour\r\n---------\r\nProgress is shown as individual progress instead of total progress when 'Share annotations across all users' is ticked in project setting.\r\n\r\nYour Environment\r\n---------\r\n<!-- Include details of your environment.-->\r\n*   Operating System: wsl2+ubuntu20.04\r\n*   Python Version Used: 3.8\r\n*   When you install doccano: 20220403\r\n*   How did you install doccano (Heroku button etc): source\r\n\n", "before_files": [{"content": "import abc\n\nfrom rest_framework import status\nfrom rest_framework.permissions import IsAuthenticated\nfrom rest_framework.response import Response\nfrom rest_framework.views import APIView\n\nfrom examples.models import Example, ExampleState\nfrom label_types.models import CategoryType, LabelType, RelationType, SpanType\nfrom labels.models import Category, Label, Relation, Span\nfrom projects.models import Member\nfrom projects.permissions import IsProjectAdmin, IsProjectStaffAndReadOnly\n\n\nclass ProgressAPI(APIView):\n    permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)]\n\n    def get(self, request, *args, **kwargs):\n        examples = Example.objects.filter(project=self.kwargs[\"project_id\"]).values(\"id\")\n        total = examples.count()\n        complete = ExampleState.objects.count_done(examples, user=self.request.user)\n        data = {\"total\": total, \"remaining\": total - complete, \"complete\": complete}\n        return Response(data=data, status=status.HTTP_200_OK)\n\n\nclass MemberProgressAPI(APIView):\n    permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)]\n\n    def get(self, request, *args, **kwargs):\n        examples = Example.objects.filter(project=self.kwargs[\"project_id\"]).values(\"id\")\n        members = Member.objects.filter(project=self.kwargs[\"project_id\"])\n        data = ExampleState.objects.measure_member_progress(examples, members)\n        return Response(data=data, status=status.HTTP_200_OK)\n\n\nclass LabelDistribution(abc.ABC, APIView):\n    permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)]\n    model = Label\n    label_type = LabelType\n\n    def get(self, request, *args, **kwargs):\n        labels = self.label_type.objects.filter(project=self.kwargs[\"project_id\"])\n        examples = Example.objects.filter(project=self.kwargs[\"project_id\"]).values(\"id\")\n        members = Member.objects.filter(project=self.kwargs[\"project_id\"])\n        data = self.model.objects.calc_label_distribution(examples, members, labels)\n        return Response(data=data, status=status.HTTP_200_OK)\n\n\nclass CategoryTypeDistribution(LabelDistribution):\n    model = Category\n    label_type = CategoryType\n\n\nclass SpanTypeDistribution(LabelDistribution):\n    model = Span\n    label_type = SpanType\n\n\nclass RelationTypeDistribution(LabelDistribution):\n    model = Relation\n    label_type = RelationType\n", "path": "backend/metrics/views.py"}]}