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