Esempio n. 1
0
    def get_all_desc(amount=None):
        if amount is None:
            docs = MongoArena._get_collection().find({}, {'score': 1}).sort('score', -1)
        else:
            docs = MongoArena._get_collection().find({}, {'score': 1}).sort('score', -1).limit(amount)

        return [(doc['_id'], doc['score']) for doc in docs]
Esempio n. 2
0
    def get_all():
        docs = MongoArena._get_collection().find(
                {},
                {'score': 1}
        ).sort('score', 1)

        return [(doc['_id'], doc['score']) for doc in docs]
Esempio n. 3
0
    def get_init_score():
        # 获得初始积分
        lowest_doc = MongoArena._get_collection().find({}, {'score':1}).sort('score', 1).limit(1)
        if lowest_doc.count() == 0:
            return ARENA_INITIAL_SCORE

        doc = lowest_doc[0]
        score = int(doc['score'])
        if score < ARENA_LOWEST_SCORE:
            score = ARENA_LOWEST_SCORE
        return score
Esempio n. 4
0
    def get_chars_by_score(low_score=None, high_score=None):
        conditions = []
        if low_score:
            conditions.append( {'score': {'$gte': low_score}} )
        if high_score:
            conditions.append( {'score': {'$lte': high_score}} )

        if len(conditions) == 1:
            conditions = conditions[0]
        elif len(conditions) == 2:
            conditions = {'$and': conditions}

        docs = MongoArena._get_collection().find(conditions, {'_id': 1})
        return [doc['_id'] for doc in docs]
Esempio n. 5
0
 def get_char_score(char_id):
     doc = MongoArena._get_collection().find_one(
             {'_id': char_id},
             {'score': 1}
     )
     return doc['score']
Esempio n. 6
0
 def get_top_ranks(amount=10):
     docs = MongoArena._get_collection().find({}, {'score': 1}).sort('score', -1).limit(amount)
     return [(doc['_id'], doc['score']) for doc in docs]
Esempio n. 7
0
 def get_char_rank(char_score):
     docs = MongoArena._get_collection().find({'score': {'$gt': char_score}}, {'_id': 1})
     rank = docs.count()
     return rank + 1