Class: RoomCoverageReport
- Inherits:
-
Object
- Object
- RoomCoverageReport
- Defined in:
- app/reports/room_coverage_report.rb
Instance Method Summary collapse
Instance Method Details
#median(array) ⇒ Object
20 21 22 23 24 25 |
# File 'app/reports/room_coverage_report.rb', line 20 def median(array) return nil if array.empty? sorted = array.sort len = sorted.length (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0 end |
#perform ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/reports/room_coverage_report.rb', line 3 def perform # Find rooms in the last year coverages = [] room_query.find_each do |rc| if (isqft = rc.installation_sqft) && (sf = rc.square_footage) && isqft > sf && isqft != sf percentage = ((sf.to_f / isqft) * 100).round(2) coverages << percentage if percentage < 100 && percentage > 0 end end { average_percentage: coverages.compact.average, sample_size: coverages.size, median: median(coverages), coverages: coverages } end |
#room_query ⇒ Object
27 28 29 |
# File 'app/reports/room_coverage_report.rb', line 27 def room_query RoomConfiguration.where(created_at: 1.year.ago.., state: 'complete', floor_type_id: [2,3]).where.not(square_footage: nil) end |