Skip to content

Instantly share code, notes, and snippets.

@yangxing-star
Created October 8, 2014 07:48
Show Gist options
  • Select an option

  • Save yangxing-star/5edf25743ea83f09ec14 to your computer and use it in GitHub Desktop.

Select an option

Save yangxing-star/5edf25743ea83f09ec14 to your computer and use it in GitHub Desktop.
User.all.each do |u|
date = [ '2014-09-01','2014-09-02','2014-09-03','2014-09-04','2014-09-05',
'2014-09-06','2014-09-07','2014-09-08','2014-09-09','2014-09-10',
'2014-09-11','2014-09-12','2014-09-13','2014-09-14','2014-09-15',
'2014-09-16','2014-09-17','2014-09-18','2014-09-19','2014-09-20',
'2014-09-21','2014-09-22','2014-09-23','2014-09-24','2014-09-25',
'2014-09-26','2014-09-27','2014-09-28','2014-09-29','2014-09-30',
'2014-10-01','2014-10-02','2014-10-03','2014-10-04','2014-10-05',
'2014-10-06','2014-10-07','2014-10-08' ]
date.each do |d|
a = AchievementCount.find_or_initialize_by(user_id: u.id, created_date: d)
maintain_count = AchievementRecord.where(user_id: u.id, category: 2).between_date(d, d).count
m_count1 = AchievementRecord.where(user_id: u.id, category: 2, maintain_type: 1, is_next_login: true).between_date(d, d).count
m_count2 = AchievementRecord.where(user_id: u.id, category: 2, maintain_type: 3, is_next_login: true).between_date(d, d).count
newly_count = AchievementRecord.where(user_id: u.id, category: 1).between_date(d, d).count
newly_valid_count = AchievementRecord.where(user_id: u.id, category: 1, is_next_login: true).between_date(d, d).count
info_count = AchievementRecord.between_date(d, d).where(category: 3, user_id: u.id).count + m_count2 + ( newly_count - newly_valid_count )
a.maintain_count = maintain_count
a.maintain_valid_count = m_count1 + m_count2
a.info_count = info_count
a.newly_count = newly_count
a.newly_valid_count = newly_valid_count
a.save
end
end
AchievementRecord.where('created_at <= ? and created_at >= ?', '2014-10-09 23:59:59', '2014-09-01 00:00:00').where(maintain_type: 3).update_all(category: 2)
AchievementRecord.where(is_next_login: false, category: 3, status: 1).each do |a|
c = Customer.find_by(mobile: a.mobile)
if c && c.is_newly_valid?
a.update(category: :newly)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment