fix weekly

This commit is contained in:
Torsten 2023-07-11 09:26:11 +03:00
parent 1b44e9464f
commit d29208ca83

View File

@ -29,21 +29,21 @@ module TimelineHelper
max = max_days - started_days(member) max = max_days - started_days(member)
distance > max ? max : distance distance > max ? max : distance
end end
# weekly occupany, hash containing weeks to number of volunteer mapping
def weekly def weekly
data = {} data = {}
week = 0 month_start = Date.today.at_beginning_of_month
while( week < @weeks ) do ( 0 ... @weeks ).each do |week|
data[ week ] = -1 data[ week ] = -1
start_week = Date.today.at_beginning_of_month + week.weeks end_week = month_start + week.weeks
end_week = Date.today.at_beginning_of_month + (week + 1).weeks
@members.each do |mem| @members.each do |mem|
next unless mem.arriving next unless mem.arriving
next unless mem.leaving next unless mem.leaving
next if mem.arriving > start_week next if mem.leaving <= end_week
next if mem.leaving < end_week next if mem.arriving >= (end_week - 7.days)
data[ week ] += 1 data[ week ] += 1
end end
week += 1
end end
data data
end end