mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-09 08:28:32 +01:00
implement simple balance by rating
This commit is contained in:
BIN
rounds.sqlite
BIN
rounds.sqlite
Binary file not shown.
61
server.py
61
server.py
@@ -118,7 +118,7 @@ def rounds():
|
|||||||
end = flask.request.args.get("end")
|
end = flask.request.args.get("end")
|
||||||
|
|
||||||
if not start or not end:
|
if not start or not end:
|
||||||
start = datetime.datetime.now() - datetime.timedelta(days=7)
|
start = datetime.datetime.now() - datetime.timedelta(days=365)
|
||||||
end = datetime.datetime.now()
|
end = datetime.datetime.now()
|
||||||
else:
|
else:
|
||||||
start = datetime.datetime.fromtimestamp(start)
|
start = datetime.datetime.fromtimestamp(start)
|
||||||
@@ -189,10 +189,16 @@ def balanceToolData():
|
|||||||
def balanceTool():
|
def balanceTool():
|
||||||
positions=["Top", "Jungle", "Mid", "Support", "Bottom"]
|
positions=["Top", "Jungle", "Mid", "Support", "Bottom"]
|
||||||
|
|
||||||
|
db = DatabaseConnection(app.config["DB_PATH"])
|
||||||
|
|
||||||
if flask.request.method == 'POST':
|
if flask.request.method == 'POST':
|
||||||
|
|
||||||
players = []
|
players = []
|
||||||
|
threshold = 2
|
||||||
for k,v in flask.request.json.items():
|
for k,v in flask.request.json.items():
|
||||||
|
if k == "acceptable-solution-threshold":
|
||||||
|
threshold = v
|
||||||
|
continue
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
if v[i] in positions:
|
if v[i] in positions:
|
||||||
v[i] = 5
|
v[i] = 5
|
||||||
@@ -207,6 +213,8 @@ def balanceTool():
|
|||||||
|
|
||||||
best = 100
|
best = 100
|
||||||
bestOption = None
|
bestOption = None
|
||||||
|
alternateOptions = []
|
||||||
|
alternateOptionsAboveThreshold = []
|
||||||
for option in permutations:
|
for option in permutations:
|
||||||
|
|
||||||
cur = 0
|
cur = 0
|
||||||
@@ -214,20 +222,63 @@ def balanceTool():
|
|||||||
for i in range(len(option)):
|
for i in range(len(option)):
|
||||||
cur += option[i].prio[i%5]
|
cur += option[i].prio[i%5]
|
||||||
|
|
||||||
|
if theoMin/cur > threshold:
|
||||||
|
alternateOptionsAboveThreshold += [option]
|
||||||
|
|
||||||
if cur < best:
|
if cur < best:
|
||||||
best = cur
|
best = cur
|
||||||
bestOption = option
|
bestOption = option
|
||||||
print(cur)
|
alternateOptions = []
|
||||||
|
alternateOptions += [option]
|
||||||
|
print("Option Found Quality: {}%".format(str(int(theoMin/cur*100))))
|
||||||
|
elif cur == best:
|
||||||
|
alternateOptions += [option]
|
||||||
|
|
||||||
|
alternateOptions += alternateOptionsAboveThreshold
|
||||||
retDict = { "left" : {}, "right" : {} }
|
retDict = { "left" : {}, "right" : {} }
|
||||||
bestOption = list(bestOption)
|
bestOption = list(bestOption)
|
||||||
if len(bestOption) < 10:
|
if len(bestOption) < 10:
|
||||||
for x in range(10-len(bestOption)):
|
for x in range(10-len(bestOption)):
|
||||||
bestOption += [Player("", [0,0,0,0,0])]
|
bestOption += [Player("", [0,0,0,0,0])]
|
||||||
|
for o in alternateOptions:
|
||||||
|
for x in range(10-len(o)):
|
||||||
|
o += [Player("", [0,0,0,0,0])]
|
||||||
|
|
||||||
|
# fix options with rating #
|
||||||
|
bestOptionWithRating = None
|
||||||
|
currDiff = 100000
|
||||||
|
for o in alternateOptions:
|
||||||
|
firstHalf = o[:2]
|
||||||
|
secondHalf = o[2:]
|
||||||
|
|
||||||
|
firstHalfPiL = [ db.getPlayerById(p.name) for p in firstHalf ]
|
||||||
|
secondHalfPiL = [ db.getPlayerById(p.name) for p in secondHalf ]
|
||||||
|
|
||||||
|
firstHalfVal = 0
|
||||||
|
secondHalfVal = 0
|
||||||
|
|
||||||
|
for pil in firstHalfPiL:
|
||||||
|
if not pil:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
firstHalfVal += pil.mu
|
||||||
|
|
||||||
|
for pil in secondHalfPiL:
|
||||||
|
if not pil:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
secondHalfVal += pil.mu
|
||||||
|
|
||||||
|
diff = abs(firstHalfVal - secondHalfVal)
|
||||||
|
if diff < currDiff:
|
||||||
|
currDiff = diff;
|
||||||
|
print("Option found rating mu-diff: {}".format(diff))
|
||||||
|
bestOptionWithRating = o
|
||||||
|
best =
|
||||||
|
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
retDict["left"].update( { positions[i] : bestOption[i].name })
|
retDict["left"].update( { positions[i] : bestOptionWithRating[i].name })
|
||||||
retDict["right"].update({ positions[i] : bestOption[i+5].name })
|
retDict["right"].update({ positions[i] : bestOptionWithRating[i+5].name })
|
||||||
|
|
||||||
renderContent = flask.render_template("balance_response_partial.html", d=retDict,
|
renderContent = flask.render_template("balance_response_partial.html", d=retDict,
|
||||||
requests=flask.request.json,
|
requests=flask.request.json,
|
||||||
@@ -304,7 +355,7 @@ def player():
|
|||||||
|
|
||||||
@app.route('/leaderboard')
|
@app.route('/leaderboard')
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@cache.cached(timeout=600, query_string=True)
|
@cache.cached(timeout=10, query_string=True)
|
||||||
def leaderboard():
|
def leaderboard():
|
||||||
'''Show main leaderboard page with range dependant on parameters'''
|
'''Show main leaderboard page with range dependant on parameters'''
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,10 @@ function balance(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prioBalanceCheckbox = document.getElementById("prio-balance")
|
||||||
|
if(prioBalanceCheckbox.checked){
|
||||||
|
dictAll["acceptable-solution-threshold"] = 0.7
|
||||||
|
}
|
||||||
jsonData = JSON.stringify(dictAll, null, 4);
|
jsonData = JSON.stringify(dictAll, null, 4);
|
||||||
|
|
||||||
/* transmitt */
|
/* transmitt */
|
||||||
@@ -266,5 +270,10 @@ setInterval(queryForPlayerData(), 3000)
|
|||||||
|
|
||||||
formContainer = document.getElementById("form-container")
|
formContainer = document.getElementById("form-container")
|
||||||
if(formContainer){
|
if(formContainer){
|
||||||
|
//formContainer.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetAll(){
|
||||||
|
formContainer = document.getElementById("form-container")
|
||||||
formContainer.reset()
|
formContainer.reset()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,20 @@
|
|||||||
aria-controls="hilfe">
|
aria-controls="hilfe">
|
||||||
Hilfe Anzeigen
|
Hilfe Anzeigen
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
class="mb-3 btn btn-secondary" onclick="resetAll()">
|
||||||
|
Reset all
|
||||||
|
</button></br>
|
||||||
|
|
||||||
|
<div class="form-check mt-3">
|
||||||
|
<input class="form-check-input" type="checkbox" value=""
|
||||||
|
id="prio-balance">
|
||||||
|
<label class="form-check-label" for="flexCheckChecked">
|
||||||
|
Prioritize balance over positional preferences
|
||||||
|
<p style="color: red;">(experimental)</p>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="hilfe" class="collapse mt-5 border-special">
|
<div id="hilfe" class="collapse mt-5 border-special">
|
||||||
<h4>Priorität</h4>
|
<h4>Priorität</h4>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
Reference in New Issue
Block a user