|
1 | | -import random, pytz |
| 1 | +import random, pytz, datetime |
2 | 2 |
|
3 | 3 |
|
4 | 4 | from django.utils import timezone |
|
20 | 20 | Visit, |
21 | 21 | ProgramServiceMap, |
22 | 22 | UrgencyLevel, |
| 23 | + ProgramAvailability |
23 | 24 | ) |
24 | 25 | from core.permissions import CASE_MANAGER, FRONT_DESK, ADMIN |
25 | 26 | from core.models.front_desk_event import FrontDeskEventType, FrontDeskEvent |
@@ -90,17 +91,44 @@ def frequency(self): |
90 | 91 | fake.add_provider(FrequencyProvider) |
91 | 92 |
|
92 | 93 |
|
| 94 | +class MonFriProvider(BaseProvider): |
| 95 | + __provider__ = "day of week" |
| 96 | + __lang__ = "en_US" |
| 97 | + |
| 98 | + def mon_fri(self): |
| 99 | + days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] |
| 100 | + return random.choices(days) |
| 101 | + |
| 102 | + |
| 103 | +fake.add_provider(MonFriProvider) |
| 104 | + |
| 105 | + |
| 106 | +class AvailabilityWindowProvider(BaseProvider): |
| 107 | + """For HRSC sign in. HRSC appointments are available Mon-Fri, 10a-4p""" |
| 108 | + __provider__ = "availability window" |
| 109 | + __lang__ = "en_US" |
| 110 | + |
| 111 | + def availability_window(self, start_hour = 10, end_hour = 17): |
| 112 | + """Returns a tuple (start_time, end_time)""" |
| 113 | + window_begin = random.randint(start_hour, end_hour - 2) |
| 114 | + end_hour = random.randint(window_begin + 1, end_hour) |
| 115 | + return datetime.time(hour=window_begin), datetime.time(hour=end_hour) |
| 116 | + |
| 117 | + |
| 118 | +fake.add_provider(AvailabilityWindowProvider) |
| 119 | + |
| 120 | + |
93 | 121 | def run_seed(self): |
94 | | - call_command("migrate") |
95 | | - call_command("flush") |
| 122 | + call_command("migrate", interactive=False) |
| 123 | + call_command("flush", interactive=False) |
96 | 124 | create_groups(output=False) |
97 | 125 | create_users(output=False) |
98 | 126 | add_users_to_groups(output=False) |
99 | 127 | create_insurers(output=False) |
100 | 128 | create_participants() |
101 | 129 | create_programs(output=False) |
102 | 130 | create_visits(output=False) |
103 | | - |
| 131 | + create_program_availability(output=False) |
104 | 132 |
|
105 | 133 | def create_users(output=True): |
106 | 134 | for group in DEFAULT_GROUPS: |
@@ -298,6 +326,36 @@ def create_event(visit, type): |
298 | 326 | f.full_clean() |
299 | 327 | f.save() |
300 | 328 |
|
| 329 | + |
| 330 | +def create_program_availability(output=True): |
| 331 | + """create program availability""" |
| 332 | + programs = Program.objects.all() |
| 333 | + days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] |
| 334 | + for program in programs: |
| 335 | + for day in days_of_week: |
| 336 | + if random.randint(0, 10) < 8: |
| 337 | + availability = ProgramAvailability() |
| 338 | + availability.program = program |
| 339 | + availability.day_of_week = day |
| 340 | + availability.start_time, availability.end_time = fake.availability_window( |
| 341 | + start_hour=8, end_hour=18) |
| 342 | + window_one_end = availability.end_time.hour |
| 343 | + availability.full_clean() |
| 344 | + availability.save() |
| 345 | + if window_one_end < 15: |
| 346 | + availability_two = ProgramAvailability() |
| 347 | + availability_two.program = program |
| 348 | + availability_two.day_of_week = day |
| 349 | + availability_two.start_time, availability_two.end_time = fake.availability_window( |
| 350 | + start_hour=window_one_end+1, end_hour=23) |
| 351 | + availability_two.full_clean() |
| 352 | + availability_two.save() |
| 353 | + |
| 354 | + if output: |
| 355 | + for availability in ProgramAvailability.objects.all().order_by('program'): |
| 356 | + print(f"Created program availability: {availability.program.name} {availability.day_of_week} {availability.start_time} {availability.end_time}") |
| 357 | + |
| 358 | + |
301 | 359 | def arrived(visit): |
302 | 360 | """After ARRIVED, can be either LEFT, SEEN, STEPPED_OUT or pending (still in ARRIVED status)""" |
303 | 361 | create_event(visit, "ARRIVED") |
|
0 commit comments