implement auto filter for min games played

This commit is contained in:
Yannik Schmidt
2020-09-28 05:04:50 +02:00
parent a91fd79859
commit b435226413
3 changed files with 13 additions and 4 deletions

View File

@@ -29,7 +29,7 @@ class DatabaseConnection:
'''Get the total number of players in the database''' '''Get the total number of players in the database'''
cursor = self.connPlayers.cursor() cursor = self.connPlayers.cursor()
cursor.execute("SELECT Count(*) FROM players") cursor.execute("SELECT Count(*) FROM players where games >= 10")
count = cursor.fetchone()[0] count = cursor.fetchone()[0]
return count return count
@@ -77,7 +77,8 @@ class DatabaseConnection:
cursor = self.connPlayers.cursor() cursor = self.connPlayers.cursor()
limit = end - start limit = end - start
sqlQuery = "Select * FROM players ORDER BY (mu - 2*sigma) DESC LIMIT ? OFFSET ?" sqlQuery = '''Select * FROM players where games >= 10
ORDER BY (mu - 2*sigma) DESC LIMIT ? OFFSET ?'''
cursor.execute(sqlQuery, (limit, start)) cursor.execute(sqlQuery, (limit, start))
rows = cursor.fetchall() rows = cursor.fetchall()
playerList = [] playerList = []
@@ -110,7 +111,9 @@ class DatabaseConnection:
can't and shouldn't be used to identify a player''' can't and shouldn't be used to identify a player'''
cursor = self.connPlayers.cursor() cursor = self.connPlayers.cursor()
cursor.execute("SELECT COUNT(*) from players where (mu-2*sigma) > (?-2*?);", if(player.games < 10):
return -1
cursor.execute("SELECT COUNT(*) from players where games >= 10 and (mu-2*sigma) > (?-2*?);",
(player.mu, player.sigma)) (player.mu, player.sigma))
rank = cursor.fetchone()[0] rank = cursor.fetchone()[0]
return rank return rank

View File

@@ -102,6 +102,8 @@ def leaderboard():
if playerName: if playerName:
playerInLeaderboard = db.findPlayerByName(playerName) playerInLeaderboard = db.findPlayerByName(playerName)
if(playerInLeaderboard.games < 10):
return flask.redirect("/player?id={}".format(playerInLeaderboard.playerId))
rank = playerInLeaderboard.rank rank = playerInLeaderboard.rank
if not playerInLeaderboard: if not playerInLeaderboard:
cannotFindPlayer = flask.Markup("<div class=noPlayerFound>No player of that name</div>") cannotFindPlayer = flask.Markup("<div class=noPlayerFound>No player of that name</div>")

View File

@@ -31,7 +31,11 @@
</h1> </h1>
<h3> <h3>
Rating: <i>{{ player.rating }}</i> <br> Rating: <i>{{ player.rating }}</i> <br>
Rank: {{ player.rank }} {% if player.rank == 0 %}
<i><small>missing {{ 10 - player.games }} placement games</small></i>
{% else %}
Rank: {{ player.rank }}
{%endif%}
</h3> </h3>
</div> </div>
<div class="plot-container"> <div class="plot-container">