We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Визуализировать результаты батлов
<img width="1113" alt="image" src="https://user-images.githubusercontent.com/19980512/81127819-1f135780-8f48-11ea-83bc-7c56e6e849e4.png">

Было бы круто как-то визуализировать полоску в зависимости от результатов баттла. Чтобы такой раз — и увидел результат, а не подсчитывал, где больше аргументов и плюсов

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `posts/templatetags/battle.py`
Content:
```
1 from django import template
2 from django.template import loader
3 
4 register = template.Library()
5 
6 
7 battle_stats_template = loader.get_template("posts/widgets/battle_stats.html")
8 
9 
10 def _is_argument_for_side(comment, side):
11     for_side = comment.metadata and comment.metadata.get("battle", {}).get("side") == side
12 
13     return not comment.is_deleted and not comment.reply_to_id and for_side
14 
15 
16 @register.simple_tag()
17 def battle_stats(post, comments):
18     arguments_for_a = [c for c in comments if _is_argument_for_side(c, "a")]
19     arguments_for_b = [c for c in comments if _is_argument_for_side(c, "b")]
20 
21     total_votes_a = sum(c.upvotes for c in arguments_for_a)
22     total_votes_b = sum(c.upvotes for c in arguments_for_b)
23     return battle_stats_template.render({
24         "total_arguments": {
25             "a": len(arguments_for_a),
26             "b": len(arguments_for_b),
27         },
28         "total_votes": {
29             "a": total_votes_a,
30             "b": total_votes_b,
31         },
32         "battle": post,
33     })
34 
35 
36 @register.filter()
37 def side_name(battle, side_code):
38     if battle and battle.metadata and battle.metadata.get("battle"):
39         return battle.metadata["battle"]["sides"][side_code]["name"]
40     return ""
41 
42
```
--- 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()

```

diff --git a/posts/templatetags/battle.py b/posts/templatetags/battle.py
--- a/posts/templatetags/battle.py
+++ b/posts/templatetags/battle.py
@@ -3,7 +3,6 @@
 
 register = template.Library()
 
-
 battle_stats_template = loader.get_template("posts/widgets/battle_stats.html")
 
 
@@ -20,6 +19,7 @@
 
     total_votes_a = sum(c.upvotes for c in arguments_for_a)
     total_votes_b = sum(c.upvotes for c in arguments_for_b)
+
     return battle_stats_template.render({
         "total_arguments": {
             "a": len(arguments_for_a),
@@ -29,6 +29,7 @@
             "a": total_votes_a,
             "b": total_votes_b,
         },
+        "graph": graph_percentages(len(arguments_for_a), len(arguments_for_b), total_votes_a, total_votes_b),
         "battle": post,
     })
 
@@ -39,3 +40,27 @@
         return battle.metadata["battle"]["sides"][side_code]["name"]
     return ""
 
+
+def graph_percentages(a_arguments: int, b_arguments: int, a_votes: int, b_votes: int):
+    """Counts percentages for battle graph
+
+    Percentage for a side is a rounded up arithmetic average of side's argument and upvote percentages
+
+    For each side: (argument % of total arguments amount + vote % of total votes amount ) / 2
+    """
+    percent_a = 0
+    percent_b = 0
+    total_arguments = a_arguments + b_arguments
+    total_upvotes = a_votes + b_votes
+    if total_arguments > 0:
+        argument_percent = 100 / total_arguments
+        percent_a = a_arguments * argument_percent
+        percent_b = b_arguments * argument_percent
+        if total_upvotes > 0:
+            upvote_percent = 100 / total_upvotes
+            percent_a = (percent_a + a_votes * upvote_percent) / 2
+            percent_b = (percent_b + b_votes * upvote_percent) / 2
+    return {
+        "percent_a": round(percent_a),
+        "percent_b": round(percent_b)
+    }

{"golden_diff": "diff --git a/posts/templatetags/battle.py b/posts/templatetags/battle.py\n--- a/posts/templatetags/battle.py\n+++ b/posts/templatetags/battle.py\n@@ -3,7 +3,6 @@\n \n register = template.Library()\n \n-\n battle_stats_template = loader.get_template(\"posts/widgets/battle_stats.html\")\n \n \n@@ -20,6 +19,7 @@\n \n     total_votes_a = sum(c.upvotes for c in arguments_for_a)\n     total_votes_b = sum(c.upvotes for c in arguments_for_b)\n+\n     return battle_stats_template.render({\n         \"total_arguments\": {\n             \"a\": len(arguments_for_a),\n@@ -29,6 +29,7 @@\n             \"a\": total_votes_a,\n             \"b\": total_votes_b,\n         },\n+        \"graph\": graph_percentages(len(arguments_for_a), len(arguments_for_b), total_votes_a, total_votes_b),\n         \"battle\": post,\n     })\n \n@@ -39,3 +40,27 @@\n         return battle.metadata[\"battle\"][\"sides\"][side_code][\"name\"]\n     return \"\"\n \n+\n+def graph_percentages(a_arguments: int, b_arguments: int, a_votes: int, b_votes: int):\n+    \"\"\"Counts percentages for battle graph\n+\n+    Percentage for a side is a rounded up arithmetic average of side's argument and upvote percentages\n+\n+    For each side: (argument % of total arguments amount + vote % of total votes amount ) / 2\n+    \"\"\"\n+    percent_a = 0\n+    percent_b = 0\n+    total_arguments = a_arguments + b_arguments\n+    total_upvotes = a_votes + b_votes\n+    if total_arguments > 0:\n+        argument_percent = 100 / total_arguments\n+        percent_a = a_arguments * argument_percent\n+        percent_b = b_arguments * argument_percent\n+        if total_upvotes > 0:\n+            upvote_percent = 100 / total_upvotes\n+            percent_a = (percent_a + a_votes * upvote_percent) / 2\n+            percent_b = (percent_b + b_votes * upvote_percent) / 2\n+    return {\n+        \"percent_a\": round(percent_a),\n+        \"percent_b\": round(percent_b)\n+    }\n", "issue": "\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0430\u0442\u043b\u043e\u0432\n<img width=\"1113\" alt=\"image\" src=\"https://user-images.githubusercontent.com/19980512/81127819-1f135780-8f48-11ea-83bc-7c56e6e849e4.png\">\r\n\r\n\u0411\u044b\u043b\u043e \u0431\u044b \u043a\u0440\u0443\u0442\u043e \u043a\u0430\u043a-\u0442\u043e \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043e\u0441\u043a\u0443 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0431\u0430\u0442\u0442\u043b\u0430. \u0427\u0442\u043e\u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0440\u0430\u0437 \u2014 \u0438 \u0443\u0432\u0438\u0434\u0435\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u043d\u0435 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043b, \u0433\u0434\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043f\u043b\u044e\u0441\u043e\u0432\n", "before_files": [{"content": "from django import template\nfrom django.template import loader\n\nregister = template.Library()\n\n\nbattle_stats_template = loader.get_template(\"posts/widgets/battle_stats.html\")\n\n\ndef _is_argument_for_side(comment, side):\n    for_side = comment.metadata and comment.metadata.get(\"battle\", {}).get(\"side\") == side\n\n    return not comment.is_deleted and not comment.reply_to_id and for_side\n\n\n@register.simple_tag()\ndef battle_stats(post, comments):\n    arguments_for_a = [c for c in comments if _is_argument_for_side(c, \"a\")]\n    arguments_for_b = [c for c in comments if _is_argument_for_side(c, \"b\")]\n\n    total_votes_a = sum(c.upvotes for c in arguments_for_a)\n    total_votes_b = sum(c.upvotes for c in arguments_for_b)\n    return battle_stats_template.render({\n        \"total_arguments\": {\n            \"a\": len(arguments_for_a),\n            \"b\": len(arguments_for_b),\n        },\n        \"total_votes\": {\n            \"a\": total_votes_a,\n            \"b\": total_votes_b,\n        },\n        \"battle\": post,\n    })\n\n\n@register.filter()\ndef side_name(battle, side_code):\n    if battle and battle.metadata and battle.metadata.get(\"battle\"):\n        return battle.metadata[\"battle\"][\"sides\"][side_code][\"name\"]\n    return \"\"\n\n", "path": "posts/templatetags/battle.py"}], "after_files": [{"content": "from django import template\nfrom django.template import loader\n\nregister = template.Library()\n\nbattle_stats_template = loader.get_template(\"posts/widgets/battle_stats.html\")\n\n\ndef _is_argument_for_side(comment, side):\n    for_side = comment.metadata and comment.metadata.get(\"battle\", {}).get(\"side\") == side\n\n    return not comment.is_deleted and not comment.reply_to_id and for_side\n\n\n@register.simple_tag()\ndef battle_stats(post, comments):\n    arguments_for_a = [c for c in comments if _is_argument_for_side(c, \"a\")]\n    arguments_for_b = [c for c in comments if _is_argument_for_side(c, \"b\")]\n\n    total_votes_a = sum(c.upvotes for c in arguments_for_a)\n    total_votes_b = sum(c.upvotes for c in arguments_for_b)\n\n    return battle_stats_template.render({\n        \"total_arguments\": {\n            \"a\": len(arguments_for_a),\n            \"b\": len(arguments_for_b),\n        },\n        \"total_votes\": {\n            \"a\": total_votes_a,\n            \"b\": total_votes_b,\n        },\n        \"graph\": graph_percentages(len(arguments_for_a), len(arguments_for_b), total_votes_a, total_votes_b),\n        \"battle\": post,\n    })\n\n\n@register.filter()\ndef side_name(battle, side_code):\n    if battle and battle.metadata and battle.metadata.get(\"battle\"):\n        return battle.metadata[\"battle\"][\"sides\"][side_code][\"name\"]\n    return \"\"\n\n\ndef graph_percentages(a_arguments: int, b_arguments: int, a_votes: int, b_votes: int):\n    \"\"\"Counts percentages for battle graph\n\n    Percentage for a side is a rounded up arithmetic average of side's argument and upvote percentages\n\n    For each side: (argument % of total arguments amount + vote % of total votes amount ) / 2\n    \"\"\"\n    percent_a = 0\n    percent_b = 0\n    total_arguments = a_arguments + b_arguments\n    total_upvotes = a_votes + b_votes\n    if total_arguments > 0:\n        argument_percent = 100 / total_arguments\n        percent_a = a_arguments * argument_percent\n        percent_b = b_arguments * argument_percent\n        if total_upvotes > 0:\n            upvote_percent = 100 / total_upvotes\n            percent_a = (percent_a + a_votes * upvote_percent) / 2\n            percent_b = (percent_b + b_votes * upvote_percent) / 2\n    return {\n        \"percent_a\": round(percent_a),\n        \"percent_b\": round(percent_b)\n    }\n", "path": "posts/templatetags/battle.py"}]}