Skip to content

Instantly share code, notes, and snippets.

@davidleandro
Created November 29, 2021 15:03
Show Gist options
  • Save davidleandro/ee8073e3de0a660c9c41c9bd586b9bf8 to your computer and use it in GitHub Desktop.
Save davidleandro/ee8073e3de0a660c9c41c9bd586b9bf8 to your computer and use it in GitHub Desktop.
Criar sprints com slots
count = 0
content_types = ContentType.all
5.times do |i|
2.times do
date = (Date.today - 2.months) + (7*count)
count += 1
UserDetail.includes(:user).where.not(hours_by_week: nil).each_with_index do |user_detail, z|
next if user_detail.user.nil?
sprint = Sprint.new(
hours_by_week: user_detail.hours_by_week,
initial_date: date.beginning_of_week(start_day = :sunday),
end_date: date.end_of_week(start_day = :sunday),
user: user_detail.user
)
sprint.save(validate: false)
p "CREATING SPRINT: #{user_detail.user.name}-#{i}-#{z}"
(user_detail.hours_by_week * 2).times do |i|
taxonomy = Taxonomy.where(taxonomy_parent_id: nil).sample
slot_date = Faker::Date.between(date.beginning_of_week(start_day = :sunday), date.end_of_week(start_day = :sunday))
slot_time = slot_date.to_time(:utc).change(hour: (0..23).to_a.sample, min: [0,30].sample)
slot_duration = slot_date.to_time(:utc).change(hour: (0..1).to_a.sample, min: [0,30].sample)
Slot.new(
sprint: sprint,
activity: Slot.activities.to_a.sample[0].to_sym,
taxonomy: taxonomy,
date: slot_date,
time: slot_time,
duration: slot_duration,
body: Faker::Hipster.paragraph(1),
accomplished: [true, false].sample,
content_type: content_types.sample,
taxonomies: Taxonomy.where(taxonomy_parent: taxonomy).order("RANDOM()").take(5)
).save(validate: false)
p "CREATING SLOT: #{user_detail.user.name}-#{i}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment