4
4
5
5
namespace Boatrace \Venture \Project \Stadiums ;
6
6
7
+ use Boatrace \Venture \Project \Converter ;
8
+ use Boatrace \Venture \Project \Exceptions \AccessoryNotFoundException ;
7
9
use Carbon \CarbonImmutable as Carbon ;
10
+ use Carbon \CarbonInterface ;
8
11
9
12
/**
10
13
* @author shimomo
11
14
*/
12
15
class Stadium10 extends BaseStadium implements StadiumInterface
13
16
{
14
17
/**
15
- * @param int $raceNumber
16
- * @param string|null $date
18
+ * @param string| int $raceCode
19
+ * @param \Carbon\CarbonInterface| string|null $date
17
20
* @return array
18
21
*/
19
- public function times (int $ raceNumber , ? string $ date = null ): array
22
+ public function times (string | int $ raceCode , CarbonInterface | string | null $ date = null ): array
20
23
{
21
24
$ response = [];
22
25
23
- $ date = Carbon::parse ($ date ?? 'today ' )-> format ( ' Ymd ' );
26
+ $ carbonDate = Carbon::parse ($ date ?? 'today ' );
24
27
$ baseUrl = 'https://www.boatrace-mikuni.jp ' ;
25
28
$ 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 );
27
30
$ crawler = $ this ->httpBrowser ->request ('GET ' , $ crawlerUrl );
28
31
$ times = $ this ->filterByKeys ($ crawler , [
29
32
'.com-rname ' ,
@@ -33,67 +36,84 @@ public function times(int $raceNumber, ?string $date = null): array
33
36
'.col8 ' ,
34
37
]);
35
38
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 ;
42
51
}
43
52
44
53
return $ response ;
45
54
}
46
55
47
56
/**
48
- * @param int $raceNumber
49
- * @param string|null $date
57
+ * @param string| int $raceCode
58
+ * @param \Carbon\CarbonInterface| string|null $date
50
59
* @return array
51
60
*/
52
- public function comments (int $ raceNumber , ? string $ date = null ): array
61
+ public function comments (string | int $ raceCode , CarbonInterface | string | null $ date = null ): array
53
62
{
54
63
$ response = [];
55
64
56
- $ date = Carbon::parse ($ date ?? 'today ' )-> format ( ' Ymd ' );
65
+ $ carbonDate = Carbon::parse ($ date ?? 'today ' );
57
66
$ baseUrl = 'https://www.boatrace-mikuni.jp ' ;
58
67
$ 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 );
60
69
$ 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 );
62
78
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 ;
67
87
}
68
88
69
89
return $ response ;
70
90
}
71
91
72
92
/**
73
- * @param int $raceNumber
74
- * @param string|null $date
93
+ * @param string| int $raceCode
94
+ * @param \Carbon\CarbonInterface| string|null $date
75
95
* @return array
76
96
*/
77
- public function forecasts (int $ raceNumber , ? string $ date = null ): array
97
+ public function forecasts (string | int $ raceCode , CarbonInterface | string | null $ date = null ): array
78
98
{
79
- $ date = Carbon::parse ($ date ?? 'today ' )-> format ( ' Ymd ' );
99
+ $ carbonDate = Carbon::parse ($ date ?? 'today ' );
80
100
81
101
return array_merge (...[
82
- $ this ->fetchYesterdayForecasts ($ raceNumber , $ date ),
83
- $ this ->fetchTodayForecasts ($ raceNumber , $ date ),
102
+ $ this ->fetchYesterdayForecasts ($ raceCode , $ carbonDate ),
103
+ $ this ->fetchTodayForecasts ($ raceCode , $ carbonDate ),
84
104
]);
85
105
}
86
106
87
107
/**
88
- * @param int $raceNumber
89
- * @param string $date
108
+ * @param string| int $raceCode
109
+ * @param \Carbon\CarbonInterface $carbonDate
90
110
* @return array
91
111
*/
92
- protected function fetchYesterdayForecasts (int $ raceNumber , string $ date ): array
112
+ private function fetchYesterdayForecasts (string | int $ raceCode , CarbonInterface $ carbonDate ): array
93
113
{
94
114
$ baseUrl = 'https://www.boatrace-mikuni.jp ' ;
95
115
$ 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 );
97
117
$ crawler = $ this ->httpBrowser ->request ('GET ' , $ crawlerUrl );
98
118
$ forecasts = $ this ->filterByKeys ($ crawler , [
99
119
'.z_focus > .focus_list > li ' ,
@@ -103,18 +123,17 @@ protected function fetchYesterdayForecasts(int $raceNumber, string $date): array
103
123
104
124
foreach ($ forecasts as $ key => $ value ) {
105
125
if (empty ($ value )) {
106
- throw new \ Boatrace \ Venture \ Project \ Exceptions \ AccessoryNotFoundException (
126
+ throw new AccessoryNotFoundException (
107
127
'No data found for key \'' . $ key . '\' at \'' . $ crawlerUrl . '\'. '
108
128
);
109
129
}
110
130
}
111
131
112
132
$ reporterYesterdayFocusLabel = '記者予想 前日フォーカス ' ;
113
- $ jlcYesterdayFocusLabel = 'JLC予想 前日フォーカス ' ;
114
- $ jlcYesterdayReliabilityLabel = 'JLC予想 前日信頼度 ' ;
115
-
116
133
$ reporterYesterdayFocus = $ this ->normalizeArray ($ forecasts ['.z_focus > .focus_list > li ' ]);
134
+ $ jlcYesterdayFocusLabel = 'JLC予想 前日フォーカス ' ;
117
135
$ jlcYesterdayFocus = $ this ->normalizeArray ($ forecasts ['.j_focus > .focus_list > li ' ]);
136
+ $ jlcYesterdayReliabilityLabel = 'JLC予想 前日信頼度 ' ;
118
137
$ jlcYesterdayReliability = $ this ->normalize ($ forecasts ['.j_reliability ' ][0 ]);
119
138
120
139
return [
@@ -128,15 +147,15 @@ protected function fetchYesterdayForecasts(int $raceNumber, string $date): array
128
147
}
129
148
130
149
/**
131
- * @param int $raceNumber
132
- * @param string $date
150
+ * @param string| int $raceCode
151
+ * @param \Carbon\CarbonInterface $carbonDate
133
152
* @return array
134
153
*/
135
- protected function fetchTodayForecasts (int $ raceNumber , string $ date ): array
154
+ private function fetchTodayForecasts (string | int $ raceCode , CarbonInterface $ carbonDate ): array
136
155
{
137
156
$ baseUrl = 'https://www.boatrace-mikuni.jp ' ;
138
157
$ 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 );
140
159
$ crawler = $ this ->httpBrowser ->request ('GET ' , $ crawlerUrl );
141
160
$ forecasts = $ this ->filterByKeys ($ crawler , [
142
161
'.cyosou_cmt ' ,
@@ -145,16 +164,15 @@ protected function fetchTodayForecasts(int $raceNumber, string $date): array
145
164
146
165
foreach ($ forecasts as $ key => $ value ) {
147
166
if (empty ($ value )) {
148
- throw new \ Boatrace \ Venture \ Project \ Exceptions \ AccessoryNotFoundException (
167
+ throw new AccessoryNotFoundException (
149
168
'No data found for key \'' . $ key . '\' at \'' . $ crawlerUrl . '\'. '
150
169
);
151
170
}
152
171
}
153
172
154
173
$ reporterTodayCommentLabel = '記者予想 当日コメント ' ;
155
- $ reporterTodayFocusLabel = '記者予想 当日フォーカス ' ;
156
-
157
174
$ reporterTodayComment = $ this ->normalize ($ forecasts ['.cyosou_cmt ' ][0 ]);
175
+ $ reporterTodayFocusLabel = '記者予想 当日フォーカス ' ;
158
176
$ reporterTodayFocus = array_values (array_filter ($ this ->normalizeArray (
159
177
preg_split ('/\s+/u ' , str_replace ('<フォーカス> ' , '' , $ forecasts ['.cyosou_focus ' ][0 ]))
160
178
)));
0 commit comments