Skip to content

Commit

Permalink
Add Learning Hours for the Seeder (#5403)
Browse files Browse the repository at this point in the history
  • Loading branch information
cflannagan authored Nov 22, 2023
1 parent 1a3e682 commit b6f2ec0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def active_record_classes
Supervisor,
SupervisorVolunteer,
User,
LearningHour,
Volunteer
]
end
Expand Down
24 changes: 24 additions & 0 deletions db/seeds/db_populator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def create_org(options_hash)
create_mileage_rates(casa_org)
create_learning_hour_types(casa_org)
create_learning_hour_topics(casa_org)
create_learning_hours(casa_org)
casa_org
end

Expand Down Expand Up @@ -386,6 +387,29 @@ def create_learning_hour_topics(casa_org)
end
end

def create_learning_hours(casa_org)
casa_org.volunteers.each do |user|
[1, 2, 3].sample.times do
learning_hour_topic = casa_org.learning_hour_topics.sample
learning_hour_type = casa_org.learning_hour_types.sample
# randomize between 30 to 180 minutes
duration_minutes = (2..12).to_a.sample * 15
duration_hours = duration_minutes / 60
duration_minutes = duration_minutes % 60
occurred_at = Time.current - (1..7).to_a.sample.days
LearningHour.create(
user:,
learning_hour_type:,
name: "#{learning_hour_type.name} on #{learning_hour_topic.name}",
duration_hours:,
duration_minutes:,
occurred_at:,
learning_hour_topic:
)
end
end
end

def most_recent_past_court_date(casa_case_id)
CourtDate.where(
"date < ? AND casa_case_id = ?",
Expand Down
1 change: 1 addition & 0 deletions spec/seeds/seeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def empty_ar_classes
Supervisor,
SupervisorVolunteer,
User,
LearningHour,
HearingType,
Volunteer,
CaseCourtOrder
Expand Down

0 comments on commit b6f2ec0

Please sign in to comment.