Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

ok

  • Loading branch information...
commit aaaf87e951f033341cda36194cd14aeab2c35512 1 parent 28da1c7
yupbank authored March 02, 2012

Showing 1 changed file with 13 additions and 11 deletions. Show diff stats Hide diff stats

  1. 24  rest/utils.py
24  rest/utils.py
@@ -40,25 +40,27 @@ def get_lat_lng_range(lat0, lng0, distance=1.0):
40 40
 
41 41
 
42 42
 def get_id_rank_list(limit=10,offset=0):
  43
+    rank_dict = user_rank_dict()
  44
+    rank = [ (i,j) for i,j in rank_dict.iteritems()]
  45
+    rank.sort(key=lambda x:x[1])
  46
+    return rank[offset:offset+limit]
  47
+
  48
+
  49
+def user_rank_dict():
43 50
     check_count = []
44 51
     rank = []
45 52
     for u in User.objects.all():
46 53
         check_count.append([u.id, u.checkin_set.count()])
47 54
     if check_count:
48  
-        check_count.sort(key=lambda x:x[1],reverse=True)
49 55
         _rank = set([i[1] for i in check_count ])
50 56
         _rank = [i for i in _rank]
51  
-        _rank = [(i, len(_rank)-1-_rank.index(i)) for i in _rank]
52  
-        rank = {}
53  
-        for i,j in _rank:
54  
-            rank.update({i:j+1})
55  
-        rank = [ [i,rank[j]] for i, j in check_count]
56  
-        rank.sort(key=lambda x:x[1],reverse=True)
57  
-    return rank[offset:offset+limit]
58  
-
  57
+        _rank.sort()
  58
+        _rank = [(i, _rank.index(j)+1) for i,j in check_count]
  59
+        rank = dict(_rank)
  60
+    return dict(rank)
59 61
 
60 62
 
61 63
 def get_rank_by_id(id):
62  
-    rank_list = get_id_rank_list()
63  
-    return dict(rank_list).get(id)
  64
+    rank_dict = user_rank_dict()
  65
+    return rank_dict.get(id)
64 66
 

0 notes on commit aaaf87e

Please sign in to comment.
Something went wrong with that request. Please try again.