lk | adds report for bikes fixed per week and some notes

This commit is contained in:
Louis Knapp
2016-07-17 11:56:49 -05:00
parent 87577ab14e
commit daa4b912e6
5 changed files with 42 additions and 3 deletions
+3
View File
@@ -5,4 +5,7 @@ class ReportsController < ApplicationController
@yearly_data = Report.yearly_data
end
def bikes_fixed_per_week
@weekly_data = Report.bikes_fixed_per_week
end
end
+7 -1
View File
@@ -2,6 +2,13 @@ class Report
@@years = Bike.all.each.map{|bike| bike.date_sold.year if bike.date_sold}
def self.bikes_fixed_per_week
beginning_of_year = Time.now.beginning_of_year
bikes = Bike.where("entry_date > ?", beginning_of_year)
weekly_data = bikes.group_by{|b| DateTime.strptime(b.entry_date, "%m/%d/%y").beginning_of_week}
weekly_data.to_a.sort!{|a, b| a.first <=> b.first}.to_h
end
def self.bikes_sold_per_year
counts = Hash.new(0)
@@years.each { |year| counts[year] += 1 }
@@ -13,7 +20,6 @@ class Report
years_prices = @@years.each_with_index.map{|year, index| {prices[index].to_s.to_sym => year}}
merged_years_prices = years_prices.reduce({}, :merge)
years_prices_grouped = merged_years_prices.group_by{|k, v| v}
average_price_array = years_prices_grouped.each.map{ |k, year_values|
year_prices = year_values.each.map{|pair| pair[0]}
float_prices = year_prices.map{|price| price.to_s.to_f}
@@ -0,0 +1,15 @@
.container
%h1 Bikes Fixed Per Week This Year
%p Because of some discrepancies in the way date data has been stored, this data may be off. Consider this feature *experimental* while this message persists. Contact Louis for more information.
%table.table
%thead
%tr
%th Week beginning
%th Number of Bikes
%th Mechanics Responsible
%tbody
- @weekly_data.each do |week, bikes|
%tr
%td= week.strftime("%m/%d/%y")
%td= bikes.length
%td= bikes.map(&:mechanic).uniq.to_sentence