diff --git a/server.py b/server.py
index e880a4d..7c77f7b 100755
--- a/server.py
+++ b/server.py
@@ -135,13 +135,99 @@ def rounds():
@app.route("/balance-tool", methods=['GET', 'POST'])
def balanceTool():
+ positions=["Top", "Jungle", "Mid", "Support", "Bottom"]
+
if flask.request.method == 'POST':
- print(flask.request.json)
- return flask.Response(json.dumps({"content":"
test
"}),
- 200, mimetype='application/json')
+
+ doneDict = dict()
+ retDict = { "left" : {}, "right" : {} }
+ recheckDict = {}
+ for p in positions:
+ retDict["left"].update({ p : "" })
+ retDict["right"].update({ p :"" })
+
+ # basic greedy #
+ for x in range(5):
+ for prio in range(1,6):
+ for k,v in flask.request.json.items():
+ if k in doneDict:
+ continue
+ if v[x] == str(prio):
+ if retDict["left"][positions[x]] == "":
+ retDict["left"][positions[x]] = k
+ doneDict.update({ k : True })
+ if prio == 5:
+ recheckDict.update({ k : x })
+ elif retDict["right"][positions[x]] == "":
+ retDict["right"][positions[x]] = k
+ doneDict.update({ k : True })
+ if prio == 5:
+ recheckDict.update({ k : x })
+
+ # try to improve the bad ones #
+ swapped = {}
+ print(recheckDict)
+ for k,v in recheckDict.items():
+ if k in swapped:
+ print("k in swapp")
+ continue
+
+ # determine own side for backswapping #
+ selfSide = None
+ if k in retDict["left"].values():
+ selfSide = "left"
+ else:
+ selfSide = "right"
+
+
+ # go through all positions look for better matches #
+ for posId in range(5):
+
+ currentHolderLeft = retDict["left"][positions[posId]]
+ currentHolderRight = retDict["right"][positions[posId]]
+
+ # right side swaps #
+ if (int(flask.request.json[currentHolderRight][v]) <=
+ int(flask.request.json[currentHolderRight][posId]) and
+ currentHolderRight != k and
+ not currentHolderRight in swapped):
+
+ print("(R) Swapping {} with {}".format(k, currentHolderRight))
+
+ retDict["right"][positions[posId]] = k
+ retDict[selfSide][positions[v]] = currentHolderRight
+
+ swapped.update({ k : True})
+ swapped.update({ currentHolderRight : True})
+
+ break
+
+ # left side swaps #
+ if (int(flask.request.json[currentHolderRight][v]) <=
+ int(flask.request.json[currentHolderLeft][posId]) and
+ currentHolderLeft != k and
+ not currentHolderRight in swapped):
+
+ print("(L) Swapping {} with {}".format(k, currentHolderLeft))
+
+ retDict["left"][positions[posId]] = k
+ retDict[selfSide][positions[v]] = currentHolderLeft
+
+ swapped.update({ k : True})
+ swapped.update({ currentHolderLeft : True})
+
+ break
+
+
+
+ renderContent = flask.render_template("balance_response_partial.html", d=retDict,
+ requests=flask.request.json,
+ positions=positions)
+ return flask.Response(
+ json.dumps({ "content": renderContent }), 200, mimetype='application/json')
else:
return flask.render_template("json_builder.html",
- positions=["Top", "Jungle", "Mid", "Support", "Bottom"],
+ positions=positions,
sides=["left", "right"])
@app.route("/player")
diff --git a/templates/balance_response_partial.html b/templates/balance_response_partial.html
new file mode 100644
index 0000000..c5289cf
--- /dev/null
+++ b/templates/balance_response_partial.html
@@ -0,0 +1,17 @@
+ {% for x in range(5) %}
+
+ {% set leftP = d["left"][positions[x]] %}
+ {% set rightP = d["right"][positions[x]] %}
+
+ {{ positions[x] }}
+
+
= 4 %}style="background: red;"{% endif %}>
+ {{ leftP }}
+
+
= 4 %}style="background: red;"{% endif %}>
+ {{ rightP }}
+
+
+ {% endfor %}
diff --git a/templates/json_builder.html b/templates/json_builder.html
index 11b4150..2cb997f 100644
--- a/templates/json_builder.html
+++ b/templates/json_builder.html
@@ -18,7 +18,7 @@
-
+
diff --git a/templates/navbar_leaderboard.html b/templates/navbar_leaderboard.html
index c98c1ed..ff75478 100644
--- a/templates/navbar_leaderboard.html
+++ b/templates/navbar_leaderboard.html
@@ -18,6 +18,9 @@
Forward
+
+ Balance Tool
+