public function testCalculateClassficationByGroupDoubleTie() { $this->game1->setScore("6/0 6/0"); $this->game2->setScore("2/6 1/6"); $this->game3->setScore("4/6 2/6"); $this->game4->setScore("1/6 2/6"); $this->game5->setScore("6/1 6/2"); $this->game6->setScore("6/1 6/1"); $this->game7->setScore("6/0 6/4"); $this->game8->setScore("6/0 6/3"); $this->game9->setScore("6/1 6/2"); $this->game10->setScore("6/1 6/3"); $this->em->persist($this->game1); $this->em->persist($this->game2); $this->em->persist($this->game3); $this->em->persist($this->game4); $this->em->persist($this->game5); $this->em->persist($this->game6); $this->em->persist($this->game7); $this->em->persist($this->game8); $this->em->persist($this->game9); $this->em->persist($this->game10); $inscriptions = [$this->inscription1, $this->inscription2, $this->inscription3, $this->inscription4, $this->inscription5]; $groupService = new GroupService(); $groupService->setManager($this->em); $rankResult = $groupService->calculateClassficationByGroup($inscriptions, $this->group); $this->assertEquals(json_encode($rankResult), '[{"matchsWon":3,"setsWon":6,"setsLost":2,"gamesWon":36,"gamesLost":21,"points":9,"pair":' . $this->pair2->getId() . '},{"matchsWon":3,"setsWon":6,"setsLost":2,"gamesWon":39,"gamesLost":21,"points":9,"pair":' . $this->pair3->getId() . '},{"matchsWon":2,"setsWon":4,"setsLost":4,"gamesWon":29,"gamesLost":34,"points":6,"pair":' . $this->pair4->getId() . '},{"matchsWon":1,"setsWon":2,"setsLost":6,"gamesWon":23,"gamesLost":39,"points":3,"pair":' . $this->pair5->getId() . '},{"matchsWon":1,"setsWon":2,"setsLost":6,"gamesWon":24,"gamesLost":36,"points":3,"pair":' . $this->pair1->getId() . '}]'); $this->assertEquals($this->inscription1->getClassifiedPositionInGroup(), 4); $this->assertEquals($this->inscription2->getClassifiedPositionInGroup(), 0); $this->assertEquals($this->inscription3->getClassifiedPositionInGroup(), 1); $this->assertEquals($this->inscription4->getClassifiedPositionInGroup(), 2); $this->assertEquals($this->inscription5->getClassifiedPositionInGroup(), 3); }
public function closeGroupTournament($tournament) { $categoryService = new CategoryService(); $inscriptionService = new InscriptionService(); $groupService = new GroupService(); $categoryService->setManager($this->em); $inscriptionService->setManager($this->em); $groupService->setManager($this->em); $categories = $categoryService->getCategoryByTournament($tournament->getId()); foreach ($categories as $category) { $groupsRank = array(); $numPairsByGroup = array(); $allInscriptions = array(); $groups = $groupService->getGroupsByCategory($category->getId()); if (!is_null($groups)) { foreach ($groups as $group) { $inscriptions = $inscriptionService->getInscriptionsByGroup($group->getId(), null); $allInscriptions = array_merge($allInscriptions, $inscriptions); $groupRank = $groupService->calculateClassficationByGroup($inscriptions, $group); if (!is_null($groupRank)) { $numPairsByGroup[] = count($groupRank); $groupsRank[] = $groupRank; } } } if (!empty($groupsRank)) { rsort($numPairsByGroup); for ($i = 0; $i < $numPairsByGroup[0]; $i++) { $rankByGroupPositions = array(); foreach ($groupsRank as $groupRank) { if (count($groupRank) > $i && !is_null($groupRank[$i])) { $rankByGroupPositions[] = $groupRank[$i]; } } $rankByGroupPositions = $groupService->sortByScore($rankByGroupPositions); foreach ($allInscriptions as $inscription) { $position = 0; foreach ($rankByGroupPositions as $rank) { if ($inscription->getPair()->getId() == $rank['pair']) { $inscription->setClassifiedPositionByGroups($position); $this->em->persist($inscription); } $position = $position + 1; } } } } } $this->em->flush(); $result = array('result' => 'ok', 'message' => $inscriptionService->getInscriptionsByGroupForATournament($tournament->getId(), 'classifiedPositionInGroup')); return $result; }