diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 694269f..a021802 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -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 diff --git a/app/models/report.rb b/app/models/report.rb index 1d394d6..ef50dd4 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -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} diff --git a/app/views/reports/bikes_fixed_per_week.html.haml b/app/views/reports/bikes_fixed_per_week.html.haml new file mode 100644 index 0000000..7b1d3bd --- /dev/null +++ b/app/views/reports/bikes_fixed_per_week.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 8ad0728..156b52d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,10 +20,10 @@ Bikedb::Application.routes.draw do get 'receipt' => 'freecyclery#receipt' get 'print_select' => 'clients#print_select', on: :collection get 'print_receipts' => 'clients#print_receipts', on: :collection - end get 'closed_applications' => 'freecyclery#closed_applications' get 'available_bikes' => 'freecyclery#available_bikes' get 'bikes_sold_per_year' => 'reports#bikes_sold_per_year' + get 'bikes_fixed_per_week' => 'reports#bikes_fixed_per_week' end diff --git a/notes.txt b/notes.txt index d911eca..0fada13 100644 --- a/notes.txt +++ b/notes.txt @@ -1,5 +1,21 @@ change agency#phone_number to agency#phone +store date fixed as a real date instead of a string and fix all the data + null values should be date_created + empty strings should be date created + strings of format mm/dd/yy + strings of format mm/dd/yyyy + +add mechanics table and change text input to a dropdown + + + + + + + +when client is created without date, app breaks + on website, tailwind for tools initiative looks weird in carousel on mobile @@ -37,5 +53,4 @@ add recyclery logos & bike memorabilia pics all over app do bike sales labels fit into sleeves? (sheaths are 5x3.75) freecyclery bikes need receipts when application is voided, bike should go back to pool of bikes -when client is created without date, app breaks phone calls made is unnecessary - notes are usualy used