def test_get_available_couples(self): spec = [ (0, True, False, [0, 1, 2, 3]), (1, True, False, [3, 3, 3, 3]), (2, True, False, [1, 2, 1, 2]), (3, False, False, [3, 0, 3, 3]), (4, False, False, [3, 0, 3, 3]), (5, False, True, [0, 0, 3, 3]), (6, False, True, [3, 0, 3, 3]), (7, False, True, [0, 0, 3, 3]), ] self.setup_couple_availabilty(self.season, self.guys, self.girls, spec) couples = Scheduler.get_available_couples(self.meetings[0]) self.assertEqual(len(couples), 1) couples = Scheduler.get_available_couples(self.meetings[3]) self.assertEqual(len(couples), 2) couples = Scheduler.get_available_couples(self.meetings[0], fulltime=False) self.assertEqual(len(couples), 3) couples = Scheduler.get_available_couples(self.meetings[2], fulltime=False) self.assertEqual(len(couples), 5)
def send_schedule_update(self, request, date, message=None): tb = Scheduler() mtg = get_meeting_for_date(date) players = tb.query_schedule(date) from_email = settings.EMAIL_HOST_USER # Generate Text and HTML versions. body = self.build_notify_message(mtg.date, players, message=message) html_body = self.build_html_notify_message(mtg.date, players, message=message) subject = settings.BLOCK_NOTIFY_SUBJECT % date if settings.TEST_BLOCK_NOTIFY_RECIPIENTS: recipients = settings.TEST_BLOCK_NOTIFY_RECIPIENTS cc_list = [] else: recipients, cc_list = tb.get_notify_email_lists() msg = EmailMultiAlternatives(subject=subject, body=body, from_email=from_email, to=recipients, cc=cc_list) msg.attach_alternative(html_body, 'text/html') msg.send() return JSONResponse({})
def test_get_available_singles(self): spec = [ (0, True, False, [0, 1, 2, 3]), (1, True, False, [3, 3, 3, 3]), (2, True, False, [1, 2, 1, 2]), (3, False, True, [3, 0, 3, 0]), (4, False, True, [3, 0, 3, 1]), (5, False, True, [0, 0, 3, 2]), (6, False, True, [3, 0, 3, 3]), (7, False, True, [0, 0, 3, 0]), ] self.setup_couple_availabilty(self.season, self.guys, self.girls, spec) guys, girls = Scheduler.get_available_singles(self.meetings[0]) self.assertEqual(len(guys), 3) self.assertEqual(len(girls), 3) guys, girls = Scheduler.get_available_singles(self.meetings[1]) self.assertEqual(len(guys), 0) self.assertEqual(len(girls), 0) guys, girls = Scheduler.get_available_singles(self.meetings[2]) self.assertEqual(len(guys), 5) self.assertEqual(len(girls), 5) guys, girls = Scheduler.get_available_singles(self.meetings[3]) self.assertEqual(len(guys), 2) self.assertEqual(len(girls), 2)
def delete(self, request, date=None): # ToDo: Insure is Admin user, not just authenticated tb = Scheduler() logger.info("blockSchedule DELETE for date:%s" % date) mgr = TeamManager() mgr.dbTeams.delete_matchup(date) tb.remove_all_couples_from_schedule(date) return Response({'status': 'success'})
def test_get_next_group_meeting_one(self): """ Test the initial version where there is no play history """ scheduler = Scheduler() group = scheduler.get_next_group(with_singles=False) self.assertIsNotNone(group) self.assertEqual(len(group), 4)
def test_block_schedule_update(self): date = '2019-09-27' mtg = get_meeting_for_date(date) couples = Scheduler.get_couples(mtg) result = Scheduler.update_schedule(date, couples) new_couples = Scheduler.get_couples(mtg) self.assertEqual(couples, new_couples) pass
def post(self, request, date=None): couples = request.data.get('couples') result = {'status': "Did not execute"} if couples: tb = Scheduler() result['status'] = tb.update_schedule(date, couples) mgr = TeamManager() mgr.dbTeams.delete_matchup(date) else: result['status'] = "Did not decode the guys and gals" return Response(result)
def test_is_player_available(self): """ Test if a player is available for a given meeting """ mtg = self.meetings[0] print(f'Meeting index {mtg.meeting_index}') player = self.guys[0] av = PlayerAvailability.objects.get_for_season_player( season=self.season, player=player) self.assertTrue(Scheduler.is_player_available(mtg, player)) av.available[0] = False av.save() self.assertFalse(Scheduler.is_player_available(mtg, player))
def test_play_stats_calc_with_plays_3(self): couple = self.couples[1] self.add_couple_plays(couple, [1, 0, 0, 1, 0, 1], [0, 0, 0, 1, 0, 1]) info = Scheduler.calc_play_stats_for_couple(self.season, couple) self.assertEqual(info.get('total_plays'), 3) self.assertEqual(info.get('weight'), 2.5)
def test_play_stats_calc_with_plays(self): couple = self.couples[1] self.add_couple_plays(couple, [1, 1, 1, 1], [1, 1, 1, 1]) info = Scheduler.calc_play_stats_for_couple(self.season, couple) self.assertEqual(info.get('total_plays'), 4) self.assertEqual(info.get('couple'), couple)
def post(self, request, date=None): # ToDo: Insure is Admin user, not just authenticated logger.info("blockSchedule POST for date:%s" % date) sched = Scheduler.generate_schedule(date) return Response(sched)
def handle(self, *args, **options): date = options['date'] logger.info("blockSchedule POST for date:%s" % date) sched = Scheduler.generate_schedule(date) if sched is None: logger.error(f"Invalid date specified, no meetings on that date.") else: logger.info(f"Schedule for date is {sched}")
def test_is_couple_available(self): """ Must create a couple, then validate they work This is a trivial function however.. """ mtg = self.meetings[0] guy = self.guys[0] girl = self.girls[0] av1 = PlayerAvailability.objects.get_for_season_player( season=self.season, player=guy) av2 = PlayerAvailability.objects.get_for_season_player( season=self.season, player=girl) couple = Couple(male=guy, female=girl) self.assertTrue(Scheduler.is_couple_available(mtg, couple)) av1.available[0] = False av1.save() self.assertFalse(Scheduler.is_couple_available(mtg, couple)) self.assertFalse(Scheduler.is_couple_available(mtg, couple)) self.assertFalse(Scheduler.is_couple_available(mtg, couple))
def test_initial_update(self): """ Build structure of couples: couple: {'guy': {'id': Player.pk, 'issub': Boolean, 'verified': Boolean}, 'gal': {'id': Player.pk, 'issub': Boolean, 'verified': Boolean}, } couples is array of couple :return: """ meeting = self.meetings[0] couples = self.build_couples() scheduler = Scheduler() date = meeting.date.strftime("%Y-%m-%d") scheduler.update_schedule(date, couples) sch = Schedule.objects.filter(meeting=meeting).all() self.assertEqual(len(sch), len(couples) * 2) self.assertEqual(ScheduleVerify.objects.all().count(), 0) for s in sch: v = s.get_verification() self.assertEqual(len(couples) * 2, ScheduleVerify.objects.all().count(), f'Verify object count should have been {len(couples) * 2}') self.assertEqual(len(couples) * 2, ScheduleVerify.objects.filter(sent_on__isnull=True).count(), f'Verify object sent count should have been {len(couples) * 2}' ) request = factory.post(reverse('api:scheduleverify_for_date', kwargs={'date': date})) force_authenticate(request, user=self.admin_user) response = ScheduleNotifyView.as_view()(request, date=date) self.assertEqual(response.status_code, 200)
def schedule(self, date): scheduler = Scheduler() logger.info("blockSchedule POST for date:%s" % date) group = scheduler.get_next_group(date) logger.info("Groups:") for g in group: logger.info("\tHe:%s She:%s" % (g.male.Name(), g.female.Name())) scheduler.add_group_to_schedule(date, group) mgr = TeamManager() mgr.dbTeams.delete_matchup(date) sched = scheduler.query_schedule(date)
def test_play_stats_calc_no_plays(self): couple = self.couples[1] info = Scheduler.calc_play_stats_for_couple(self.season, couple) self.assertEqual(info.get('total_plays'), 0) self.assertEqual(info.get('weight'), 0)
def get(self, request, date=None): logger.info(f"Getting players for block for date {date}") tb = Scheduler() data = tb.query_schedule(date) return Response(data)
def get(self, request, date=None): tb = Scheduler() sched = tb.query_schedule(date) return Response(sched)