Created
April 2, 2014 07:45
-
-
Save yangxing-star/9929636 to your computer and use it in GitHub Desktop.
计算城市大使
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = ["哈尔滨","广州", "拉萨", "天津", "成都", "郑州", "沈阳", "宁波"] | |
b = [] | |
cities = City.where(:name_chn.in => a).each do |c| | |
hash = {} | |
user = User.within_circle('location.loc' => c.to_a).desc(:referring_count).first | |
if user.nil? | |
hash[:error] = nil | |
b << hash | |
return | |
end | |
count = 0 | |
user.referring.each do |r| | |
if r.created_at >= '2013-11-30 00:00:00' | |
count += 1 | |
end | |
end | |
hash[:city] = c.name_chn | |
hash[:nickname] = user.nickname | |
hash[:count] = count | |
b << hash | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment