-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Guess end time base on YouTube's start time if times mismatch * Guess end time based on the average of past events
- Loading branch information
Showing
12 changed files
with
379 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env php | ||
<?php declare(strict_types=1); | ||
|
||
use nicoSWD\IfscCalendar\Domain\Event\IFSCEventTagsRegex as Tag; | ||
use nicoSWD\IfscCalendar\Domain\Tags\IFSCTagsParser; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$videos = json_decode( | ||
file_get_contents(__DIR__ . '/../vendor/sportclimbing/ifsc-youtube-videos/data/videos.json') | ||
); | ||
|
||
$tagsParser = new IFSCTagsParser(); | ||
|
||
function cache_key(array $tags): string | ||
{ | ||
$key = []; | ||
|
||
foreach ($tags as $tag) { | ||
$key[] = $tag->name; | ||
} | ||
|
||
sort($key); | ||
|
||
return strtolower(implode('_', $key)); | ||
} | ||
|
||
$videoDurations = []; | ||
|
||
foreach ($videos as $video) { | ||
$tags = $tagsParser->fromString($video->title); | ||
|
||
if (!$tags->hasTag(Tag::WOMEN) && !$tags->hasTag(Tag::MEN)) { | ||
$videoTags = [Tag::WOMEN, Tag::MEN, ...$tags->allTags()]; | ||
} else { | ||
$videoTags = $tags->allTags(); | ||
} | ||
|
||
$videoDurations[cache_key($videoTags)][] = $video->duration; | ||
} | ||
|
||
$results = []; | ||
|
||
foreach ($videoDurations as $key => $minutes) { | ||
$averageDuration = (int) floor(array_sum($minutes) / count($minutes)); | ||
$averageDuration -= ($averageDuration % 30); | ||
|
||
if ($averageDuration > 30) { | ||
$results[$key] = $averageDuration; | ||
} | ||
} | ||
|
||
ksort($results); | ||
var_export($results); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* @license http://opensource.org/licenses/mit-license.php MIT | ||
* @link https://github.com/nicoSWD | ||
* @author Nicolas Oelgart <nico@oelgart.com> | ||
*/ | ||
namespace nicoSWD\IfscCalendar\Domain\Round; | ||
|
||
use nicoSWD\IfscCalendar\Domain\Event\IFSCEventTagsRegex as Tag; | ||
|
||
final readonly class IFSCAverageRoundDuration | ||
{ | ||
private const int DEFAULT_ROUND_DURATION = 90; | ||
|
||
// Run `bin/avg-round-duration` to generate an updated list | ||
private const array AVERAGE_DURATIONS = [ | ||
'boulder_combined_men_qualification' => 120, | ||
'boulder_combined_men_qualification_women' => 120, | ||
'boulder_combined_qualification_women' => 120, | ||
'boulder_final_lead_men' => 180, | ||
'boulder_final_lead_men_semi_final_women' => 360, | ||
'boulder_final_lead_men_women' => 240, | ||
'boulder_final_lead_women' => 180, | ||
'boulder_final_men' => 120, | ||
'boulder_final_men_paraclimbing' => 150, | ||
'boulder_final_men_women' => 180, | ||
'boulder_final_women' => 120, | ||
'boulder_lead_men_semi_final' => 180, | ||
'boulder_lead_men_semi_final_women' => 120, | ||
'boulder_lead_semi_final_women' => 90, | ||
'boulder_men_semi_final' => 120, | ||
'boulder_men_semi_final_women' => 120, | ||
'boulder_semi_final_women' => 120, | ||
'combined_final_men' => 240, | ||
'combined_final_men_women' => 420, | ||
'combined_final_women' => 240, | ||
'combined_lead_men_qualification' => 90, | ||
'combined_lead_men_qualification_women' => 90, | ||
'combined_lead_qualification_women' => 120, | ||
'combined_men_qualification_speed_women' => 60, | ||
'final_lead_men' => 60, | ||
'final_lead_men_women' => 120, | ||
'final_lead_women' => 120, | ||
'final_men_paraclimbing_women' => 210, | ||
'final_men_speed_women' => 90, | ||
'final_speed_women' => 60, | ||
'lead_men_semi_final' => 120, | ||
'lead_men_semi_final_women' => 150, | ||
'lead_semi_final_women' => 210, | ||
'men_paraclimbing_women' => 120, | ||
'men_qualification_speed' => 60, | ||
'men_qualification_speed_women' => 90, | ||
]; | ||
|
||
/** @param Tag[] $tags */ | ||
public function fromTags(array $tags): int | ||
{ | ||
return self::AVERAGE_DURATIONS[$this->lookupKey($tags)] | ||
?? self::DEFAULT_ROUND_DURATION; | ||
} | ||
|
||
/** @param Tag[] $tags */ | ||
private function lookupKey(array $tags): string | ||
{ | ||
$tags = array_map( | ||
static fn (Tag $tag): string => $tag->name, | ||
$tags, | ||
); | ||
|
||
sort($tags); | ||
|
||
return strtolower( | ||
implode('_', $tags), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/** | ||
* @license http://opensource.org/licenses/mit-license.php MIT | ||
* @link https://github.com/nicoSWD | ||
* @author Nicolas Oelgart <nico@oelgart.com> | ||
*/ | ||
namespace nicoSWD\IfscCalendar\Domain\YouTube; | ||
|
||
use nicoSWD\IfscCalendar\Domain\Event\Info\IFSCEventInfo; | ||
use nicoSWD\IfscCalendar\Domain\Stream\LiveStream; | ||
|
||
interface YouTubeLiveStreamFinderInterface | ||
{ | ||
public function findLiveStream(IFSCEventInfo $event, string $roundName): LiveStream; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.