Last active
April 6, 2022 18:40
-
-
Save davidleandro/0ca2d2ce1236bd9cfec1410b688e6d4c to your computer and use it in GitHub Desktop.
Popula respostas para os ultimos 30 dias de cada usuario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user_ids = User.where(status_record: :active).order('RANDOM()').limit(100) | |
30.times do |i| | |
date = (Date.today - i.days) | |
User.where(id: user_ids).each_with_index do |user, z| | |
datetime_start = Faker::Time.between(from: date.beginning_of_day, to: date.end_of_day) | |
datetime_end = Faker::Time.between(from: datetime_start, to: date.end_of_day) | |
daily_grouped_answer = user.daily_grouped_answers.new(datetime_start: datetime_start, datetime_end: datetime_end) | |
daily_grouped_answer.save(validate: false) | |
Question.limit(100).order('RANDOM()').each do |question| | |
alternative = question.alternatives.where(is_correct: [true, false].sample).sample | |
alternative = question.alternatives.sample unless alternative | |
created_at = Faker::Time.between(from: datetime_start, to: datetime_end) | |
question.answers.new( | |
is_correct: alternative&.is_correct, | |
user: user, | |
alternative: alternative, | |
daily_grouped_answer: daily_grouped_answer, | |
created_at: created_at, | |
updated_at: created_at | |
).save(validate: false) | |
p "RESPONDING ANSWER: #{user.name} #{question.code} #{i}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment