Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
namespace SportClimbing\IfscCalendar\Domain\Athlete;

enum IFSCAthleteGender: string
enum IFSCAthleteCategory: string
{
case MEN = 'men';
case WOMEN = 'women';
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Round/IFSCRound.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
namespace SportClimbing\IfscCalendar\Domain\Round;

use DateTimeImmutable;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteGender;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteCategory;
use SportClimbing\IfscCalendar\Domain\Discipline\IFSCDisciplines;
use SportClimbing\IfscCalendar\Domain\Stream\LiveStream;

final readonly class IFSCRound
{
/** @param IFSCAthleteGender[] $categories */
/** @param IFSCAthleteCategory[] $categories */
public function __construct(
public string $name,
public array $categories,
Expand Down
6 changes: 3 additions & 3 deletions src/Domain/Round/IFSCSameStreamRoundsMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace SportClimbing\IfscCalendar\Domain\Round;

use DateTimeImmutable;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteGender;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteCategory;
use SportClimbing\IfscCalendar\Domain\Tags\IFSCTagsParser;

final readonly class IFSCSameStreamRoundsMerger
Expand Down Expand Up @@ -108,7 +108,7 @@ private function buildMergedName(array $rounds): string

/**
* @param IFSCRound[] $rounds
* @return IFSCAthleteGender[]
* @return IFSCAthleteCategory[]
*/
private function mergedCategories(array $rounds): array
{
Expand All @@ -122,7 +122,7 @@ private function mergedCategories(array $rounds): array
}
}

usort($categories, static fn (IFSCAthleteGender $a, IFSCAthleteGender $b) => $a->value <=> $b->value);
usort($categories, static fn (IFSCAthleteCategory $a, IFSCAthleteCategory $b) => $a->value <=> $b->value);

return $categories;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Domain/StartList/IFSCStartListGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteService;
use SportClimbing\IfscCalendar\Domain\Ranking\IFSCAthleteRankingCalculator;

use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteGender;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteCategory;

final readonly class IFSCStartListGenerator
{
Expand All @@ -39,7 +39,7 @@ public function buildStartList(int $eventId): IFSCStartListResult
$starter->score = $this->rankingCalculator->calculateScore($athlete);
$starter->photoUrl = $athlete->photoUrl;
$starter->instagram = $this->normalizeInstagram($athlete->instagram);
$starter->gender = $this->getGender($athlete);
$starter->category = $this->getCategory($athlete);

$startList[] = $starter;
}
Expand All @@ -58,8 +58,8 @@ public function buildStartList(int $eventId): IFSCStartListResult
*/
private function selectTopByGender(array $startList): array
{
$men = $this->filterByGender($startList, IFSCAthleteGender::MEN);
$women = $this->filterByGender($startList, IFSCAthleteGender::WOMEN);
$men = $this->filterByGender($startList, IFSCAthleteCategory::MEN);
$women = $this->filterByGender($startList, IFSCAthleteCategory::WOMEN);

$selectedMen = $this->selectTopFromPool($men, array_slice($women, self::PER_GENDER_MAX));
$selectedWomen = $this->selectTopFromPool($women, array_slice($men, self::PER_GENDER_MAX));
Expand Down Expand Up @@ -101,9 +101,9 @@ private function sortByScore(): Closure
}

/** @return IFSCStarter[] */
public function filterByGender(array $startList, IFSCAthleteGender $gender): array
public function filterByGender(array $startList, IFSCAthleteCategory $category): array
{
return array_values(array_filter($startList, fn (IFSCStarter $starter): bool => $starter->gender === $gender));
return array_values(array_filter($startList, fn (IFSCStarter $starter): bool => $starter->category === $category));
}

private function normalizeInstagram(?string $instagram): ?string
Expand All @@ -122,13 +122,13 @@ private function normalizeInstagram(?string $instagram): ?string

/**
* @param IFSCAthlete $athlete
* @return IFSCAthleteGender|null
* @return IFSCAthleteCategory|null
*/
private function getGender(IFSCAthlete $athlete): ?IFSCAthleteGender
private function getCategory(IFSCAthlete $athlete): ?IFSCAthleteCategory
{
return match ($athlete->gender) {
'male' => IFSCAthleteGender::MEN,
'female' => IFSCAthleteGender::WOMEN,
'male' => IFSCAthleteCategory::MEN,
'female' => IFSCAthleteCategory::WOMEN,
default => null,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/StartList/IFSCStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace SportClimbing\IfscCalendar\Domain\StartList;

use SportClimbing\IfscCalendar\Domain\Discipline\IFSCDiscipline;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteGender;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteCategory;

final class IFSCStarter
{
Expand All @@ -18,7 +18,7 @@ public function __construct(
public readonly string $firstName,
public readonly string $lastName,
public readonly string $country,
public ?IFSCAthleteGender $gender = null,
public ?IFSCAthleteCategory $category = null,
public readonly array $disciplines = [],
public float $score = 0,
public ?string $photoUrl = null,
Expand Down
14 changes: 7 additions & 7 deletions src/Domain/Tags/IFSCParsedTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use SportClimbing\IfscCalendar\Domain\Discipline\IFSCDiscipline;
use SportClimbing\IfscCalendar\Domain\Event\IFSCEventTagsRegex as Tag;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteGender;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteCategory;
use SportClimbing\IfscCalendar\Domain\Round\IFSCRoundKind;

final readonly class IFSCParsedTags
Expand All @@ -29,8 +29,8 @@
];

private const array CATEGORIES = [
IFSCAthleteGender::WOMEN->value => Tag::WOMEN,
IFSCAthleteGender::MEN->value => Tag::MEN,
IFSCAthleteCategory::WOMEN->value => Tag::WOMEN,
IFSCAthleteCategory::MEN->value => Tag::MEN,
];

/** @param Tag[] $tags */
Expand Down Expand Up @@ -75,20 +75,20 @@ public function getRoundKind(): ?IFSCRoundKind
return null;
}

/** @return IFSCAthleteGender[] */
/** @return IFSCAthleteCategory[] */
public function getCategories(): array
{
$categories = [];

foreach (self::CATEGORIES as $name => $tag) {
if ($this->hasTag($tag)) {
$categories[] = IFSCAthleteGender::from($name);
$categories[] = IFSCAthleteCategory::from($name);
}
}

if (empty($categories)) {
$categories[] = IFSCAthleteGender::WOMEN;
$categories[] = IFSCAthleteGender::MEN;
$categories[] = IFSCAthleteCategory::WOMEN;
$categories[] = IFSCAthleteCategory::MEN;
}

return $categories;
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Calendar/ICalCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function convertStarterToArray(IFSCStarter $starter): array
'first_name' => $starter->firstName,
'last_name' => $starter->lastName,
'country' => $starter->country,
'category' => $starter->gender?->value,
'category' => $starter->category?->value,
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/Infrastructure/Calendar/JsonCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use SportClimbing\IfscCalendar\Domain\Discipline\IFSCDiscipline;
use SportClimbing\IfscCalendar\Domain\Event\IFSCEvent;
use SportClimbing\IfscCalendar\Domain\Round\IFSCRound;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteGender;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteCategory;
use SportClimbing\IfscCalendar\Domain\StartList\IFSCStarter;
use Override;

Expand Down Expand Up @@ -99,7 +99,7 @@ private function formatStarters(array $starters): array
'athlete_id' => $starter->athleteId,
'first_name' => $starter->firstName,
'last_name' => $starter->lastName,
'gender' => $starter->gender,
'category' => $starter->category,
'country' => $starter->country,
'photo_url' => $starter->photoUrl,
'instagram' => $starter->instagram,
Expand Down Expand Up @@ -139,7 +139,7 @@ private function buildDisciplines(IFSCRound $round): array
/** @return string[] */
private function buildCategories(IFSCRound $round): array
{
return array_map(static fn (IFSCAthleteGender $category): string => $category->value, $round->categories);
return array_map(static fn (IFSCAthleteCategory $category): string => $category->value, $round->categories);
}

private function countryName(string $countryCode): string
Expand Down
40 changes: 20 additions & 20 deletions tests/unit/Domain/Round/IFSCSameStreamRoundsMergerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SportClimbing\IfscCalendar\Domain\Discipline\IFSCDiscipline;
use SportClimbing\IfscCalendar\Domain\Discipline\IFSCDisciplines;
use SportClimbing\IfscCalendar\Domain\Round\IFSCRound;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteGender;
use SportClimbing\IfscCalendar\Domain\Athlete\IFSCAthleteCategory;
use SportClimbing\IfscCalendar\Domain\Round\IFSCRoundKind;
use SportClimbing\IfscCalendar\Domain\Round\IFSCRoundNameNormalizer;
use SportClimbing\IfscCalendar\Domain\Round\IFSCRoundStatus;
Expand All @@ -37,14 +37,14 @@ protected function setUp(): void
{
$stream = new LiveStream(url: 'https://youtu.be/abc123');

$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteGender::MEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 14:00', '2025-05-10 15:30');
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteGender::WOMEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 15:30', '2025-05-10 17:00');
$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteCategory::MEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 14:00', '2025-05-10 15:30');
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteCategory::WOMEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 15:30', '2025-05-10 17:00');

$result = $this->merger->merge([$mens, $womens]);

$this->assertCount(1, $result);
$this->assertSame("Men's & Women's Lead Final", $result[0]->name);
$this->assertSame([IFSCAthleteGender::MEN, IFSCAthleteGender::WOMEN], $result[0]->categories);
$this->assertSame([IFSCAthleteCategory::MEN, IFSCAthleteCategory::WOMEN], $result[0]->categories);
$this->assertSame($mens->startTime, $result[0]->startTime);
$this->assertSame('2025-05-10T17:00:00+00:00', $result[0]->endTime->format(DATE_RFC3339));
$this->assertSame('https://youtu.be/abc123', $result[0]->liveStream->url);
Expand All @@ -54,23 +54,23 @@ protected function setUp(): void
{
$stream = new LiveStream(url: 'https://youtu.be/abc123');

$womens = $this->makeRound("Women's Boulder Qualification", [IFSCAthleteGender::WOMEN], IFSCRoundKind::QUALIFICATION, $stream, '2025-05-10 09:00', '2025-05-10 12:00');
$mens = $this->makeRound("Men's Boulder Qualification", [IFSCAthleteGender::MEN], IFSCRoundKind::QUALIFICATION, $stream, '2025-05-10 12:00', '2025-05-10 15:00');
$womens = $this->makeRound("Women's Boulder Qualification", [IFSCAthleteCategory::WOMEN], IFSCRoundKind::QUALIFICATION, $stream, '2025-05-10 09:00', '2025-05-10 12:00');
$mens = $this->makeRound("Men's Boulder Qualification", [IFSCAthleteCategory::MEN], IFSCRoundKind::QUALIFICATION, $stream, '2025-05-10 12:00', '2025-05-10 15:00');

$result = $this->merger->merge([$womens, $mens]);

$this->assertCount(1, $result);
$this->assertSame("Men's & Women's Boulder Qualification", $result[0]->name);
$this->assertSame([IFSCAthleteGender::MEN, IFSCAthleteGender::WOMEN], $result[0]->categories);
$this->assertSame([IFSCAthleteCategory::MEN, IFSCAthleteCategory::WOMEN], $result[0]->categories);
}

#[Test] public function rounds_with_different_stream_urls_are_not_merged(): void
{
$streamA = new LiveStream(url: 'https://youtu.be/aaa');
$streamB = new LiveStream(url: 'https://youtu.be/bbb');

$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteGender::MEN], IFSCRoundKind::FINAL, $streamA, '2025-05-10 14:00', '2025-05-10 15:30');
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteGender::WOMEN], IFSCRoundKind::FINAL, $streamB, '2025-05-10 15:30', '2025-05-10 17:00');
$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteCategory::MEN], IFSCRoundKind::FINAL, $streamA, '2025-05-10 14:00', '2025-05-10 15:30');
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteCategory::WOMEN], IFSCRoundKind::FINAL, $streamB, '2025-05-10 15:30', '2025-05-10 17:00');

$result = $this->merger->merge([$mens, $womens]);

Expand All @@ -81,8 +81,8 @@ protected function setUp(): void
{
$noStream = new LiveStream();

$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteGender::MEN], IFSCRoundKind::FINAL, $noStream, '2025-05-10 14:00', '2025-05-10 15:30');
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteGender::WOMEN], IFSCRoundKind::FINAL, $noStream, '2025-05-10 15:30', '2025-05-10 17:00');
$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteCategory::MEN], IFSCRoundKind::FINAL, $noStream, '2025-05-10 14:00', '2025-05-10 15:30');
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteCategory::WOMEN], IFSCRoundKind::FINAL, $noStream, '2025-05-10 15:30', '2025-05-10 17:00');

$result = $this->merger->merge([$mens, $womens]);

Expand All @@ -93,8 +93,8 @@ protected function setUp(): void
{
$stream = new LiveStream(url: 'https://youtu.be/abc123');

$qual = $this->makeRound("Men's Lead Qualification", [IFSCAthleteGender::MEN], IFSCRoundKind::QUALIFICATION, $stream, '2025-05-10 09:00', '2025-05-10 12:00');
$final = $this->makeRound("Women's Lead Final", [IFSCAthleteGender::WOMEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 15:00', '2025-05-10 17:00');
$qual = $this->makeRound("Men's Lead Qualification", [IFSCAthleteCategory::MEN], IFSCRoundKind::QUALIFICATION, $stream, '2025-05-10 09:00', '2025-05-10 12:00');
$final = $this->makeRound("Women's Lead Final", [IFSCAthleteCategory::WOMEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 15:00', '2025-05-10 17:00');

$result = $this->merger->merge([$qual, $final]);

Expand All @@ -105,8 +105,8 @@ protected function setUp(): void
{
$stream = new LiveStream(url: 'https://youtu.be/abc123');

$lead = $this->makeRound("Men's Lead Final", [IFSCAthleteGender::MEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 14:00', '2025-05-10 15:30', IFSCDiscipline::LEAD);
$boulder = $this->makeRound("Women's Boulder Final", [IFSCAthleteGender::WOMEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 15:30', '2025-05-10 17:00', IFSCDiscipline::BOULDER);
$lead = $this->makeRound("Men's Lead Final", [IFSCAthleteCategory::MEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 14:00', '2025-05-10 15:30', IFSCDiscipline::LEAD);
$boulder = $this->makeRound("Women's Boulder Final", [IFSCAthleteCategory::WOMEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 15:30', '2025-05-10 17:00', IFSCDiscipline::BOULDER);

$result = $this->merger->merge([$lead, $boulder]);

Expand All @@ -117,8 +117,8 @@ protected function setUp(): void
{
$stream = new LiveStream(url: 'https://youtu.be/abc123');

$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteGender::MEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 14:00', '2025-05-10 15:30', status: IFSCRoundStatus::PROVISIONAL);
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteGender::WOMEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 15:30', '2025-05-10 17:00', status: IFSCRoundStatus::CONFIRMED);
$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteCategory::MEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 14:00', '2025-05-10 15:30', status: IFSCRoundStatus::PROVISIONAL);
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteCategory::WOMEN], IFSCRoundKind::FINAL, $stream, '2025-05-10 15:30', '2025-05-10 17:00', status: IFSCRoundStatus::CONFIRMED);

$result = $this->merger->merge([$mens, $womens]);

Expand All @@ -131,9 +131,9 @@ protected function setUp(): void
$otherStream = new LiveStream(url: 'https://youtu.be/other');
$noStream = new LiveStream();

$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteGender::MEN], IFSCRoundKind::FINAL, $sharedStream, '2025-05-10 14:00', '2025-05-10 15:30');
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteGender::WOMEN], IFSCRoundKind::FINAL, $sharedStream, '2025-05-10 15:30', '2025-05-10 17:00');
$speed = $this->makeRound("Men's Speed Final", [IFSCAthleteGender::MEN], IFSCRoundKind::FINAL, $otherStream, '2025-05-10 18:00', '2025-05-10 19:00');
$mens = $this->makeRound("Men's Lead Final", [IFSCAthleteCategory::MEN], IFSCRoundKind::FINAL, $sharedStream, '2025-05-10 14:00', '2025-05-10 15:30');
$womens = $this->makeRound("Women's Lead Final", [IFSCAthleteCategory::WOMEN], IFSCRoundKind::FINAL, $sharedStream, '2025-05-10 15:30', '2025-05-10 17:00');
$speed = $this->makeRound("Men's Speed Final", [IFSCAthleteCategory::MEN], IFSCRoundKind::FINAL, $otherStream, '2025-05-10 18:00', '2025-05-10 19:00');
$boulderQual = $this->makeRound("Boulder Qualification", [], IFSCRoundKind::QUALIFICATION, $noStream, '2025-05-09 09:00', '2025-05-09 13:00');

$result = $this->merger->merge([$mens, $womens, $speed, $boulderQual]);
Expand Down
Loading
Loading