prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Stats are wrong for children where the child name is repeated in the childs descendants
  this is causing stats to foo
  
  </issue>
  <code>
  [start of pootle/apps/pootle_data/directory_data.py]
  1 # -*- coding: utf-8 -*-
  2 #
  3 # Copyright (C) Pootle contributors.
  4 #
  5 # This file is a part of the Pootle project. It is distributed under the GPL3
  6 # or later license. See the LICENSE file for a copy of the license and the
  7 # AUTHORS file for copyright and authorship information.
  8 
  9 from django.db.models import Max
  10 
  11 from pootle_translationproject.models import TranslationProject
  12 
  13 from .utils import RelatedStoresDataTool
  14 
  15 
  16 class DirectoryDataTool(RelatedStoresDataTool):
  17     """Retrieves aggregate stats for a Directory"""
  18 
  19     group_by = ("store__parent__tp_path", )
  20     cache_key_name = "directory"
  21 
  22     @property
  23     def context_name(self):
  24         return self.context.pootle_path
  25 
  26     @property
  27     def max_unit_revision(self):
  28         try:
  29             return self.context.translationproject.data_tool.max_unit_revision
  30         except TranslationProject.DoesNotExist:
  31             return self.all_stat_data.aggregate(rev=Max("max_unit_revision"))["rev"]
  32 
  33     def filter_data(self, qs):
  34         return (
  35             qs.filter(
  36                 store__translation_project=self.context.translation_project,
  37                 store__parent__tp_path__startswith=self.context.tp_path)
  38               .exclude(store__parent=self.context))
  39 
  40     def get_children_stats(self, qs):
  41         children = {}
  42         for child in qs.iterator():
  43             self.add_child_stats(children, child)
  44         child_stores = self.data_model.filter(store__parent=self.context).values(
  45             *("store__name", ) + self.max_fields + self.sum_fields)
  46         for child in child_stores:
  47             self.add_child_stats(
  48                 children,
  49                 child,
  50                 root=child["store__name"],
  51                 use_aggregates=False)
  52         self.add_submission_info(self.stat_data, children)
  53         self.add_last_created_info(child_stores, children)
  54         return children
  55 
  56     def get_root_child_path(self, child):
  57         return (
  58             child["store__parent__tp_path"].replace(
  59                 self.context.tp_path, "").split("/")[0])
  60
  [end of pootle/apps/pootle_data/directory_data.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/pootle/apps/pootle_data/directory_data.py b/pootle/apps/pootle_data/directory_data.py
  --- a/pootle/apps/pootle_data/directory_data.py
  +++ b/pootle/apps/pootle_data/directory_data.py
  @@ -54,6 +54,5 @@
           return children
   
       def get_root_child_path(self, child):
  -        return (
  -            child["store__parent__tp_path"].replace(
  -                self.context.tp_path, "").split("/")[0])
  +        return child["store__parent__tp_path"][
  +            len(self.context.tp_path):].split("/")[0]
  
verification_info: {"golden_diff": "diff --git a/pootle/apps/pootle_data/directory_data.py b/pootle/apps/pootle_data/directory_data.py\n--- a/pootle/apps/pootle_data/directory_data.py\n+++ b/pootle/apps/pootle_data/directory_data.py\n@@ -54,6 +54,5 @@\n         return children\n \n     def get_root_child_path(self, child):\n-        return (\n-            child[\"store__parent__tp_path\"].replace(\n-                self.context.tp_path, \"\").split(\"/\")[0])\n+        return child[\"store__parent__tp_path\"][\n+            len(self.context.tp_path):].split(\"/\")[0]\n", "issue": "Stats are wrong for children where the child name is repeated in the childs descendants\nthis is causing stats to foo\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nfrom django.db.models import Max\n\nfrom pootle_translationproject.models import TranslationProject\n\nfrom .utils import RelatedStoresDataTool\n\n\nclass DirectoryDataTool(RelatedStoresDataTool):\n    \"\"\"Retrieves aggregate stats for a Directory\"\"\"\n\n    group_by = (\"store__parent__tp_path\", )\n    cache_key_name = \"directory\"\n\n    @property\n    def context_name(self):\n        return self.context.pootle_path\n\n    @property\n    def max_unit_revision(self):\n        try:\n            return self.context.translationproject.data_tool.max_unit_revision\n        except TranslationProject.DoesNotExist:\n            return self.all_stat_data.aggregate(rev=Max(\"max_unit_revision\"))[\"rev\"]\n\n    def filter_data(self, qs):\n        return (\n            qs.filter(\n                store__translation_project=self.context.translation_project,\n                store__parent__tp_path__startswith=self.context.tp_path)\n              .exclude(store__parent=self.context))\n\n    def get_children_stats(self, qs):\n        children = {}\n        for child in qs.iterator():\n            self.add_child_stats(children, child)\n        child_stores = self.data_model.filter(store__parent=self.context).values(\n            *(\"store__name\", ) + self.max_fields + self.sum_fields)\n        for child in child_stores:\n            self.add_child_stats(\n                children,\n                child,\n                root=child[\"store__name\"],\n                use_aggregates=False)\n        self.add_submission_info(self.stat_data, children)\n        self.add_last_created_info(child_stores, children)\n        return children\n\n    def get_root_child_path(self, child):\n        return (\n            child[\"store__parent__tp_path\"].replace(\n                self.context.tp_path, \"\").split(\"/\")[0])\n", "path": "pootle/apps/pootle_data/directory_data.py"}]}