Guest User

Untitled

a guest
Apr 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. def get_top10(app_id):
  2.  
  3. ts = get_all(app_id)
  4. cities_str = ""
  5. cities = {}
  6. for t in ts:
  7. city = t.client_city.lower()
  8. if city != "":
  9. if "@%s@"%city not in cities_str:
  10. cities_str += "@%s@"%city
  11. cities[city] = 1
  12. else:
  13. cities[city] += 1
  14.  
  15. from operator import itemgetter
  16. items = cities.items()
  17. items.sort(key = itemgetter(1), reverse=True)
  18. return items[:10]
  19.  
  20.  
  21.  
  22. def get_all(app_id):
  23.  
  24. last = None
  25. all_ts = []
  26. while True:
  27.  
  28. ts = Transaction.all().filter("application_id =",app_id).order("__key__")
  29. if last is not None:
  30. ts = ts.filter("__key__ >",last.key())
  31.  
  32. ts = ts.fetch(400)
  33. last = ts[-1]
  34. all_ts += ts
  35.  
  36. if len(ts) != 400:
  37. print "FINISH"
  38. return all_ts
Add Comment
Please, Sign In to add comment