Fix critical bugs: touchEnabled undefined, MongoDB score sorting with score_value field
This commit is contained in:
15
app.py
15
app.py
@@ -105,7 +105,7 @@ db.users.create_index('username', unique=True)
|
||||
db.songs.create_index('id', unique=True)
|
||||
db.songs.create_index('song_type')
|
||||
db.scores.create_index('username')
|
||||
db.leaderboards.create_index([('song_id', 1), ('difficulty', 1), ('month', 1), ('score', -1)])
|
||||
db.leaderboards.create_index([('song_id', 1), ('difficulty', 1), ('month', 1), ('score_value', -1)])
|
||||
db.leaderboards.create_index([('song_id', 1), ('difficulty', 1), ('username', 1), ('month', 1)], unique=True)
|
||||
db.leaderboards.create_index('month')
|
||||
|
||||
@@ -795,12 +795,13 @@ def route_api_leaderboard_submit():
|
||||
|
||||
if existing:
|
||||
# Update only if new score is higher
|
||||
existing_score = int(existing.get('score', {}).get('score', 0))
|
||||
existing_score = existing.get('score_value', 0)
|
||||
if score_value > existing_score:
|
||||
db.leaderboards.update_one(
|
||||
{'_id': existing['_id']},
|
||||
{'$set': {
|
||||
'score': score_data,
|
||||
'score_value': score_value,
|
||||
'display_name': user['display_name'],
|
||||
'submitted_at': time.time()
|
||||
}}
|
||||
@@ -822,10 +823,10 @@ def route_api_leaderboard_submit():
|
||||
'song_id': song_id,
|
||||
'difficulty': difficulty,
|
||||
'month': current_month
|
||||
}).sort('score', -1).limit(50))
|
||||
}).sort('score_value', -1).limit(50))
|
||||
|
||||
if len(leaderboard) >= 50:
|
||||
last_score = int(leaderboard[49].get('score', {}).get('score', 0))
|
||||
last_score = leaderboard[49].get('score_value', 0)
|
||||
if score_value <= last_score:
|
||||
return jsonify({'status': 'ok', 'message': 'score_too_low'})
|
||||
|
||||
@@ -836,6 +837,7 @@ def route_api_leaderboard_submit():
|
||||
'username': username,
|
||||
'display_name': user['display_name'],
|
||||
'score': score_data,
|
||||
'score_value': score_value,
|
||||
'submitted_at': time.time(),
|
||||
'month': current_month
|
||||
})
|
||||
@@ -847,7 +849,7 @@ def route_api_leaderboard_submit():
|
||||
'song_id': song_id,
|
||||
'difficulty': difficulty,
|
||||
'month': current_month
|
||||
}).sort('score', -1))
|
||||
}).sort('score_value', -1))
|
||||
|
||||
# Delete entries beyond 50
|
||||
if len(all_entries) > 50:
|
||||
@@ -888,8 +890,9 @@ def route_api_leaderboard_get():
|
||||
'username': True,
|
||||
'display_name': True,
|
||||
'score': True,
|
||||
'score_value': True,
|
||||
'submitted_at': True
|
||||
}).sort('score', -1).limit(50))
|
||||
}).sort('score_value', -1).limit(50))
|
||||
|
||||
# Add rank to each entry
|
||||
for i, entry in enumerate(leaderboard):
|
||||
|
||||
Reference in New Issue
Block a user