Module: Rawbotz::SalesData
- Defined in:
- lib/rawbotz/sales_data.rb
Class Method Summary collapse
Class Method Details
.sales_since(day, products) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/rawbotz/sales_data.rb', line 3 def self.sales_since day, products db = RawgentoDB::Query monthly_sales = products.map{|p| [p.product_id, db.sales_monthly_between(p.product_id, Date.today, day)]}.to_h # This is NOT the average! monthly_sales.each{|k,v| monthly_sales[k] = v.inject(0){|a,s| a + s[1].to_i}/v.length rescue 0} end |