@@ -6,7 +6,7 @@ |
||
6 | 6 | "services" => [ |
7 | 7 | "url" => [ |
8 | 8 | "shared" => true, |
9 | - "callback" => function () { |
|
9 | + "callback" => function() { |
|
10 | 10 | $forecaster = new \Anax\Models\Forecaster(); |
11 | 11 | |
12 | 12 | $cfg = $di->get("configuration"); |
@@ -19,14 +19,14 @@ discard block |
||
19 | 19 | // protected $weatherDesc = ""; |
20 | 20 | protected $todaysWeather = array(); |
21 | 21 | |
22 | - protected $dailyDate = []; |
|
23 | - protected $dailyDesc = []; |
|
24 | - protected $dailyTemp = []; |
|
25 | - protected $dailyWind = []; |
|
26 | - protected $historicalDate = []; |
|
27 | - protected $historicalDesc = []; |
|
28 | - protected $historicalTemp = []; |
|
29 | - protected $historicalWind = []; |
|
22 | + protected $dailyDate = [ ]; |
|
23 | + protected $dailyDesc = [ ]; |
|
24 | + protected $dailyTemp = [ ]; |
|
25 | + protected $dailyWind = [ ]; |
|
26 | + protected $historicalDate = [ ]; |
|
27 | + protected $historicalDesc = [ ]; |
|
28 | + protected $historicalTemp = [ ]; |
|
29 | + protected $historicalWind = [ ]; |
|
30 | 30 | |
31 | 31 | // ACTUAL USEFUL FUNCS |
32 | 32 | |
@@ -43,25 +43,25 @@ discard block |
||
43 | 43 | |
44 | 44 | // Fetching epoch times for last 5 days |
45 | 45 | $epochDays = array(); |
46 | - $epochDays[0] = strtotime("-5 days"); |
|
47 | - $epochDays[1] = strtotime("-4 days"); |
|
48 | - $epochDays[2] = strtotime("-3 days"); |
|
49 | - $epochDays[3] = strtotime("-2 days"); |
|
50 | - $epochDays[4] = strtotime("-1 days"); |
|
46 | + $epochDays[ 0 ] = strtotime("-5 days"); |
|
47 | + $epochDays[ 1 ] = strtotime("-4 days"); |
|
48 | + $epochDays[ 2 ] = strtotime("-3 days"); |
|
49 | + $epochDays[ 3 ] = strtotime("-2 days"); |
|
50 | + $epochDays[ 4 ] = strtotime("-1 days"); |
|
51 | 51 | |
52 | 52 | $url1 = "https://api.openweathermap.org/data/2.5/onecall?" |
53 | - . "lat=" . $inputLat . "&lon=" . $inputLong |
|
53 | + . "lat=".$inputLat."&lon=".$inputLong |
|
54 | 54 | . "&exclude=minutely,hourly,alerts&" |
55 | - . "appid=" . $owmApiKey |
|
55 | + . "appid=".$owmApiKey |
|
56 | 56 | . "&units=metric&lang=se"; |
57 | 57 | |
58 | 58 | //Creating URLs for historical data |
59 | 59 | $historicalUrls = array(); |
60 | 60 | for ($i = 0; $i < 5; $i++) { |
61 | - $historicalUrls[$i] = "https://api.openweathermap.org/data/2.5/onecall/timemachine?" |
|
62 | - . "lat=" . $inputLat . "&lon=" . $inputLong |
|
63 | - . "&dt=" . $epochDays[$i] |
|
64 | - . "&appid=" . $owmApiKey |
|
61 | + $historicalUrls[ $i ] = "https://api.openweathermap.org/data/2.5/onecall/timemachine?" |
|
62 | + . "lat=".$inputLat."&lon=".$inputLong |
|
63 | + . "&dt=".$epochDays[ $i ] |
|
64 | + . "&appid=".$owmApiKey |
|
65 | 65 | . "&units=metric&lang=se"; |
66 | 66 | } |
67 | 67 | |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | $running = 0; |
76 | 76 | |
77 | 77 | for ($i = 0; $i < $urlCount; $i++) { |
78 | - $url =$urls[$i]; |
|
79 | - $responseArr[$i] = curl_init($url); |
|
80 | - curl_setopt($responseArr[$i], CURLOPT_RETURNTRANSFER, true); |
|
81 | - curl_multi_add_handle($master, $responseArr[$i]); |
|
78 | + $url = $urls[ $i ]; |
|
79 | + $responseArr[ $i ] = curl_init($url); |
|
80 | + curl_setopt($responseArr[ $i ], CURLOPT_RETURNTRANSFER, true); |
|
81 | + curl_multi_add_handle($master, $responseArr[ $i ]); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | do { |
@@ -87,20 +87,20 @@ discard block |
||
87 | 87 | |
88 | 88 | $results = array(); |
89 | 89 | for ($i = 0; $i < $urlCount; $i++) { |
90 | - $results[$i] = curl_multi_getcontent($responseArr[$i]); |
|
91 | - $results[$i] = json_decode($results[$i]); |
|
90 | + $results[ $i ] = curl_multi_getcontent($responseArr[ $i ]); |
|
91 | + $results[ $i ] = json_decode($results[ $i ]); |
|
92 | 92 | } |
93 | 93 | |
94 | - if (isset($results[0])) { |
|
94 | + if (isset($results[ 0 ])) { |
|
95 | 95 | // Handle response for request 1 |
96 | 96 | |
97 | 97 | // Current weather |
98 | - $this->todaysWeather["temperature"] = @$results[0]->current->temp; |
|
99 | - $this->todaysWeather["feelsLike"] = @$results[0]->current->feels_like; |
|
100 | - $this->todaysWeather["windSpeed"] = @$results[0]->current->wind_speed; |
|
98 | + $this->todaysWeather[ "temperature" ] = @$results[ 0 ]->current->temp; |
|
99 | + $this->todaysWeather[ "feelsLike" ] = @$results[ 0 ]->current->feels_like; |
|
100 | + $this->todaysWeather[ "windSpeed" ] = @$results[ 0 ]->current->wind_speed; |
|
101 | 101 | |
102 | - $this->todaysWeather["weatherMain"] = @$results[0]->current->weather[0]->main; |
|
103 | - $this->todaysWeather["weatherDesc"] = @$results[0]->current->weather[0]->description; |
|
102 | + $this->todaysWeather[ "weatherMain" ] = @$results[ 0 ]->current->weather[ 0 ]->main; |
|
103 | + $this->todaysWeather[ "weatherDesc" ] = @$results[ 0 ]->current->weather[ 0 ]->description; |
|
104 | 104 | // $this->temperature = @$results[0]->current->temp; |
105 | 105 | // $this->feelsLike = @$results[0]->current->feels_like; |
106 | 106 | // $this->windSpeed = @$results[0]->current->wind_speed; |
@@ -109,21 +109,21 @@ discard block |
||
109 | 109 | // $this->weatherDesc = @$results[0]->current->weather[0]->description; |
110 | 110 | |
111 | 111 | // Weather next 7 days |
112 | - $dailySize = @sizeof($results[0]->daily); |
|
112 | + $dailySize = @sizeof($results[ 0 ]->daily); |
|
113 | 113 | for ($i = 1; $i < @$dailySize; $i++) { |
114 | - $this->dailyDate[$i] = $results[0]->daily[$i]->dt; |
|
115 | - $this->dailyDesc[$i] = $results[0]->daily[$i]->weather[0]->description; |
|
116 | - $this->dailyTemp[$i] = $results[0]->daily[$i]->temp->day; |
|
117 | - $this->dailyWind[$i] = $results[0]->daily[$i]->wind_speed; |
|
114 | + $this->dailyDate[ $i ] = $results[ 0 ]->daily[ $i ]->dt; |
|
115 | + $this->dailyDesc[ $i ] = $results[ 0 ]->daily[ $i ]->weather[ 0 ]->description; |
|
116 | + $this->dailyTemp[ $i ] = $results[ 0 ]->daily[ $i ]->temp->day; |
|
117 | + $this->dailyWind[ $i ] = $results[ 0 ]->daily[ $i ]->wind_speed; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // Weather last 5 days |
121 | 121 | $resultSize = sizeof($results); |
122 | 122 | for ($i = 1; $i < $resultSize; $i++) { |
123 | - $this->historicalDate[$i] = @$results[$i]->current->dt; |
|
124 | - $this->historicalDesc[$i] = @$results[$i]->current->weather[0]->description; |
|
125 | - $this->historicalTemp[$i] = @$results[$i]->current->temp; |
|
126 | - $this->historicalWind[$i] = @$results[$i]->current->wind_speed; |
|
123 | + $this->historicalDate[ $i ] = @$results[ $i ]->current->dt; |
|
124 | + $this->historicalDesc[ $i ] = @$results[ $i ]->current->weather[ 0 ]->description; |
|
125 | + $this->historicalTemp[ $i ] = @$results[ $i ]->current->temp; |
|
126 | + $this->historicalWind[ $i ] = @$results[ $i ]->current->wind_speed; |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | } |
@@ -131,21 +131,21 @@ discard block |
||
131 | 131 | |
132 | 132 | public function buildWeatherHtml() |
133 | 133 | { |
134 | - if (isset($this->todaysWeather["temperature"])) { |
|
134 | + if (isset($this->todaysWeather[ "temperature" ])) { |
|
135 | 135 | $geoapifyApiKey = $this->geoApiKey; |
136 | 136 | |
137 | 137 | // Weather right now |
138 | 138 | $lat = $this->latitude; |
139 | 139 | $long = $this->longitude; |
140 | - $tmpr = $this->todaysWeather["temperature"]; |
|
141 | - $flike = $this->todaysWeather["feelsLike"]; |
|
142 | - $wSpeed = $this->todaysWeather["windSpeed"]; |
|
143 | - $wMain = $this->todaysWeather["weatherMain"]; |
|
144 | - $wDesc = $this->todaysWeather["weatherDesc"]; |
|
140 | + $tmpr = $this->todaysWeather[ "temperature" ]; |
|
141 | + $flike = $this->todaysWeather[ "feelsLike" ]; |
|
142 | + $wSpeed = $this->todaysWeather[ "windSpeed" ]; |
|
143 | + $wMain = $this->todaysWeather[ "weatherMain" ]; |
|
144 | + $wDesc = $this->todaysWeather[ "weatherDesc" ]; |
|
145 | 145 | |
146 | 146 | // Map image link |
147 | 147 | $mapLink = "https://maps.geoapify.com/v1/staticmap?style=osm-carto&width=500&height=350¢er=" |
148 | - . "lonlat:" . $long . "," . $lat . "&zoom=16&apiKey=" . $geoapifyApiKey; |
|
148 | + . "lonlat:".$long.",".$lat."&zoom=16&apiKey=".$geoapifyApiKey; |
|
149 | 149 | |
150 | 150 | // Coming weather next 7 days |
151 | 151 | $comingWeatherTable = $this->genForecastTable(); |
@@ -157,24 +157,24 @@ discard block |
||
157 | 157 | $returnHtml = " |
158 | 158 | <h5>Vädret just nu</h5> |
159 | 159 | <p> |
160 | - Vädret vid koordinaterna (" . $lat . ", " . $long . ") |
|
161 | - är <br><br><b>" . $wMain . "</b> (<b>" . $wDesc . "</b>) |
|
160 | + Vädret vid koordinaterna (" . $lat.", ".$long.") |
|
161 | + är <br><br><b>" . $wMain."</b> (<b>".$wDesc."</b>) |
|
162 | 162 | </p> |
163 | 163 | <br> |
164 | 164 | <p> |
165 | - Temperaturen är <b>" . $tmpr ."°C</b>, och känns som <b>" . $flike . "°C</b>. |
|
165 | + Temperaturen är <b>" . $tmpr."°C</b>, och känns som <b>".$flike."°C</b>. |
|
166 | 166 | </p> |
167 | 167 | <p> |
168 | - Vindar blåser i upp emot <b>" . $wSpeed . "m/s</b>.</p> |
|
168 | + Vindar blåser i upp emot <b>" . $wSpeed."m/s</b>.</p> |
|
169 | 169 | |
170 | 170 | <h5>Karta</h5> |
171 | - <img src=" . $mapLink . " alt='Karta'> |
|
171 | + <img src=" . $mapLink." alt='Karta'> |
|
172 | 172 | |
173 | 173 | <h5>Vädret kommande vecka</h5> |
174 | - " . $comingWeatherTable . " |
|
174 | + " . $comingWeatherTable." |
|
175 | 175 | |
176 | 176 | <h5>Vädret tidigare 5 dagar</h5> |
177 | - " . $histWeatherTbl . " |
|
177 | + " . $histWeatherTbl." |
|
178 | 178 | |
179 | 179 | "; |
180 | 180 | |
@@ -190,24 +190,24 @@ discard block |
||
190 | 190 | $htmlTable = "<table><thead><tr><th></th>"; //First cell is empty |
191 | 191 | $dailyDateSize = sizeof($this->dailyDate); |
192 | 192 | for ($i = 1; $i < $dailyDateSize; $i++) { |
193 | - $epochDate = $this->dailyDate[$i]; |
|
193 | + $epochDate = $this->dailyDate[ $i ]; |
|
194 | 194 | $day = date("D j", $epochDate); |
195 | - $htmlTable .= "<th>" . $day . "</th>"; |
|
195 | + $htmlTable .= "<th>".$day."</th>"; |
|
196 | 196 | } |
197 | 197 | $htmlTable .= "</tr></thead><tbody><tr><td><b>Beskrivning</b></td>"; |
198 | 198 | $dailyDescSize = sizeof($this->dailyDesc); |
199 | 199 | for ($i = 1; $i < $dailyDescSize; $i++) { |
200 | - $htmlTable .= "<td>" . $this->dailyDesc[$i] . "</td>"; |
|
200 | + $htmlTable .= "<td>".$this->dailyDesc[ $i ]."</td>"; |
|
201 | 201 | } |
202 | 202 | $htmlTable .= "</tr><tr><td><b>Temperatur</b></td>"; |
203 | 203 | $dailyTSize = sizeof($this->dailyTemp); |
204 | 204 | for ($i = 1; $i < $dailyTSize; $i++) { |
205 | - $htmlTable .= "<td>" . $this->dailyTemp[$i] . "°C</td>"; |
|
205 | + $htmlTable .= "<td>".$this->dailyTemp[ $i ]."°C</td>"; |
|
206 | 206 | } |
207 | 207 | $htmlTable .= "</tr><tr><td><b>Vindhastighet</b></td>"; |
208 | 208 | $dailyWSize = sizeof($this->dailyWind); |
209 | 209 | for ($i = 1; $i < $dailyWSize; $i++) { |
210 | - $htmlTable .= "<td>" . $this->dailyWind[$i] . "m/s</td>"; |
|
210 | + $htmlTable .= "<td>".$this->dailyWind[ $i ]."m/s</td>"; |
|
211 | 211 | } |
212 | 212 | $htmlTable .= "</tr></tbody></table>"; |
213 | 213 | return $htmlTable; |
@@ -220,24 +220,24 @@ discard block |
||
220 | 220 | $htmlTable = "<table><thead><tr><th></th>"; //First cell is empty |
221 | 221 | $histDateSize = sizeof($this->historicalDate); |
222 | 222 | for ($i = 1; $i < $histDateSize + 1; $i++) { |
223 | - $epochDate = $this->historicalDate[$i]; |
|
223 | + $epochDate = $this->historicalDate[ $i ]; |
|
224 | 224 | $day = date("D j", $epochDate); |
225 | - $htmlTable .= "<th>" . $day . "</th>"; |
|
225 | + $htmlTable .= "<th>".$day."</th>"; |
|
226 | 226 | } |
227 | 227 | $htmlTable .= "</tr></thead><tbody><tr><td><b>Beskrivning</b></td>"; |
228 | 228 | $histDescSize = sizeof($this->historicalDesc); |
229 | 229 | for ($i = 1; $i < $histDescSize + 1; $i++) { |
230 | - $htmlTable .= "<td>" . $this->historicalDesc[$i] . "</td>"; |
|
230 | + $htmlTable .= "<td>".$this->historicalDesc[ $i ]."</td>"; |
|
231 | 231 | } |
232 | 232 | $htmlTable .= "</tr><tr><td><b>Temperatur</b></td>"; |
233 | 233 | $dailyWSize = sizeof($this->historicalTemp); |
234 | 234 | for ($i = 1; $i < $dailyWSize + 1; $i++) { |
235 | - $htmlTable .= "<td>" . $this->historicalTemp[$i] . "°C</td>"; |
|
235 | + $htmlTable .= "<td>".$this->historicalTemp[ $i ]."°C</td>"; |
|
236 | 236 | } |
237 | 237 | $htmlTable .= "</tr><tr><td><b>Vindhastighet</b></td>"; |
238 | 238 | $dailyWSize = sizeof($this->historicalWind); |
239 | 239 | for ($i = 1; $i < $dailyWSize + 1; $i++) { |
240 | - $htmlTable .= "<td>" . $this->historicalWind[$i] . "m/s</td>"; |
|
240 | + $htmlTable .= "<td>".$this->historicalWind[ $i ]."m/s</td>"; |
|
241 | 241 | } |
242 | 242 | $htmlTable .= "</tr></tbody></table>"; |
243 | 243 | return $htmlTable; |
@@ -256,8 +256,8 @@ discard block |
||
256 | 256 | { |
257 | 257 | if ($this->latitude != "" && $this->longitude != "") { |
258 | 258 | $returnArray = array(); |
259 | - $returnArray["lat"] = $this->latitude; |
|
260 | - $returnArray["long"] = $this->longitude; |
|
259 | + $returnArray[ "lat" ] = $this->latitude; |
|
260 | + $returnArray[ "long" ] = $this->longitude; |
|
261 | 261 | return $returnArray; |
262 | 262 | } |
263 | 263 | return false; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | public function getCompleteFetchedData() |
267 | 267 | { |
268 | 268 | if (isset($this->latitude) && |
269 | - isset($this->todaysWeather["temperature"])) { |
|
269 | + isset($this->todaysWeather[ "temperature" ])) { |
|
270 | 270 | $currentArray = $this->todaysWeather; |
271 | 271 | $dailyArray = array(); |
272 | 272 | $historicalArray = array(); |
@@ -274,23 +274,23 @@ discard block |
||
274 | 274 | |
275 | 275 | $dailyDateSize = sizeof($this->dailyDate); |
276 | 276 | for ($i = 1; $i < $dailyDateSize + 1; $i++) { |
277 | - $arrayIdx = "forecast_" . $i; |
|
278 | - $dailyArray[$arrayIdx]["date"] = $this->dailyDate[$i]; |
|
279 | - $dailyArray[$arrayIdx]["description"] = $this->dailyDesc[$i]; |
|
280 | - $dailyArray[$arrayIdx]["temperature"] = $this->dailyTemp[$i]; |
|
281 | - $dailyArray[$arrayIdx]["windspeed"] = $this->dailyWind[$i]; |
|
277 | + $arrayIdx = "forecast_".$i; |
|
278 | + $dailyArray[ $arrayIdx ][ "date" ] = $this->dailyDate[ $i ]; |
|
279 | + $dailyArray[ $arrayIdx ][ "description" ] = $this->dailyDesc[ $i ]; |
|
280 | + $dailyArray[ $arrayIdx ][ "temperature" ] = $this->dailyTemp[ $i ]; |
|
281 | + $dailyArray[ $arrayIdx ][ "windspeed" ] = $this->dailyWind[ $i ]; |
|
282 | 282 | } |
283 | 283 | $histDateSize = sizeof($this->historicalDate); |
284 | 284 | for ($i = 1; $i < $histDateSize + 1; $i++) { |
285 | - $arrayIdx = "historical_" . $i; |
|
286 | - $historicalArray[$arrayIdx]["date"] = $this->historicalDate[$i]; |
|
287 | - $historicalArray[$arrayIdx]["description"] = $this->historicalDesc[$i]; |
|
288 | - $historicalArray[$arrayIdx]["temperature"] = $this->historicalTemp[$i]; |
|
289 | - $historicalArray[$arrayIdx]["windspeed"] = $this->historicalWind[$i]; |
|
285 | + $arrayIdx = "historical_".$i; |
|
286 | + $historicalArray[ $arrayIdx ][ "date" ] = $this->historicalDate[ $i ]; |
|
287 | + $historicalArray[ $arrayIdx ][ "description" ] = $this->historicalDesc[ $i ]; |
|
288 | + $historicalArray[ $arrayIdx ][ "temperature" ] = $this->historicalTemp[ $i ]; |
|
289 | + $historicalArray[ $arrayIdx ][ "windspeed" ] = $this->historicalWind[ $i ]; |
|
290 | 290 | } |
291 | - $returnArray[0] = $currentArray; |
|
292 | - $returnArray[1] = $dailyArray; |
|
293 | - $returnArray[2] = $historicalArray; |
|
291 | + $returnArray[ 0 ] = $currentArray; |
|
292 | + $returnArray[ 1 ] = $dailyArray; |
|
293 | + $returnArray[ 2 ] = $historicalArray; |
|
294 | 294 | return $returnArray; |
295 | 295 | } |
296 | 296 | return false; |