-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclassics.php
88 lines (71 loc) · 2.66 KB
/
classics.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types = 1);
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;
define('RACE_ID', 227);
require_once('vendor/autoload.php');
require_once('ProCyclingStatsFetcher.php');
require_once('ScoritoFormatter.php');
$scorito = new ScoritoClassicsGame(
RACE_ID,
[
'Omloop Het Nieuwsblad Elite',
'Kuurne - Bruxelles - Kuurne',
'Strade Bianche',
// 'Milano - Torino',
'Milano-Sanremo',
'Classic Brugge-De Panne',
'E3 Saxo Classic',
'Gent-Wevelgem in Flanders Fields',
'Dwars door Vlaanderen - A travers la Flandre',
'Ronde van Vlaanderen - Tour des Flandres',
'Scheldeprijs',
'Amstel Gold Race',
'Paris-Roubaix',
'De Brabantse Pijl - La Flèche Brabançonne',
'La Flèche Wallonne',
'Liège-Bastogne-Liège',
'Eschborn-Frankfurt',
]
);
$scoritoData = $scorito->fetch();
$out = fopen('classics.csv', 'w');
fputcsv($out, array_keys($scoritoData[0]));
foreach ($scoritoData as $row) {
fputcsv($out, array_map(function ($col) {
if (is_array($col)) {
return print_r($col, true);
}
return $col;
}, $row));
}
fclose($out);
class ScoritoClassicsGame {
private HttpClientInterface $client;
private int $raceId;
private ProCyclingStatsFetcher $fetcher;
public function __construct(int $raceId, array $filterRaces)
{
$this->raceId = $raceId;
$this->client = HttpClient::create();
$this->fetcher = new ProCyclingStatsFetcher($this->client, $filterRaces);
}
public function fetchTeams(): array
{
$response = $this->client->request('GET', 'https://cycling.scorito.com/cycling/v2.0/team');
$scoritoData = $response->toArray();
return $scoritoData['Content'];
}
public function fetch(): array
{
$response = $this->client->request('GET', 'https://cycling.scorito.com/cyclingteammanager/v2.0/marketrider/' . $this->raceId);
$scoritoData = $response->toArray();
$teams = $this->fetchTeams();
$filtered = $scoritoData['Content'];
$filtered = array_map(['ScoritoFormatter', 'formatQualities'], $filtered);
$filtered = array_map(['ScoritoFormatter', 'formatType'], $filtered);
$filtered = array_map(fn (array $rider) => ScoritoFormatter::formatTeam($rider, $teams), $filtered);
$filtered = array_map(['ScoritoFormatter', 'filterColumns'], $filtered);
return $this->fetcher->fetchRiders($filtered, true, true, true);
}
}