app.kluk.fr/app/models/mood.rb

25 lines
683 B
Ruby
Raw Normal View History

2025-08-05 16:11:24 +02:00
class Mood < ApplicationRecord
def self.log
return if Mood.count < 1
first_mood = Mood.order(:recorded_at).first.recorded_at.to_date
first_monday = first_mood - (first_mood.wday - 1)
current_date = first_monday
current_mode = nil
log_mood = []
Mood.order(:recorded_at).all.each do |mood|
while current_date < mood.recorded_at.to_date do
log_mood << [ current_date.to_s, current_mode ]
current_date += 1
end
current_mode = mood.mode
end
while current_date <= Date.today do
log_mood << [ current_date.to_s, current_mode ]
current_date += 1
end
log_mood.each_slice(7).to_a.last(52)
end
end