From 7bfde8d2645793f9b3960de3a9baa0fd84f3ba57 Mon Sep 17 00:00:00 2001 From: Nico Oelgart Date: Sat, 18 May 2024 12:21:07 +0200 Subject: [PATCH] Fix oqs streams (#21) * Fix OQS live streams and schedule * Hardcode OQS schedule --- config/services/domain.yml | 2 +- .../PostProcess/Season2024PostProcessor.php | 63 +++++++++++++------ .../Schedule/PDFScheduleProviderTest.php | 51 +++++++-------- 3 files changed, 70 insertions(+), 46 deletions(-) diff --git a/config/services/domain.yml b/config/services/domain.yml index 8b2df2f..d8173db 100644 --- a/config/services/domain.yml +++ b/config/services/domain.yml @@ -22,8 +22,8 @@ services: nicoSWD\IfscCalendar\Domain\Calendar\PostProcess\Season2024PostProcessor: class: nicoSWD\IfscCalendar\Domain\Calendar\PostProcess\Season2024PostProcessor arguments: - - '@nicoSWD\IfscCalendar\Infrastructure\Round\InfoSheetRoundProvider' - '@nicoSWD\IfscCalendar\Domain\Round\IFSCRoundFactory' + - '@nicoSWD\IfscCalendar\Domain\Schedule\IFSCScheduleFactory' nicoSWD\IfscCalendar\Domain\Calendar\SiteURLBuilder: class: nicoSWD\IfscCalendar\Domain\Calendar\SiteURLBuilder diff --git a/src/Domain/Calendar/PostProcess/Season2024PostProcessor.php b/src/Domain/Calendar/PostProcess/Season2024PostProcessor.php index 0e6a375..ea1e29d 100644 --- a/src/Domain/Calendar/PostProcess/Season2024PostProcessor.php +++ b/src/Domain/Calendar/PostProcess/Season2024PostProcessor.php @@ -7,13 +7,15 @@ */ namespace nicoSWD\IfscCalendar\Domain\Calendar\PostProcess; +use DateTimeImmutable; +use DateTimeZone; use Exception; use nicoSWD\IfscCalendar\Domain\Event\IFSCEvent; use nicoSWD\IfscCalendar\Domain\Event\Info\IFSCEventInfo; +use nicoSWD\IfscCalendar\Domain\Round\IFSCRound; use nicoSWD\IfscCalendar\Domain\Round\IFSCRoundFactory; -use nicoSWD\IfscCalendar\Domain\Round\IFSCRoundProviderInterface; use nicoSWD\IfscCalendar\Domain\Round\IFSCRoundStatus; -use nicoSWD\IfscCalendar\Domain\Schedule\IFSCSchedule; +use nicoSWD\IfscCalendar\Domain\Schedule\IFSCScheduleFactory; use nicoSWD\IfscCalendar\Domain\Stream\LiveStream; final readonly class Season2024PostProcessor @@ -21,12 +23,11 @@ private const int WUJIANG_IFSC_EVENT_ID = 1354; private const string WUJIAN_POSTER_URL = 'https://res.dasheng.top/227/pro/ctms_tool/20240323/jpg/d7f6d496a71d4dc785c8d0e51169d17b.jpg'; private const int OLYMPIC_QUALIFIERS_SHANGHAI_ID = 1384; - private const string OLYMPIC_QUALIFIERS_SHANGHAI_INFO_SHEET = 'https://images.ifsc-climbing.org/ifsc/image/private/t_q_good/prd/yg3cqznmay12orsv9hpa.pdf'; private const string OLYMPIC_QUALIFIERS_SHANGHAI_LIVE_STREAM = 'https://olympics.com/en/sport-events/olympic-qualifier-series-2024-shanghai/broadcasting-schedule'; public function __construct( - private IFSCRoundProviderInterface $roundProvider, private IFSCRoundFactory $roundFactory, + private IFSCScheduleFactory $scheduleFactory, ) { } /** @@ -59,25 +60,47 @@ private function isOlympicQualifiersShanghai(IFSCEvent $event): bool private function fetchOlympicQualifiersShanghaiRounds(IFSCEvent $event): array { - $rounds = []; $eventInfo = IFSCEventInfo::fromEvent($event); - /** @var IFSCSchedule[] $schedules */ - $schedules = $this->roundProvider->fetchRoundsFromInfoSheet( - event: $eventInfo, - infoSheetUrl: self::OLYMPIC_QUALIFIERS_SHANGHAI_INFO_SHEET, + + return [ + // 16/5 + $this->round($eventInfo, "Men's & Women's Boulder Qualification", '2024-05-16T04:30:00+02:00'), + + // 17/5 + $this->round($eventInfo, "Men's & Women's Lead Qualification", '2024-05-17T04:00:00+02:00'), + $this->round($eventInfo, "Women's Speed Qualification", '2024-05-17T10:50:00+02:00'), + $this->round($eventInfo, "Men's Speed Qualification", '2024-05-17T11:45:00+02:00'), + + // 18/5 + $this->round($eventInfo, "Men's & Women's Boulder Semifinal", '2024-05-18T03:30:00+02:00'), + $this->round($eventInfo, "Men's & Women's Lead Semifinal", '2024-05-18T07:30:00+02:00'), + $this->round($eventInfo, "Men's & Women's Speed Final", '2024-05-18T11:00:00+02:00'), + + // 19/05 + $this->round($eventInfo, "Men's Boulder Final", '2024-05-19T04:00:00+02:00'), + $this->round($eventInfo, "Men's Lead Final", '2024-05-19T06:05:00+02:00'), + $this->round($eventInfo, "Women's Boulder Final", '2024-05-19T09:25:00+02:00'), + $this->round($eventInfo, "Women's Lead Final", '2024-05-19T11:30:00+02:00'), + ]; + } + + private function round(IFSCEventInfo $eventInfo, string $title, string $startsAt): IFSCRound + { + $schedule = $this->scheduleFactory->create( + name: $title, + startsAt: (new DateTimeImmutable($startsAt))->setTimezone(new DateTimeZone('Europe/Madrid')), + endsAt: null, ); - foreach ($schedules as $schedule) { - $rounds[] = $this->roundFactory->create( - event: $eventInfo, - roundName: $schedule->name, - startTime: $schedule->startsAt, - endTime: $schedule->endsAt, - status: IFSCRoundStatus::PROVISIONAL, - liveStream: new LiveStream(self::OLYMPIC_QUALIFIERS_SHANGHAI_LIVE_STREAM), - ); - } + $liveStream = new LiveStream(self::OLYMPIC_QUALIFIERS_SHANGHAI_LIVE_STREAM); - return $rounds; + return $this->roundFactory->create( + event: $eventInfo, + roundName: $schedule->name, + startTime: $schedule->startsAt, + endTime: $schedule->endsAt, + status: IFSCRoundStatus::CONFIRMED, + liveStream: $liveStream, + ); } } diff --git a/tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php b/tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php index 1654e22..1b690ad 100644 --- a/tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php +++ b/tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php @@ -25,9 +25,9 @@ final class PDFScheduleProviderTest extends TestCase #[Test] public function keqiao_schedule_is_found(): void { - $schedule = $this->parseEventsFromFile('Keqiao.pdf.html', 'Asia/Shanghai'); + $schedule = $this->parseScheduleFromFile('Keqiao.pdf.html', 'Asia/Shanghai'); - $this->assertSame(6, count($schedule)); + $this->assertCount(6, $schedule); $this->assertSame("Women's Boulder Qualification", $schedule[0]->name); $this->assertSameDate("2024-04-08T09:00:00+08:00", $schedule[0]->startsAt); @@ -56,9 +56,9 @@ final class PDFScheduleProviderTest extends TestCase #[Test] public function wujiang_schedule_is_found(): void { - $schedule = $this->parseEventsFromFile('Wujiang.pdf.html', 'Asia/Shanghai'); + $schedule = $this->parseScheduleFromFile('Wujiang.pdf.html', 'Asia/Shanghai'); - $this->assertSame(5, count($schedule)); + $this->assertCount(5, $schedule); $this->assertSame("Men's & Women's Lead Qualification", $schedule[0]->name); $this->assertSameDate("2024-04-12T09:00:00+08:00", $schedule[0]->startsAt); @@ -83,9 +83,9 @@ final class PDFScheduleProviderTest extends TestCase #[Test] public function salt_lake_city_schedule_is_found(): void { - $schedule = $this->parseEventsFromFile('Salt_Lake_City.pdf.html', 'America/Phoenix'); + $schedule = $this->parseScheduleFromFile('Salt_Lake_City.pdf.html', 'America/Phoenix'); - $this->assertSame(10, count($schedule)); + $this->assertCount(10, $schedule); $this->assertSame("Men's Boulder Qualification", $schedule[0]->name); $this->assertSameDate("2024-05-03T09:00:00-07:00", $schedule[0]->startsAt); @@ -130,9 +130,9 @@ final class PDFScheduleProviderTest extends TestCase #[Test] public function innsbruck_schedule_is_found(): void { - $schedule = $this->parseEventsFromFile('Innsbruck.pdf.html', 'Europe/Vienna'); + $schedule = $this->parseScheduleFromFile('Innsbruck.pdf.html', 'Europe/Vienna'); - $this->assertSame(10, count($schedule)); + $this->assertCount(10, $schedule); $this->assertSame("Women's Boulder Qualification", $schedule[0]->name); $this->assertSameDate("2024-06-26T09:00:00+02:00", $schedule[0]->startsAt); @@ -177,9 +177,9 @@ final class PDFScheduleProviderTest extends TestCase #[Test] public function koper_schedule_is_found(): void { - $schedule = $this->parseEventsFromFile('Koper.pdf.html', 'Europe/Ljubljana'); + $schedule = $this->parseScheduleFromFile('Koper.pdf.html', 'Europe/Ljubljana'); - $this->assertSame(4, count($schedule)); + $this->assertCount(4, $schedule); $this->assertSame("Men's & Women's Lead Qualification", $schedule[0]->name); $this->assertSameDate("2024-09-06T09:00:00+02:00", $schedule[0]->startsAt); @@ -200,9 +200,9 @@ final class PDFScheduleProviderTest extends TestCase #[Test] public function chamonix_schedule_is_found(): void { - $schedule = $this->parseEventsFromFile('Chamonix.pdf.html', 'Europe/Paris'); + $schedule = $this->parseScheduleFromFile('Chamonix.pdf.html', 'Europe/Paris'); - $this->assertSame(6, count($schedule)); + $this->assertCount(6, $schedule); $this->assertSame("Men's & Women's Speed Qualification", $schedule[0]->name); $this->assertSameDate("2024-07-12T18:45:00+02:00", $schedule[0]->startsAt); @@ -231,9 +231,9 @@ final class PDFScheduleProviderTest extends TestCase #[Test] public function prague_schedule_is_found(): void { - $schedule = $this->parseEventsFromFile('Prague.pdf.html', 'Europe/Prague'); + $schedule = $this->parseScheduleFromFile('Prague.pdf.html', 'Europe/Prague'); - $this->assertSame(6, count($schedule)); + $this->assertCount(6, $schedule); $this->assertSame("Men's Boulder Qualification", $schedule[0]->name); $this->assertSameDate("2024-09-20T09:00:00+02:00", $schedule[0]->startsAt); @@ -262,9 +262,9 @@ final class PDFScheduleProviderTest extends TestCase #[Test] public function oqs_shanghai_schedule_is_found(): void { - $schedule = $this->parseEventsFromFile('OQS_Shanghai.pdf.html', 'Asia/Shanghai'); + $schedule = $this->parseScheduleFromFile('OQS_Shanghai.pdf.html', 'Asia/Shanghai'); - $this->assertSame(10, count($schedule)); + $this->assertCount(10, $schedule); $this->assertSame("Men's & Women's Boulder Qualification", $schedule[0]->name); $this->assertSameDate("2024-05-16T10:30:00+08:00", $schedule[0]->startsAt); @@ -312,16 +312,17 @@ private function assertSameDate(string $expected, DateTimeImmutable $actual): vo $this->assertSame($expected, $actual->format(\DateTimeInterface::RFC3339)); } - /** - * @return IFSCSchedule[] - * @throws Exception - */ - private function parseEventsFromFile(string $filename, string $timeZone): array + /** @return IFSCSchedule[] */ + private function parseScheduleFromFile(string $filename, string $timeZone): array { - return $this->scheduleParser->parseSchedule( - $this->loadTestFile($filename), - new DateTimeZone($timeZone), - ); + try { + return $this->scheduleParser->parseSchedule( + $this->loadTestFile($filename), + new DateTimeZone($timeZone), + ); + } catch (Exception $e) { + $this->fail($e->getMessage()); + } } private function loadTestFile(string $filename): string