]> git.openstreetmap.org Git - rails.git/blob - app/helpers/heatmap_helper.rb
Add frozen_string_literal comments to ruby files
[rails.git] / app / helpers / heatmap_helper.rb
1 # frozen_string_literal: true
2
3 module HeatmapHelper
4   def prepare_heatmap(data, from, to)
5     # Pad the start by one week to ensure the heatmap can start on the first day of the week
6     all_days = ((from - 1.week).to_date..to.to_date).map do |date|
7       data[date] || { :date => date, :total_changes => 0 }
8     end
9
10     # Get unique months with repeating months and count into the next year with numbers over 12
11     month_offset = 0
12     months = ((from - 2.weeks).to_date..(to + 1.week).to_date)
13              .map(&:month)
14              .chunk_while { |before, after| before == after }
15              .map(&:first)
16              .map do |month|
17       month_offset += 12 if month == 1
18       month + month_offset
19     end
20
21     {
22       :days => all_days,
23       :months => months,
24       :max_per_day => data.values.pluck(:total_changes).max
25     }
26   end
27 end