prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Stats are wrong for children where the child name is repeated in the childs descendants
  this is causing stats to foo
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pootle/apps/pootle_data/directory_data.py`
  Content:
  ```
  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 FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
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"}], "after_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 child[\"store__parent__tp_path\"][\n            len(self.context.tp_path):].split(\"/\")[0]\n", "path": "pootle/apps/pootle_data/directory_data.py"}]}