Non-updating rank table fix and tiebreaker logic (#1)

This commit is contained in:
FinnHornhoover 2023-12-25 23:37:22 +03:00 committed by GitHub
parent 9deba1956f
commit b70816fa64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,22 +32,32 @@ except Exception as ex:
sys.exit() sys.exit()
#db.set_trace_callback(print) #db.set_trace_callback(print)
def fetch_ranks(epid, date, num): def fetch_ranks(epid, date, num):
sql = """ sql = """
SELECT * FROM ( SELECT
SELECT RaceResults.PlayerID, PBRaceResults.PlayerID,
Players.FirstName, Players.FirstName,
Players.LastName, Players.LastName,
RaceResults.Score PBRaceResults.Score
FROM (
SELECT
ROW_NUMBER() OVER (
PARTITION BY RaceResults.PlayerID
ORDER BY
RaceResults.Score DESC,
RaceResults.RingCount DESC,
RaceResults.Time ASC
) AS PersonalOrder,
RaceResults.*
FROM RaceResults FROM RaceResults
INNER JOIN Players ON RaceResults.PlayerID=Players.PlayerID WHERE EPID=? AND DATETIME(Timestamp, 'unixepoch') > DATETIME('now', ?)
WHERE EPID=? AND ) AS PBRaceResults
DATETIME(Timestamp,'unixepoch') > (SELECT DATETIME('now', ?)) INNER JOIN Players ON PBRaceResults.PlayerID=Players.PlayerID AND PBRaceResults.PersonalOrder=1
ORDER BY Score DESC ORDER BY
) PBRaceResults.Score DESC,
GROUP BY PlayerID PBRaceResults.RingCount DESC,
ORDER BY Score DESC PBRaceResults.Time ASC
""" """
if num > -1: if num > -1:
@ -63,15 +73,16 @@ def fetch_ranks(epid, date, num):
def fetch_my_ranks(pcuid, epid, date): def fetch_my_ranks(pcuid, epid, date):
sql = """ sql = """
SELECT RaceResults.PlayerID, SELECT
Players.FirstName, RaceResults.PlayerID,
Players.LastName, Players.FirstName,
RaceResults.Score Players.LastName,
RaceResults.Score
FROM RaceResults FROM RaceResults
INNER JOIN Players ON RaceResults.PlayerID=Players.PlayerID INNER JOIN Players ON RaceResults.PlayerID=Players.PlayerID
WHERE RaceResults.PlayerID=? AND EPID=? AND WHERE RaceResults.PlayerID=? AND EPID=? AND DATETIME(Timestamp, 'unixepoch') > DATETIME('now', ?)
DATETIME(Timestamp,'unixepoch') > (SELECT DATETIME('now', ?)) ORDER BY RaceResults.Score DESC
ORDER BY Score DESC LIMIT 1; LIMIT 1;
""" """
args = (pcuid, epid, date) args = (pcuid, epid, date)
@ -105,7 +116,7 @@ def get_score_entries(data, name):
def rankings(): def rankings():
#print("PCUID:", request.form['PCUID']) #print("PCUID:", request.form['PCUID'])
#print("EP_ID:", request.form['EP_ID']) #print("EP_ID:", request.form['EP_ID'])
# Input Validation # Input Validation
try: try:
pcuid = int(request.form['PCUID']) pcuid = int(request.form['PCUID'])