prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add a function to filter labels
  When I rechecked the labels of the annotated data, I had no way of filtering out the labels I wanted to see. For example, when I am doing a check of dichotomous annotations, I would like to filter the data set to find out which labels are positive and which are negative, so that I can save time on the check. However, due to the lack of this function, I have to filter one by one from dataset, which wastes a lot of time and manpower.
  
  Thanks for every contributor!
  
  </issue>
  <code>
  [start of backend/examples/filters.py]
  1 from django.db.models import Count, Q
  2 from django_filters.rest_framework import BooleanFilter, FilterSet
  3 
  4 from .models import Example
  5 
  6 
  7 class ExampleFilter(FilterSet):
  8     confirmed = BooleanFilter(field_name="states", method="filter_by_state")
  9 
  10     def filter_by_state(self, queryset, field_name, is_confirmed: bool):
  11         queryset = queryset.annotate(
  12             num_confirm=Count(
  13                 expression=field_name,
  14                 filter=Q(**{f"{field_name}__confirmed_by": self.request.user})
  15                 | Q(project__collaborative_annotation=True),
  16             )
  17         )
  18         if is_confirmed:
  19             queryset = queryset.filter(num_confirm__gte=1)
  20         else:
  21             queryset = queryset.filter(num_confirm__lte=0)
  22         return queryset
  23 
  24     class Meta:
  25         model = Example
  26         fields = ("project", "text", "created_at", "updated_at")
  27
  [end of backend/examples/filters.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/examples/filters.py b/backend/examples/filters.py
  --- a/backend/examples/filters.py
  +++ b/backend/examples/filters.py
  @@ -1,11 +1,12 @@
  -from django.db.models import Count, Q
  -from django_filters.rest_framework import BooleanFilter, FilterSet
  +from django.db.models import Count, Q, QuerySet
  +from django_filters.rest_framework import BooleanFilter, CharFilter, FilterSet
   
   from .models import Example
   
   
   class ExampleFilter(FilterSet):
       confirmed = BooleanFilter(field_name="states", method="filter_by_state")
  +    label = CharFilter(method="filter_by_label")
   
       def filter_by_state(self, queryset, field_name, is_confirmed: bool):
           queryset = queryset.annotate(
  @@ -21,6 +22,35 @@
               queryset = queryset.filter(num_confirm__lte=0)
           return queryset
   
  +    def filter_by_label(self, queryset: QuerySet, field_name: str, label: str) -> QuerySet:
  +        """Filter examples by a given label name.
  +
  +        This performs filtering on all of the following labels at once:
  +        - categories
  +        - spans
  +        - relations
  +        - bboxes
  +        - segmentations
  +
  +        Todo: Consider project type to make filtering more efficient.
  +
  +        Args:
  +            queryset (QuerySet): QuerySet to filter.
  +            field_name (str): This equals to `label`.
  +            label (str): The label name to filter.
  +
  +        Returns:
  +            QuerySet: Filtered examples.
  +        """
  +        queryset = queryset.filter(
  +            Q(categories__label__text=label)
  +            | Q(spans__label__text=label)
  +            | Q(relations__type__text=label)
  +            | Q(bboxes__label__text=label)
  +            | Q(segmentations__label__text=label)
  +        )
  +        return queryset
  +
       class Meta:
           model = Example
  -        fields = ("project", "text", "created_at", "updated_at")
  +        fields = ("project", "text", "created_at", "updated_at", "label")
  
verification_info: {"golden_diff": "diff --git a/backend/examples/filters.py b/backend/examples/filters.py\n--- a/backend/examples/filters.py\n+++ b/backend/examples/filters.py\n@@ -1,11 +1,12 @@\n-from django.db.models import Count, Q\n-from django_filters.rest_framework import BooleanFilter, FilterSet\n+from django.db.models import Count, Q, QuerySet\n+from django_filters.rest_framework import BooleanFilter, CharFilter, FilterSet\n \n from .models import Example\n \n \n class ExampleFilter(FilterSet):\n     confirmed = BooleanFilter(field_name=\"states\", method=\"filter_by_state\")\n+    label = CharFilter(method=\"filter_by_label\")\n \n     def filter_by_state(self, queryset, field_name, is_confirmed: bool):\n         queryset = queryset.annotate(\n@@ -21,6 +22,35 @@\n             queryset = queryset.filter(num_confirm__lte=0)\n         return queryset\n \n+    def filter_by_label(self, queryset: QuerySet, field_name: str, label: str) -> QuerySet:\n+        \"\"\"Filter examples by a given label name.\n+\n+        This performs filtering on all of the following labels at once:\n+        - categories\n+        - spans\n+        - relations\n+        - bboxes\n+        - segmentations\n+\n+        Todo: Consider project type to make filtering more efficient.\n+\n+        Args:\n+            queryset (QuerySet): QuerySet to filter.\n+            field_name (str): This equals to `label`.\n+            label (str): The label name to filter.\n+\n+        Returns:\n+            QuerySet: Filtered examples.\n+        \"\"\"\n+        queryset = queryset.filter(\n+            Q(categories__label__text=label)\n+            | Q(spans__label__text=label)\n+            | Q(relations__type__text=label)\n+            | Q(bboxes__label__text=label)\n+            | Q(segmentations__label__text=label)\n+        )\n+        return queryset\n+\n     class Meta:\n         model = Example\n-        fields = (\"project\", \"text\", \"created_at\", \"updated_at\")\n+        fields = (\"project\", \"text\", \"created_at\", \"updated_at\", \"label\")\n", "issue": "Add a function to filter labels\nWhen I rechecked the labels of the annotated data, I had no way of filtering out the labels I wanted to see. For example, when I am doing a check of dichotomous annotations, I would like to filter the data set to find out which labels are positive and which are negative, so that I can save time on the check. However, due to the lack of this function, I have to filter one by one from dataset, which wastes a lot of time and manpower.\r\n\r\nThanks for every contributor!\n", "before_files": [{"content": "from django.db.models import Count, Q\nfrom django_filters.rest_framework import BooleanFilter, FilterSet\n\nfrom .models import Example\n\n\nclass ExampleFilter(FilterSet):\n    confirmed = BooleanFilter(field_name=\"states\", method=\"filter_by_state\")\n\n    def filter_by_state(self, queryset, field_name, is_confirmed: bool):\n        queryset = queryset.annotate(\n            num_confirm=Count(\n                expression=field_name,\n                filter=Q(**{f\"{field_name}__confirmed_by\": self.request.user})\n                | Q(project__collaborative_annotation=True),\n            )\n        )\n        if is_confirmed:\n            queryset = queryset.filter(num_confirm__gte=1)\n        else:\n            queryset = queryset.filter(num_confirm__lte=0)\n        return queryset\n\n    class Meta:\n        model = Example\n        fields = (\"project\", \"text\", \"created_at\", \"updated_at\")\n", "path": "backend/examples/filters.py"}]}