mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 07:01:36 +01:00
implement balance tool basic func done
This commit is contained in:
94
server.py
94
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":"<div>test</div>"}),
|
||||
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")
|
||||
|
||||
17
templates/balance_response_partial.html
Normal file
17
templates/balance_response_partial.html
Normal file
@@ -0,0 +1,17 @@
|
||||
{% for x in range(5) %}
|
||||
<div class="row">
|
||||
{% set leftP = d["left"][positions[x]] %}
|
||||
{% set rightP = d["right"][positions[x]] %}
|
||||
<div class="col-sm">
|
||||
{{ positions[x] }}
|
||||
</div>
|
||||
<div class="col-sm"
|
||||
{% if requests[leftP][x] | int >= 4 %}style="background: red;"{% endif %}>
|
||||
{{ leftP }}
|
||||
</div>
|
||||
<div class="col-sm"
|
||||
{% if requests[rightP][x] | int >= 4 %}style="background: red;"{% endif %}>
|
||||
{{ rightP }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<button type="button" class="mb-3 btn btn-secondary" onclick="balance()">Go</button>
|
||||
|
||||
<div id="response-container" class="row mt-3 mb-3">
|
||||
<div id="response-container" class="mt-3 mb-3">
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
<li class="nav-item">
|
||||
<a id="button-forward" class="nav-link" href="/?page={{ nextPageNumber }}">Forward</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a id="button-forward" class="nav-link" href="/balance-tool">Balance Tool</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
<!--
|
||||
@@ -33,7 +36,7 @@
|
||||
placeholder="search player...">
|
||||
</li>
|
||||
{{ findPlayer }}
|
||||
<!--- <li class="nav-item right">
|
||||
<!-- <li class="nav-item right">
|
||||
<input id="gotoRank" type="number" aria-label="goto rank"
|
||||
placeholder="goto rank...">
|
||||
</li> -->
|
||||
|
||||
Reference in New Issue
Block a user