mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 15:11:35 +01:00
update
This commit is contained in:
32
api.py
32
api.py
@@ -11,17 +11,18 @@ import datetime as dt
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
REGION = "euw1"
|
REGION = "euw1"
|
||||||
|
DEFAULT_RATING = 1200
|
||||||
|
|
||||||
def tierToNumber(tier):
|
def tierToNumber(tier):
|
||||||
ratingmap = { 'CHALLENGER' : 3500,
|
ratingmap = { 'CHALLENGER' : 4500,
|
||||||
'GRANDMASTER': 3000,
|
'GRANDMASTER': 4000,
|
||||||
'MASTER' : 2500,
|
'MASTER' : 3500,
|
||||||
'DIAMOND' : 2000,
|
'DIAMOND' : 3000,
|
||||||
'PLATINUM' : 1500,
|
'PLATINUM' : 2500,
|
||||||
'GOLD' : 500,
|
'GOLD' : 1500,
|
||||||
'SILVER' : 0,
|
'SILVER' : 1000,
|
||||||
'BRONZE' : -500,
|
'BRONZE' : 500,
|
||||||
'IRON' : -1000 }
|
'IRON' : 0 }
|
||||||
return ratingmap[tier]
|
return ratingmap[tier]
|
||||||
|
|
||||||
def divisionToNumber(division):
|
def divisionToNumber(division):
|
||||||
@@ -41,7 +42,7 @@ def checkPlayerKnown(playerName):
|
|||||||
try:
|
try:
|
||||||
playerName, rating, lastUpdated = cursor.fetchone()
|
playerName, rating, lastUpdated = cursor.fetchone()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
print("sqlite cache player not found")
|
print("sqlite cache '{}' not found".format(playerName))
|
||||||
return None
|
return None
|
||||||
conn.close()
|
conn.close()
|
||||||
return (playerName, rating, lastUpdated)
|
return (playerName, rating, lastUpdated)
|
||||||
@@ -55,13 +56,14 @@ def addToDB(playerName, rating):
|
|||||||
rating,
|
rating,
|
||||||
dt.datetime.now().timestamp()))
|
dt.datetime.now().timestamp()))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
print("Added {}".format(playerName))
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def getPlayerRatingFromApi(playerName, WATCHER):
|
def getPlayerRatingFromApi(playerName, WATCHER):
|
||||||
|
|
||||||
if not playerName:
|
if not playerName:
|
||||||
return 0
|
return DEFAULT_RATING
|
||||||
|
|
||||||
tupel = checkPlayerKnown(playerName)
|
tupel = checkPlayerKnown(playerName)
|
||||||
if tupel:
|
if tupel:
|
||||||
@@ -74,7 +76,7 @@ def getPlayerRatingFromApi(playerName, WATCHER):
|
|||||||
# not found #
|
# not found #
|
||||||
if e.response.status_code == 404:
|
if e.response.status_code == 404:
|
||||||
addToDB(playerName, 0)
|
addToDB(playerName, 0)
|
||||||
return 0
|
return DEFAULT_RATING
|
||||||
# rate limit
|
# rate limit
|
||||||
elif e.response.status_code == 429:
|
elif e.response.status_code == 429:
|
||||||
print("Ratelimit reached")
|
print("Ratelimit reached")
|
||||||
@@ -84,9 +86,9 @@ def getPlayerRatingFromApi(playerName, WATCHER):
|
|||||||
raise e
|
raise e
|
||||||
if not pTmp:
|
if not pTmp:
|
||||||
addToDB(playerName, 0)
|
addToDB(playerName, 0)
|
||||||
return 0
|
return DEFAULT_RATING
|
||||||
|
|
||||||
computed = 0
|
computed = DEFAULT_RATING
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pInfo = WATCHER.league.by_summoner(REGION, pTmp["id"])
|
pInfo = WATCHER.league.by_summoner(REGION, pTmp["id"])
|
||||||
@@ -104,6 +106,6 @@ def getPlayerRatingFromApi(playerName, WATCHER):
|
|||||||
computed = tierToNumber(queue["tier"]) + divisionToNumber(queue["rank"]) + \
|
computed = tierToNumber(queue["tier"]) + divisionToNumber(queue["rank"]) + \
|
||||||
int(queue["leaguePoints"])
|
int(queue["leaguePoints"])
|
||||||
print(computed)
|
print(computed)
|
||||||
addToDB(playerName, computed)
|
|
||||||
|
|
||||||
|
addToDB(playerName, computed)
|
||||||
return computed
|
return computed
|
||||||
|
|||||||
71
server.py
71
server.py
@@ -12,6 +12,7 @@ import random
|
|||||||
import secrets
|
import secrets
|
||||||
import riotwatcher
|
import riotwatcher
|
||||||
import time
|
import time
|
||||||
|
import statistics
|
||||||
|
|
||||||
from database import DatabaseConnection
|
from database import DatabaseConnection
|
||||||
import api
|
import api
|
||||||
@@ -202,7 +203,7 @@ def balanceTool():
|
|||||||
if flask.request.method == 'POST':
|
if flask.request.method == 'POST':
|
||||||
|
|
||||||
players = []
|
players = []
|
||||||
threshold = 2
|
threshold = 0.7
|
||||||
for k,v in flask.request.json.items():
|
for k,v in flask.request.json.items():
|
||||||
if k == "acceptable-solution-threshold":
|
if k == "acceptable-solution-threshold":
|
||||||
threshold = v
|
threshold = v
|
||||||
@@ -234,13 +235,14 @@ def balanceTool():
|
|||||||
if theoMin/cur > threshold:
|
if theoMin/cur > threshold:
|
||||||
alternateOptionsAboveThreshold.append(list(option))
|
alternateOptionsAboveThreshold.append(list(option))
|
||||||
|
|
||||||
|
qualityCur = int(theoMin/cur*100)
|
||||||
if cur < best:
|
if cur < best:
|
||||||
best = cur
|
best = cur
|
||||||
bestOption = list(option)
|
bestOption = list(option)
|
||||||
alternateOptions = []
|
alternateOptions = []
|
||||||
alternateOptions.append(list(option))
|
alternateOptions.append(list(option))
|
||||||
print("Option Found Quality: {}%".format(str(int(theoMin/cur*100))))
|
print("Option Found Quality: {}%".format(str(qualityCur)))
|
||||||
elif cur == best:
|
elif cur == best or qualityCur > threshold*100:
|
||||||
alternateOptions.append(list(option))
|
alternateOptions.append(list(option))
|
||||||
|
|
||||||
alternateOptions += alternateOptionsAboveThreshold
|
alternateOptions += alternateOptionsAboveThreshold
|
||||||
@@ -255,28 +257,67 @@ def balanceTool():
|
|||||||
|
|
||||||
# fix options with rating #
|
# fix options with rating #
|
||||||
bestOptionWithRating = None
|
bestOptionWithRating = None
|
||||||
currDiff = 100000
|
bestOptionRatings = None
|
||||||
|
|
||||||
|
# alternate options rundown positional diff #
|
||||||
|
posCurrDiff = 100000
|
||||||
for o in alternateOptions:
|
for o in alternateOptions:
|
||||||
firstHalf = o[:5]
|
firstHalf = o[:5]
|
||||||
secondHalf = o[5:]
|
secondHalf = o[5:]
|
||||||
|
|
||||||
firstHalfVal = 0
|
firstHalfVal = [0, 0, 0, 0, 0]
|
||||||
secondHalfVal = 0
|
secondHalfVal = [0, 0, 0, 0, 0]
|
||||||
|
|
||||||
|
countFirstHalf = 0
|
||||||
for pil in firstHalf:
|
for pil in firstHalf:
|
||||||
if pil:
|
if pil:
|
||||||
firstHalfVal += api.getPlayerRatingFromApi(pil.name, WATCHER)
|
firstHalfVal[countFirstHalf] = api.getPlayerRatingFromApi(pil.name, WATCHER)
|
||||||
|
#print(pil.name, firstHalfVal[countFirstHalf])
|
||||||
|
countFirstHalf += 1
|
||||||
|
|
||||||
|
countSecondHalf = 0
|
||||||
for pil in secondHalf:
|
for pil in secondHalf:
|
||||||
if pil:
|
if pil:
|
||||||
secondHalfVal += api.getPlayerRatingFromApi(pil.name, WATCHER)
|
secondHalfVal[countSecondHalf] = api.getPlayerRatingFromApi(pil.name, WATCHER)
|
||||||
|
#print(pil.name, secondHalfVal[countSecondHalf])
|
||||||
|
countSecondHalf += 1
|
||||||
|
|
||||||
diff = abs(firstHalfVal - secondHalfVal)
|
posDiff = abs(statistics.median(firstHalfVal) - statistics.median(secondHalfVal))
|
||||||
if diff < currDiff:
|
|
||||||
currDiff = diff;
|
# check if posdiff is better #
|
||||||
print("Option found rating mu-diff: {}".format(diff))
|
if posDiff < posCurrDiff:
|
||||||
bestOptionWithRating = o
|
bestOptionWithRating = o
|
||||||
|
bestOptionRatings = firstHalfVal + secondHalfVal
|
||||||
|
qualityRatings = -1
|
||||||
|
|
||||||
|
# find the best permutation of this solution #
|
||||||
|
for i in range(0,5):
|
||||||
|
teamDiff = abs(sum(firstHalfVal) - sum(secondHalfVal))
|
||||||
|
|
||||||
|
# first flip
|
||||||
|
tmp = firstHalfVal[i]
|
||||||
|
firstHalfVal[i] = secondHalfVal[i]
|
||||||
|
secondHalfVal[i] = tmp
|
||||||
|
teamDiffNew = abs(sum(firstHalfVal) - sum(secondHalfVal))
|
||||||
|
|
||||||
|
# if new is not better #
|
||||||
|
if not (teamDiffNew < teamDiff):
|
||||||
|
# flip it back #
|
||||||
|
tmp = firstHalfVal[i]
|
||||||
|
firstHalfVal[i] = secondHalfVal[i]
|
||||||
|
secondHalfVal[i] = tmp
|
||||||
|
# else flip the names too #
|
||||||
|
else:
|
||||||
|
tmp = firstHalf[i]
|
||||||
|
firstHalf[i] = secondHalf[i]
|
||||||
|
secondHalf[i] = tmp
|
||||||
|
# and reset the option #
|
||||||
|
bestOptionWithRating = firstHalf + secondHalf
|
||||||
|
bestOptionRatings = firstHalfVal + secondHalfVal
|
||||||
|
qualityRatings = min(sum(firstHalfVal)/sum(secondHalfVal),
|
||||||
|
sum(secondHalfVal)/sum(firstHalfVal))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
retDict["left"].update( { positions[i] : bestOptionWithRating[i].name })
|
retDict["left"].update( { positions[i] : bestOptionWithRating[i].name })
|
||||||
@@ -285,7 +326,9 @@ def balanceTool():
|
|||||||
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,
|
||||||
positions=positions,
|
positions=positions,
|
||||||
quality=int(theoMin/best*100))
|
ratings=bestOptionRatings,
|
||||||
|
qualityPositions=int(theoMin/best*100),
|
||||||
|
qualityRatings=int(qualityRatings*100))
|
||||||
return flask.Response(
|
return flask.Response(
|
||||||
json.dumps({ "content": renderContent }), 200, mimetype='application/json')
|
json.dumps({ "content": renderContent }), 200, mimetype='application/json')
|
||||||
else:
|
else:
|
||||||
@@ -314,7 +357,7 @@ def playerApi():
|
|||||||
@app.route("/player-api-cache")
|
@app.route("/player-api-cache")
|
||||||
def playerApiCache():
|
def playerApiCache():
|
||||||
result = api.checkPlayerKnown(flask.request.args.get("id"))
|
result = api.checkPlayerKnown(flask.request.args.get("id"))
|
||||||
if result:
|
if result and result[1] != 0:
|
||||||
return ("OK", 200)
|
return ("OK", 200)
|
||||||
else:
|
else:
|
||||||
return ("Nope", 404)
|
return ("Nope", 404)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var checkPlayerFunc = function checkPlayer() {
|
|||||||
if(r.status == 200){
|
if(r.status == 200){
|
||||||
this.style.background = "#74bb74"
|
this.style.background = "#74bb74"
|
||||||
}else{
|
}else{
|
||||||
//this.style.background = "#d25252"
|
this.style.background = "#d25252"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -151,6 +151,8 @@ function balance(){
|
|||||||
|
|
||||||
prioBalanceCheckbox = document.getElementById("prio-balance")
|
prioBalanceCheckbox = document.getElementById("prio-balance")
|
||||||
if(prioBalanceCheckbox.checked){
|
if(prioBalanceCheckbox.checked){
|
||||||
|
dictAll["acceptable-solution-threshold"] = 0.5
|
||||||
|
}else{
|
||||||
dictAll["acceptable-solution-threshold"] = 0.7
|
dictAll["acceptable-solution-threshold"] = 0.7
|
||||||
}
|
}
|
||||||
jsonData = JSON.stringify(dictAll, null, 4);
|
jsonData = JSON.stringify(dictAll, null, 4);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<div class="my-3">
|
<div class="my-3">
|
||||||
<h3> Suggestion: (Quality: {{ quality }}%)</h3>
|
<h3> Suggestion </h3>
|
||||||
|
<p>Postion Wishes: {{ qualityPositions }}% fullfilled /
|
||||||
|
Teambalance: {{ qualityRatings }}% </p>
|
||||||
</div>
|
</div>
|
||||||
{% for x in range(5) %}
|
{% for x in range(5) %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -10,11 +12,26 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-sm"
|
<div class="col-sm"
|
||||||
{% if requests[leftP][x] | int >= 4 %}style="background: red;"{% endif %}>
|
{% if requests[leftP][x] | int >= 4 %}style="background: red;"{% endif %}>
|
||||||
{{ leftP }}
|
{{ leftP }} ({{ ratings[x] }})
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm"
|
<div class="col-sm"
|
||||||
{% if requests[rightP][x] | int >= 4 %}style="background: red;"{% endif %}>
|
{% if requests[rightP][x] | int >= 4 %}style="background: red;"{% endif %}>
|
||||||
{{ rightP }}
|
{{ rightP }} ({{ ratings[x+5] }})
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
<div class="mt-3">
|
||||||
|
<h3>For copying into Lobby:</h3>
|
||||||
|
<div class="mt-2">
|
||||||
|
<div class="row">
|
||||||
|
<textarea style="padding-left: 10px !important; padding-top: 10px !important" rows="16" cols= 100>
|
||||||
|
Left Side Team
|
||||||
|
{% for x in range(5) %}
|
||||||
|
{% set leftP = d["left"][positions[x]] %}{{ leftP }} left team {{ positions[x] }}{% endfor %}
|
||||||
|
|
||||||
|
Right Side Team
|
||||||
|
{% for x in range(5) %}
|
||||||
|
{% set rightP = d["right"][positions[x]] %}{{ rightP }} right team {{ positions[x] }}{% endfor %}
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -43,12 +43,12 @@
|
|||||||
Reset all
|
Reset all
|
||||||
</button></br>
|
</button></br>
|
||||||
|
|
||||||
<div class="form-check mt-3">
|
<div style="display: none;" class="form-check mt-3">
|
||||||
<input class="form-check-input" type="checkbox" value=""
|
<input class="form-check-input" type="checkbox" value=""
|
||||||
id="prio-balance">
|
id="prio-balance">
|
||||||
<label class="form-check-label" for="flexCheckChecked">
|
<label class="form-check-label" for="flexCheckChecked">
|
||||||
Prioritize balance over positional preferences
|
Prioritize balance over positional preferences
|
||||||
<p style="color: red;">(experimental)</p>
|
<p style="color: red;">(experimental, slow af)</p>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<!-- player name field -->
|
<!-- player name field -->
|
||||||
<form action="/role-submission?id={{ ident }}" method="POST">
|
<form action="/role-submission?id={{ ident }}" method="POST">
|
||||||
|
<p style="color: red; font-weight: bold"> PLEASE USE YOUR _CORRECTLY SPELLED_ LoL-NAME!!</p>
|
||||||
<input class="form-control pname m-3" type="text" placeholder="Player"
|
<input class="form-control pname m-3" type="text" placeholder="Player"
|
||||||
name="playername" id="playername">
|
name="playername" id="playername">
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user