Skip to content
Permalink
Browse files

some fixes

  • Loading branch information...
YogurtTheHorse committed Sep 18, 2016
1 parent 4449aef commit 2560465bde3908213af5a75fd6265d7cffd34932
Showing with 13 additions and 6 deletions.
  1. +10 −3 databasemanager/leaderboard_model.py
  2. +3 −3 migrate.py
@@ -1,3 +1,7 @@
import pymongo

from collections import Counter

from mongothon import Schema
from mongothon import create_model
from mongothon.validators import one_of
@@ -27,6 +31,8 @@ def get_leaderboard(cls, leaderboard, count=10):
if leaderboard == 'death':
res = list(cls.find({"leaderboard": 'rooms'}))

counter = Counter()

for r in res:
if 'death_reason' in r and str(r['death_reason']) != 'None':
counter.update([r['death_reason']])
@@ -36,8 +42,9 @@ def get_leaderboard(cls, leaderboard, count=10):
def sort_by_score(doc):
return doc['score']

res = list(cls.find({"leaderboard": leaderboard}))
res.sort(key=sort_by_score, reverse=True)
cursor = cls.find({"leaderboard": leaderboard})
sorted = cursor.sort('score', pymongo.DESCENDING)
res = list(sorted.limit(count))

return res[:count]
return list(cls.find({"leaderboard": leaderboard}))[:count]
@@ -60,4 +67,4 @@ def add_to_leaderboard(cls, user, score, leaderboard_name='rooms'):

cls.insert(doc)

return Scores
return Scores
@@ -169,9 +169,9 @@ def sort_by_score(doc):
return res[:count]

import databasemanager
from pymongo import Connection
c = Connection()
c.drop_database('rogbot')
#from pymongo import Connection
#c = Connection()
#c.drop_database('rogbot')

print('Moving variables..')
for variable in db.table(VAR_TABLE).all():

0 comments on commit 2560465

Please sign in to comment.
You can’t perform that action at this time.