Skip to content

Commit

Permalink
Fix oqs streams (#21)
Browse files Browse the repository at this point in the history
* Fix OQS live streams and schedule

* Hardcode OQS schedule
  • Loading branch information
nicoSWD authored May 18, 2024
1 parent 6d417a5 commit 7bfde8d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 46 deletions.
2 changes: 1 addition & 1 deletion config/services/domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 43 additions & 20 deletions src/Domain/Calendar/PostProcess/Season2024PostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@
*/
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
{
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,
) {
}
/**
Expand Down Expand Up @@ -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,
);
}
}
51 changes: 26 additions & 25 deletions tests/unit/Infrastructure/Schedule/PDFScheduleProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7bfde8d

Please sign in to comment.