Skip to content

Instantly share code, notes, and snippets.

@yangxing-star
Created November 11, 2014 02:01
Show Gist options
  • Save yangxing-star/0b20b320e071e8e5aab2 to your computer and use it in GitHub Desktop.
Save yangxing-star/0b20b320e071e8e5aab2 to your computer and use it in GitHub Desktop.
def total
data = []
a = ["2014-10-17", "2014-10-18", "2014-10-19", "2014-10-20", "2014-10-21", "2014-10-22", "2014-10-23", "2014-10-24", "2014-10-25", "2014-10-26", "2014-10-27", "2014-10-28", "2014-10-29", "2014-10-30", "2014-10-31", "2014-11-01", "2014-11-02", "2014-11-03", "2014-11-04", "2014-11-05", "2014-11-06", "2014-11-07", "2014-11-08", "2014-11-09", "2014-11-10"]
a.each do |d|
date = Date.parse(d)
begin_at = date.beginning_of_day
end_at = date.end_of_day
newly_customers_count = Customer.newly_added(begin_at, end_at).count
newly_merchants_count = Customer.newly_added(begin_at, end_at).where('career = ?', 1).count
customers_count = Customer.where('import_at <= ?', (date + 1.day).beginning_of_day).count
merchants_count = Customer.where('import_at <= ? and career = ?', (date + 1.day).beginning_of_day, 1).count
data << { '日期' => (date + 1.day).to_s, newly_customers_count: newly_customers_count,
newly_merchants_count: newly_merchants_count, customers_count: customers_count,
merchants_count: merchants_count }
end
puts '-'*80
p data
puts '-'*80
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment