Skip to content

Instantly share code, notes, and snippets.

@yangxing-star
Created April 2, 2014 07:45
Show Gist options
  • Save yangxing-star/9929636 to your computer and use it in GitHub Desktop.
Save yangxing-star/9929636 to your computer and use it in GitHub Desktop.
计算城市大使
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