Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 799f362

Browse files
committed
Wip
1 parent 938905c commit 799f362

File tree

9 files changed

+189
-169
lines changed

9 files changed

+189
-169
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Accessory in the Boatrace Venture Project
1+
# Accessory
22

33
[![Build Status](https://github.com/BoatraceVentureProject/Accessory/workflows/Tests/badge.svg)](https://github.com/BoatraceVentureProject/Accessory/actions?query=workflow%3Atests)
44
[![codecov](https://codecov.io/gh/BoatraceVentureProject/Accessory/graph/badge.svg?token=G22GRD1CUF)](https://codecov.io/gh/BoatraceVentureProject/Accessory)

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"symfony/browser-kit": "^6.0 || ^7.0",
1919
"symfony/css-selector": "^6.0 || ^7.0",
2020
"symfony/http-client": "^6.0 || ^7.0",
21-
"symfony/mime": "^6.0 || ^7.0"
21+
"symfony/mime": "^6.0 || ^7.0",
22+
"bvp/converter": "^1.0"
2223
},
2324
"require-dev": {
2425
"phpunit/phpunit": "^10.1"

src/Accessory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class Accessory
2525
protected static Container $container;
2626

2727
/**
28-
* @param \Boatrace\Venture\Project\MainAccessory $accessory
28+
* @param \Boatrace\Venture\Project\AccessoryCore $accessory
2929
*/
30-
public function __construct(protected MainAccessory $accessory){}
30+
public function __construct(private readonly AccessoryCore $accessory) {}
3131

3232
/**
3333
* @param string $name

src/MainAccessory.php renamed to src/AccessoryCore.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
/**
1010
* @author shimomo
1111
*/
12-
class MainAccessory
12+
class AccessoryCore
1313
{
1414
/**
1515
* @return void
1616
*/
1717
public function __construct()
1818
{
19-
Collection::macro('recursive', fn() => $this->map(fn($value) =>
20-
is_array($value) || is_object($value)
19+
Collection::macro('recursive', fn() => $this->map(
20+
fn($value) => is_array($value) || is_object($value)
2121
? collect($value)->recursive()
2222
: $value
2323
));

src/Stadiums/BaseStadium.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
abstract class BaseStadium
1414
{
1515
/**
16-
* @param \Symfony\Component\BrowserKit\HttpBrowser $httpBrowser
16+
* @param \Symfony\Component\BrowserKit\HttpBrowser $httpBrowser
17+
* @return void
1718
*/
18-
public function __construct(protected HttpBrowser $httpBrowser){}
19+
public function __construct(protected readonly HttpBrowser $httpBrowser) {}
1920

2021
/**
2122
* @param \Symfony\Component\DomCrawler\Crawler $crawler

src/Stadiums/Stadium05.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public function times(int $raceNumber, ?string $date = null): array
3434
'.col9',
3535
]);
3636

37-
foreach (range(1, 6) as $bracket) {
38-
$response['bracket_' . $bracket . '_racer_name'] = $this->removeSpace($times['.com-rname'][$bracket - 1] ?? '');
39-
$response['bracket_' . $bracket . '_exhibition_time'] = (float) ($times['.col6'][$bracket] ?? 0);
40-
$response['bracket_' . $bracket . '_lap_time'] = (float) ($times['.col7'][$bracket] ?? 0);
41-
$response['bracket_' . $bracket . '_turn_time'] = (float) ($times['.col8'][$bracket] ?? 0);
42-
$response['bracket_' . $bracket . '_straight_time'] = (float) ($times['.col9'][$bracket] ?? 0);
37+
foreach (range(1, 6) as $boat_number) {
38+
$response['boat_number_' . $boat_number . '_racer_name'] = $this->removeSpace($times['.com-rname'][$boat_number - 1] ?? '');
39+
$response['boat_number_' . $boat_number . '_exhibition_time'] = (float) ($times['.col6'][$boat_number] ?? 0);
40+
$response['boat_number_' . $boat_number . '_lap_time'] = (float) ($times['.col7'][$boat_number] ?? 0);
41+
$response['boat_number_' . $boat_number . '_turn_time'] = (float) ($times['.col8'][$boat_number] ?? 0);
42+
$response['boat_number_' . $boat_number . '_straight_time'] = (float) ($times['.col9'][$boat_number] ?? 0);
4343
}
4444

4545
return $response;

src/Stadiums/Stadium10.php

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@
44

55
namespace Boatrace\Venture\Project\Stadiums;
66

7+
use Boatrace\Venture\Project\Converter;
8+
use Boatrace\Venture\Project\Exceptions\AccessoryNotFoundException;
79
use Carbon\CarbonImmutable as Carbon;
10+
use Carbon\CarbonInterface;
811

912
/**
1013
* @author shimomo
1114
*/
1215
class Stadium10 extends BaseStadium implements StadiumInterface
1316
{
1417
/**
15-
* @param int $raceNumber
16-
* @param string|null $date
18+
* @param string|int $raceCode
19+
* @param \Carbon\CarbonInterface|string|null $date
1720
* @return array
1821
*/
19-
public function times(int $raceNumber, ?string $date = null): array
22+
public function times(string|int $raceCode, CarbonInterface|string|null $date = null): array
2023
{
2124
$response = [];
2225

23-
$date = Carbon::parse($date ?? 'today')->format('Ymd');
26+
$carbonDate = Carbon::parse($date ?? 'today');
2427
$baseUrl = 'https://www.boatrace-mikuni.jp';
2528
$crawlerFormat = '%s/modules/yosou/group-cyokuzen.php?day=%s&race=%d&kind=2&if=1';
26-
$crawlerUrl = sprintf($crawlerFormat, $baseUrl, $date, $raceNumber);
29+
$crawlerUrl = sprintf($crawlerFormat, $baseUrl, $carbonDate->format('Ymd'), $raceCode);
2730
$crawler = $this->httpBrowser->request('GET', $crawlerUrl);
2831
$times = $this->filterByKeys($crawler, [
2932
'.com-rname',
@@ -33,67 +36,84 @@ public function times(int $raceNumber, ?string $date = null): array
3336
'.col8',
3437
]);
3538

36-
foreach (range(1, 6) as $bracket) {
37-
$response['bracket_' . $bracket . '_racer_name'] = $this->removeSpace($times['.com-rname'][$bracket - 1] ?? '');
38-
$response['bracket_' . $bracket . '_exhibition_time'] = (float) ($times['.col5'][$bracket] ?? 0);
39-
$response['bracket_' . $bracket . '_lap_time'] = (float) ($times['.col6'][$bracket] ?? 0);
40-
$response['bracket_' . $bracket . '_turn_time'] = (float) ($times['.col7'][$bracket] ?? 0);
41-
$response['bracket_' . $bracket . '_straight_time'] = (float) ($times['.col8'][$bracket] ?? 0);
39+
foreach (range(1, 6) as $boatNumber) {
40+
$racerName = $this->removeSpace($times['.com-rname'][$boatNumber - 1] ?? '');
41+
$racerExhibitionTime = Converter::float($times['.col5'][$boatNumber] ?? 0.0);
42+
$racerLapTime = Converter::float($times['.col6'][$boatNumber] ?? 0.0);
43+
$racerTurnTime = Converter::float($times['.col7'][$boatNumber] ?? 0.0);
44+
$racerStraightTime = Converter::float($times['.col8'][$boatNumber] ?? 0.0);
45+
46+
$response['boat_number_' . $boatNumber . '_racer_name'] = $racerName;
47+
$response['boat_number_' . $boatNumber . '_racer_exhibition_time'] = $racerExhibitionTime;
48+
$response['boat_number_' . $boatNumber . '_racer_lap_time'] = $racerLapTime;
49+
$response['boat_number_' . $boatNumber . '_racer_turn_time'] = $racerTurnTime;
50+
$response['boat_number_' . $boatNumber . '_racer_straight_time'] = $racerStraightTime;
4251
}
4352

4453
return $response;
4554
}
4655

4756
/**
48-
* @param int $raceNumber
49-
* @param string|null $date
57+
* @param string|int $raceCode
58+
* @param \Carbon\CarbonInterface|string|null $date
5059
* @return array
5160
*/
52-
public function comments(int $raceNumber, ?string $date = null): array
61+
public function comments(string|int $raceCode, CarbonInterface|string|null $date = null): array
5362
{
5463
$response = [];
5564

56-
$date = Carbon::parse($date ?? 'today')->format('Ymd');
65+
$carbonDate = Carbon::parse($date ?? 'today');
5766
$baseUrl = 'https://www.boatrace-mikuni.jp';
5867
$crawlerFormat = '%s/modules/yosou/group-syussou.php?day=%s&race=%d&if=1';
59-
$crawlerUrl = sprintf($crawlerFormat, $baseUrl, $date, $raceNumber);
68+
$crawlerUrl = sprintf($crawlerFormat, $baseUrl, $carbonDate->format('Ymd'), $raceCode);
6069
$crawler = $this->httpBrowser->request('GET', $crawlerUrl);
61-
$comments = $this->filterByKeys($crawler, ['.com-rname', '.col10']);
70+
$comments = $this->filterByKeys($crawler, [
71+
'.com-rname',
72+
'.col10',
73+
]);
74+
75+
foreach (range(1, 6) as $boatNumber) {
76+
$racerName = $comments['.com-rname'][$boatNumber - 1];
77+
$racerName = $this->removeSpace($racerName);
6278

63-
foreach (range(1, 6) as $bracket) {
64-
$response['bracket_' . $bracket . '_racer_name'] = $this->removeSpace($comments['.com-rname'][$bracket - 1]);
65-
$response['bracket_' . $bracket . '_racer_comment_1_label'] = '前日コメント';
66-
$response['bracket_' . $bracket . '_racer_comment_1'] = $this->normalize(preg_split('/過去コメント/u', $comments['.col10'][$bracket])[0] ?? '');
79+
$racerYesterdayCommentLabel = '前日コメント';
80+
$racerYesterdayComment = $comments['.col10'][$boatNumber];
81+
$racerYesterdayComment = preg_split('/過去コメント/u', $racerYesterdayComment);
82+
$racerYesterdayComment = $this->normalize($racerYesterdayComment[0] ?? '');
83+
84+
$response['boat_number_' . $boatNumber . '_racer_name'] = $racerName;
85+
$response['boat_number_' . $boatNumber . '_racer_yesterday_comment_label'] = $racerYesterdayCommentLabel;
86+
$response['boat_number_' . $boatNumber . '_racer_yesterday_comment'] = $racerYesterdayComment;
6787
}
6888

6989
return $response;
7090
}
7191

7292
/**
73-
* @param int $raceNumber
74-
* @param string|null $date
93+
* @param string|int $raceCode
94+
* @param \Carbon\CarbonInterface|string|null $date
7595
* @return array
7696
*/
77-
public function forecasts(int $raceNumber, ?string $date = null): array
97+
public function forecasts(string|int $raceCode, CarbonInterface|string|null $date = null): array
7898
{
79-
$date = Carbon::parse($date ?? 'today')->format('Ymd');
99+
$carbonDate = Carbon::parse($date ?? 'today');
80100

81101
return array_merge(...[
82-
$this->fetchYesterdayForecasts($raceNumber, $date),
83-
$this->fetchTodayForecasts($raceNumber, $date),
102+
$this->fetchYesterdayForecasts($raceCode, $carbonDate),
103+
$this->fetchTodayForecasts($raceCode, $carbonDate),
84104
]);
85105
}
86106

87107
/**
88-
* @param int $raceNumber
89-
* @param string $date
108+
* @param string|int $raceCode
109+
* @param \Carbon\CarbonInterface $carbonDate
90110
* @return array
91111
*/
92-
protected function fetchYesterdayForecasts(int $raceNumber, string $date): array
112+
private function fetchYesterdayForecasts(string|int $raceCode, CarbonInterface $carbonDate): array
93113
{
94114
$baseUrl = 'https://www.boatrace-mikuni.jp';
95115
$crawlerFormat = '%s/modules/yosou/group-syussou.php?day=%s&race=%d';
96-
$crawlerUrl = sprintf($crawlerFormat, $baseUrl, $date, $raceNumber);
116+
$crawlerUrl = sprintf($crawlerFormat, $baseUrl, $carbonDate->format('Ymd'), $raceCode);
97117
$crawler = $this->httpBrowser->request('GET', $crawlerUrl);
98118
$forecasts = $this->filterByKeys($crawler, [
99119
'.z_focus > .focus_list > li',
@@ -103,18 +123,17 @@ protected function fetchYesterdayForecasts(int $raceNumber, string $date): array
103123

104124
foreach ($forecasts as $key => $value) {
105125
if (empty($value)) {
106-
throw new \Boatrace\Venture\Project\Exceptions\AccessoryNotFoundException(
126+
throw new AccessoryNotFoundException(
107127
'No data found for key \'' . $key . '\' at \'' . $crawlerUrl . '\'.'
108128
);
109129
}
110130
}
111131

112132
$reporterYesterdayFocusLabel = '記者予想 前日フォーカス';
113-
$jlcYesterdayFocusLabel = 'JLC予想 前日フォーカス';
114-
$jlcYesterdayReliabilityLabel = 'JLC予想 前日信頼度';
115-
116133
$reporterYesterdayFocus = $this->normalizeArray($forecasts['.z_focus > .focus_list > li']);
134+
$jlcYesterdayFocusLabel = 'JLC予想 前日フォーカス';
117135
$jlcYesterdayFocus = $this->normalizeArray($forecasts['.j_focus > .focus_list > li']);
136+
$jlcYesterdayReliabilityLabel = 'JLC予想 前日信頼度';
118137
$jlcYesterdayReliability = $this->normalize($forecasts['.j_reliability'][0]);
119138

120139
return [
@@ -128,15 +147,15 @@ protected function fetchYesterdayForecasts(int $raceNumber, string $date): array
128147
}
129148

130149
/**
131-
* @param int $raceNumber
132-
* @param string $date
150+
* @param string|int $raceCode
151+
* @param \Carbon\CarbonInterface $carbonDate
133152
* @return array
134153
*/
135-
protected function fetchTodayForecasts(int $raceNumber, string $date): array
154+
private function fetchTodayForecasts(string|int $raceCode, CarbonInterface $carbonDate): array
136155
{
137156
$baseUrl = 'https://www.boatrace-mikuni.jp';
138157
$crawlerFormat = '%s/modules/yosou/group-cyokuzen.php?day=%s&race=%d';
139-
$crawlerUrl = sprintf($crawlerFormat, $baseUrl, $date, $raceNumber);
158+
$crawlerUrl = sprintf($crawlerFormat, $baseUrl, $carbonDate->format('Ymd'), $raceCode);
140159
$crawler = $this->httpBrowser->request('GET', $crawlerUrl);
141160
$forecasts = $this->filterByKeys($crawler, [
142161
'.cyosou_cmt',
@@ -145,16 +164,15 @@ protected function fetchTodayForecasts(int $raceNumber, string $date): array
145164

146165
foreach ($forecasts as $key => $value) {
147166
if (empty($value)) {
148-
throw new \Boatrace\Venture\Project\Exceptions\AccessoryNotFoundException(
167+
throw new AccessoryNotFoundException(
149168
'No data found for key \'' . $key . '\' at \'' . $crawlerUrl . '\'.'
150169
);
151170
}
152171
}
153172

154173
$reporterTodayCommentLabel = '記者予想 当日コメント';
155-
$reporterTodayFocusLabel = '記者予想 当日フォーカス';
156-
157174
$reporterTodayComment = $this->normalize($forecasts['.cyosou_cmt'][0]);
175+
$reporterTodayFocusLabel = '記者予想 当日フォーカス';
158176
$reporterTodayFocus = array_values(array_filter($this->normalizeArray(
159177
preg_split('/\s+/u', str_replace('<フォーカス>', '', $forecasts['.cyosou_focus'][0]))
160178
)));

src/Stadiums/Stadium24.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ public function comments(int $raceNumber, ?string $date = null): array
7171
foreach (range(1, 6) as $bracket) {
7272
$pattern = '/(.+)(\(当日気配\).+)/u';
7373
$subject = $comments['.tei' . $bracket][2] ?? '';
74-
preg_match($pattern, $subject, $matches);
75-
76-
if (count($matches) === 0) {
74+
if (!preg_match($pattern, $subject, $matches)) {
7775
$matches[1] = $subject;
7876
}
7977

80-
$response['bracket_' . $bracket . '_racer_name'] = $this->removeSpace($comments['.tei' . $bracket][1] ?? '');
78+
$racerName = $comments['.tei' . $bracket][1] ?? '';
79+
80+
$response['bracket_' . $bracket . '_racer_name'] = $this->removeSpace($racerName);
8181
$response['bracket_' . $bracket . '_racer_comment_1_label'] = '前日コメント';
8282
$response['bracket_' . $bracket . '_racer_comment_1'] = $this->normalize($matches[1]);
8383

0 commit comments

Comments
 (0)