@@ -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"); |
@@ -11,14 +11,14 @@ discard block |
||
11 | 11 | protected $longitude = ""; |
12 | 12 | protected $todaysWeather = array(); |
13 | 13 | |
14 | - protected $dailyDate = []; |
|
15 | - protected $dailyDesc = []; |
|
16 | - protected $dailyTemp = []; |
|
17 | - protected $dailyWind = []; |
|
18 | - protected $historicalDate = []; |
|
19 | - protected $historicalDesc = []; |
|
20 | - protected $historicalTemp = []; |
|
21 | - protected $historicalWind = []; |
|
14 | + protected $dailyDate = [ ]; |
|
15 | + protected $dailyDesc = [ ]; |
|
16 | + protected $dailyTemp = [ ]; |
|
17 | + protected $dailyWind = [ ]; |
|
18 | + protected $historicalDate = [ ]; |
|
19 | + protected $historicalDesc = [ ]; |
|
20 | + protected $historicalTemp = [ ]; |
|
21 | + protected $historicalWind = [ ]; |
|
22 | 22 | |
23 | 23 | public function getWeather($inputLat, $inputLong) |
24 | 24 | { |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | |
29 | 29 | // Fetching epoch times for last 5 days |
30 | 30 | $epochDays = array(); |
31 | - $epochDays[0] = strtotime("-5 days"); |
|
32 | - $epochDays[1] = strtotime("-4 days"); |
|
33 | - $epochDays[2] = strtotime("-3 days"); |
|
34 | - $epochDays[3] = strtotime("-2 days"); |
|
35 | - $epochDays[4] = strtotime("-1 days"); |
|
31 | + $epochDays[ 0 ] = strtotime("-5 days"); |
|
32 | + $epochDays[ 1 ] = strtotime("-4 days"); |
|
33 | + $epochDays[ 2 ] = strtotime("-3 days"); |
|
34 | + $epochDays[ 3 ] = strtotime("-2 days"); |
|
35 | + $epochDays[ 4 ] = strtotime("-1 days"); |
|
36 | 36 | |
37 | 37 | $url1 = "https://api.openweathermap.org/data/2.5/onecall?" |
38 | - . "lat=" . $inputLat . "&lon=" . $inputLong |
|
38 | + . "lat=".$inputLat."&lon=".$inputLong |
|
39 | 39 | . "&exclude=minutely,hourly,alerts&" |
40 | - . "appid=" . $owmApiKey |
|
40 | + . "appid=".$owmApiKey |
|
41 | 41 | . "&units=metric&lang=se"; |
42 | 42 | |
43 | 43 | //Creating URLs for historical data |
44 | 44 | $historicalUrls = array(); |
45 | 45 | for ($i = 0; $i < 5; $i++) { |
46 | - $historicalUrls[$i] = "https://api.openweathermap.org/data/2.5/onecall/timemachine?" |
|
47 | - . "lat=" . $inputLat . "&lon=" . $inputLong |
|
48 | - . "&dt=" . $epochDays[$i] |
|
49 | - . "&appid=" . $owmApiKey |
|
46 | + $historicalUrls[ $i ] = "https://api.openweathermap.org/data/2.5/onecall/timemachine?" |
|
47 | + . "lat=".$inputLat."&lon=".$inputLong |
|
48 | + . "&dt=".$epochDays[ $i ] |
|
49 | + . "&appid=".$owmApiKey |
|
50 | 50 | . "&units=metric&lang=se"; |
51 | 51 | } |
52 | 52 | |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | $running = 0; |
61 | 61 | |
62 | 62 | for ($i = 0; $i < $urlCount; $i++) { |
63 | - $url =$urls[$i]; |
|
64 | - $responseArr[$i] = curl_init($url); |
|
65 | - curl_setopt($responseArr[$i], CURLOPT_RETURNTRANSFER, true); |
|
66 | - curl_multi_add_handle($master, $responseArr[$i]); |
|
63 | + $url = $urls[ $i ]; |
|
64 | + $responseArr[ $i ] = curl_init($url); |
|
65 | + curl_setopt($responseArr[ $i ], CURLOPT_RETURNTRANSFER, true); |
|
66 | + curl_multi_add_handle($master, $responseArr[ $i ]); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | do { |
@@ -72,37 +72,37 @@ discard block |
||
72 | 72 | |
73 | 73 | $results = array(); |
74 | 74 | for ($i = 0; $i < $urlCount; $i++) { |
75 | - $results[$i] = curl_multi_getcontent($responseArr[$i]); |
|
76 | - $results[$i] = json_decode($results[$i]); |
|
75 | + $results[ $i ] = curl_multi_getcontent($responseArr[ $i ]); |
|
76 | + $results[ $i ] = json_decode($results[ $i ]); |
|
77 | 77 | } |
78 | 78 | |
79 | - if (isset($results[0])) { |
|
79 | + if (isset($results[ 0 ])) { |
|
80 | 80 | // Handle response for request 1 |
81 | 81 | |
82 | 82 | // Current weather |
83 | - $this->todaysWeather["temperature"] = @$results[0]->current->temp; |
|
84 | - $this->todaysWeather["feelsLike"] = @$results[0]->current->feels_like; |
|
85 | - $this->todaysWeather["windSpeed"] = @$results[0]->current->wind_speed; |
|
83 | + $this->todaysWeather[ "temperature" ] = @$results[ 0 ]->current->temp; |
|
84 | + $this->todaysWeather[ "feelsLike" ] = @$results[ 0 ]->current->feels_like; |
|
85 | + $this->todaysWeather[ "windSpeed" ] = @$results[ 0 ]->current->wind_speed; |
|
86 | 86 | |
87 | - $this->todaysWeather["weatherMain"] = @$results[0]->current->weather[0]->main; |
|
88 | - $this->todaysWeather["weatherDesc"] = @$results[0]->current->weather[0]->description; |
|
87 | + $this->todaysWeather[ "weatherMain" ] = @$results[ 0 ]->current->weather[ 0 ]->main; |
|
88 | + $this->todaysWeather[ "weatherDesc" ] = @$results[ 0 ]->current->weather[ 0 ]->description; |
|
89 | 89 | |
90 | 90 | // Weather next 7 days |
91 | - $dailySize = @sizeof($results[0]->daily); |
|
91 | + $dailySize = @sizeof($results[ 0 ]->daily); |
|
92 | 92 | for ($i = 1; $i < @$dailySize; $i++) { |
93 | - $this->dailyDate[$i] = $results[0]->daily[$i]->dt; |
|
94 | - $this->dailyDesc[$i] = $results[0]->daily[$i]->weather[0]->description; |
|
95 | - $this->dailyTemp[$i] = $results[0]->daily[$i]->temp->day; |
|
96 | - $this->dailyWind[$i] = $results[0]->daily[$i]->wind_speed; |
|
93 | + $this->dailyDate[ $i ] = $results[ 0 ]->daily[ $i ]->dt; |
|
94 | + $this->dailyDesc[ $i ] = $results[ 0 ]->daily[ $i ]->weather[ 0 ]->description; |
|
95 | + $this->dailyTemp[ $i ] = $results[ 0 ]->daily[ $i ]->temp->day; |
|
96 | + $this->dailyWind[ $i ] = $results[ 0 ]->daily[ $i ]->wind_speed; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // Weather last 5 days |
100 | 100 | $resultSize = sizeof($results); |
101 | 101 | for ($i = 1; $i < $resultSize; $i++) { |
102 | - $this->historicalDate[$i] = @$results[$i]->current->dt; |
|
103 | - $this->historicalDesc[$i] = @$results[$i]->current->weather[0]->description; |
|
104 | - $this->historicalTemp[$i] = @$results[$i]->current->temp; |
|
105 | - $this->historicalWind[$i] = @$results[$i]->current->wind_speed; |
|
102 | + $this->historicalDate[ $i ] = @$results[ $i ]->current->dt; |
|
103 | + $this->historicalDesc[ $i ] = @$results[ $i ]->current->weather[ 0 ]->description; |
|
104 | + $this->historicalTemp[ $i ] = @$results[ $i ]->current->temp; |
|
105 | + $this->historicalWind[ $i ] = @$results[ $i ]->current->wind_speed; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
@@ -110,21 +110,21 @@ discard block |
||
110 | 110 | |
111 | 111 | public function buildWeatherHtml() |
112 | 112 | { |
113 | - if (isset($this->todaysWeather["temperature"])) { |
|
113 | + if (isset($this->todaysWeather[ "temperature" ])) { |
|
114 | 114 | $geoapifyApiKey = $this->geoApiKey; |
115 | 115 | |
116 | 116 | // Weather right now |
117 | 117 | $lat = $this->latitude; |
118 | 118 | $long = $this->longitude; |
119 | - $tmpr = $this->todaysWeather["temperature"]; |
|
120 | - $flike = $this->todaysWeather["feelsLike"]; |
|
121 | - $wSpeed = $this->todaysWeather["windSpeed"]; |
|
122 | - $wMain = $this->todaysWeather["weatherMain"]; |
|
123 | - $wDesc = $this->todaysWeather["weatherDesc"]; |
|
119 | + $tmpr = $this->todaysWeather[ "temperature" ]; |
|
120 | + $flike = $this->todaysWeather[ "feelsLike" ]; |
|
121 | + $wSpeed = $this->todaysWeather[ "windSpeed" ]; |
|
122 | + $wMain = $this->todaysWeather[ "weatherMain" ]; |
|
123 | + $wDesc = $this->todaysWeather[ "weatherDesc" ]; |
|
124 | 124 | |
125 | 125 | // Map image link |
126 | 126 | $mapLink = "https://maps.geoapify.com/v1/staticmap?style=osm-carto&width=500&height=350¢er=" |
127 | - . "lonlat:" . $long . "," . $lat . "&zoom=16&apiKey=" . $geoapifyApiKey; |
|
127 | + . "lonlat:".$long.",".$lat."&zoom=16&apiKey=".$geoapifyApiKey; |
|
128 | 128 | |
129 | 129 | // Coming weather next 7 days |
130 | 130 | $comingWeatherTable = $this->genForecastTable(); |
@@ -136,24 +136,24 @@ discard block |
||
136 | 136 | $returnHtml = " |
137 | 137 | <h5>Vädret just nu</h5> |
138 | 138 | <p> |
139 | - Vädret vid koordinaterna (" . $lat . ", " . $long . ") |
|
140 | - är <br><br><b>" . $wMain . "</b> (<b>" . $wDesc . "</b>) |
|
139 | + Vädret vid koordinaterna (" . $lat.", ".$long.") |
|
140 | + är <br><br><b>" . $wMain."</b> (<b>".$wDesc."</b>) |
|
141 | 141 | </p> |
142 | 142 | <br> |
143 | 143 | <p> |
144 | - Temperaturen är <b>" . $tmpr ."°C</b>, och känns som <b>" . $flike . "°C</b>. |
|
144 | + Temperaturen är <b>" . $tmpr."°C</b>, och känns som <b>".$flike."°C</b>. |
|
145 | 145 | </p> |
146 | 146 | <p> |
147 | - Vindar blåser i upp emot <b>" . $wSpeed . "m/s</b>.</p> |
|
147 | + Vindar blåser i upp emot <b>" . $wSpeed."m/s</b>.</p> |
|
148 | 148 | |
149 | 149 | <h5>Karta</h5> |
150 | - <img src=" . $mapLink . " alt='Karta'> |
|
150 | + <img src=" . $mapLink." alt='Karta'> |
|
151 | 151 | |
152 | 152 | <h5>Vädret kommande vecka</h5> |
153 | - " . $comingWeatherTable . " |
|
153 | + " . $comingWeatherTable." |
|
154 | 154 | |
155 | 155 | <h5>Vädret tidigare 5 dagar</h5> |
156 | - " . $histWeatherTbl . " |
|
156 | + " . $histWeatherTbl." |
|
157 | 157 | |
158 | 158 | "; |
159 | 159 | |
@@ -169,24 +169,24 @@ discard block |
||
169 | 169 | $htmlTable = "<table><thead><tr><th></th>"; //First cell is empty |
170 | 170 | $dailyDateSize = sizeof($this->dailyDate); |
171 | 171 | for ($i = 1; $i < $dailyDateSize; $i++) { |
172 | - $epochDate = $this->dailyDate[$i]; |
|
172 | + $epochDate = $this->dailyDate[ $i ]; |
|
173 | 173 | $day = date("D j", $epochDate); |
174 | - $htmlTable .= "<th>" . $day . "</th>"; |
|
174 | + $htmlTable .= "<th>".$day."</th>"; |
|
175 | 175 | } |
176 | 176 | $htmlTable .= "</tr></thead><tbody><tr><td><b>Beskrivning</b></td>"; |
177 | 177 | $dailyDescSize = sizeof($this->dailyDesc); |
178 | 178 | for ($i = 1; $i < $dailyDescSize; $i++) { |
179 | - $htmlTable .= "<td>" . $this->dailyDesc[$i] . "</td>"; |
|
179 | + $htmlTable .= "<td>".$this->dailyDesc[ $i ]."</td>"; |
|
180 | 180 | } |
181 | 181 | $htmlTable .= "</tr><tr><td><b>Temperatur</b></td>"; |
182 | 182 | $dailyTSize = sizeof($this->dailyTemp); |
183 | 183 | for ($i = 1; $i < $dailyTSize; $i++) { |
184 | - $htmlTable .= "<td>" . $this->dailyTemp[$i] . "°C</td>"; |
|
184 | + $htmlTable .= "<td>".$this->dailyTemp[ $i ]."°C</td>"; |
|
185 | 185 | } |
186 | 186 | $htmlTable .= "</tr><tr><td><b>Vindhastighet</b></td>"; |
187 | 187 | $dailyWSize = sizeof($this->dailyWind); |
188 | 188 | for ($i = 1; $i < $dailyWSize; $i++) { |
189 | - $htmlTable .= "<td>" . $this->dailyWind[$i] . "m/s</td>"; |
|
189 | + $htmlTable .= "<td>".$this->dailyWind[ $i ]."m/s</td>"; |
|
190 | 190 | } |
191 | 191 | $htmlTable .= "</tr></tbody></table>"; |
192 | 192 | return $htmlTable; |
@@ -199,24 +199,24 @@ discard block |
||
199 | 199 | $htmlTable = "<table><thead><tr><th></th>"; //First cell is empty |
200 | 200 | $histDateSize = sizeof($this->historicalDate); |
201 | 201 | for ($i = 1; $i < $histDateSize + 1; $i++) { |
202 | - $epochDate = $this->historicalDate[$i]; |
|
202 | + $epochDate = $this->historicalDate[ $i ]; |
|
203 | 203 | $day = date("D j", $epochDate); |
204 | - $htmlTable .= "<th>" . $day . "</th>"; |
|
204 | + $htmlTable .= "<th>".$day."</th>"; |
|
205 | 205 | } |
206 | 206 | $htmlTable .= "</tr></thead><tbody><tr><td><b>Beskrivning</b></td>"; |
207 | 207 | $histDescSize = sizeof($this->historicalDesc); |
208 | 208 | for ($i = 1; $i < $histDescSize + 1; $i++) { |
209 | - $htmlTable .= "<td>" . $this->historicalDesc[$i] . "</td>"; |
|
209 | + $htmlTable .= "<td>".$this->historicalDesc[ $i ]."</td>"; |
|
210 | 210 | } |
211 | 211 | $htmlTable .= "</tr><tr><td><b>Temperatur</b></td>"; |
212 | 212 | $dailyWSize = sizeof($this->historicalTemp); |
213 | 213 | for ($i = 1; $i < $dailyWSize + 1; $i++) { |
214 | - $htmlTable .= "<td>" . $this->historicalTemp[$i] . "°C</td>"; |
|
214 | + $htmlTable .= "<td>".$this->historicalTemp[ $i ]."°C</td>"; |
|
215 | 215 | } |
216 | 216 | $htmlTable .= "</tr><tr><td><b>Vindhastighet</b></td>"; |
217 | 217 | $dailyWSize = sizeof($this->historicalWind); |
218 | 218 | for ($i = 1; $i < $dailyWSize + 1; $i++) { |
219 | - $htmlTable .= "<td>" . $this->historicalWind[$i] . "m/s</td>"; |
|
219 | + $htmlTable .= "<td>".$this->historicalWind[ $i ]."m/s</td>"; |
|
220 | 220 | } |
221 | 221 | $htmlTable .= "</tr></tbody></table>"; |
222 | 222 | return $htmlTable; |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | { |
236 | 236 | if ($this->latitude != "" && $this->longitude != "") { |
237 | 237 | $returnArray = array(); |
238 | - $returnArray["lat"] = $this->latitude; |
|
239 | - $returnArray["long"] = $this->longitude; |
|
238 | + $returnArray[ "lat" ] = $this->latitude; |
|
239 | + $returnArray[ "long" ] = $this->longitude; |
|
240 | 240 | return $returnArray; |
241 | 241 | } |
242 | 242 | return false; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | public function getCompleteFetchedData() |
246 | 246 | { |
247 | 247 | if (isset($this->latitude) && |
248 | - isset($this->todaysWeather["temperature"])) { |
|
248 | + isset($this->todaysWeather[ "temperature" ])) { |
|
249 | 249 | $currentArray = $this->todaysWeather; |
250 | 250 | $dailyArray = array(); |
251 | 251 | $historicalArray = array(); |
@@ -253,23 +253,23 @@ discard block |
||
253 | 253 | |
254 | 254 | $dailyDateSize = sizeof($this->dailyDate); |
255 | 255 | for ($i = 1; $i < $dailyDateSize + 1; $i++) { |
256 | - $arrayIdx = "forecast_" . $i; |
|
257 | - $dailyArray[$arrayIdx]["date"] = $this->dailyDate[$i]; |
|
258 | - $dailyArray[$arrayIdx]["description"] = $this->dailyDesc[$i]; |
|
259 | - $dailyArray[$arrayIdx]["temperature"] = $this->dailyTemp[$i]; |
|
260 | - $dailyArray[$arrayIdx]["windspeed"] = $this->dailyWind[$i]; |
|
256 | + $arrayIdx = "forecast_".$i; |
|
257 | + $dailyArray[ $arrayIdx ][ "date" ] = $this->dailyDate[ $i ]; |
|
258 | + $dailyArray[ $arrayIdx ][ "description" ] = $this->dailyDesc[ $i ]; |
|
259 | + $dailyArray[ $arrayIdx ][ "temperature" ] = $this->dailyTemp[ $i ]; |
|
260 | + $dailyArray[ $arrayIdx ][ "windspeed" ] = $this->dailyWind[ $i ]; |
|
261 | 261 | } |
262 | 262 | $histDateSize = sizeof($this->historicalDate); |
263 | 263 | for ($i = 1; $i < $histDateSize + 1; $i++) { |
264 | - $arrayIdx = "historical_" . $i; |
|
265 | - $historicalArray[$arrayIdx]["date"] = $this->historicalDate[$i]; |
|
266 | - $historicalArray[$arrayIdx]["description"] = $this->historicalDesc[$i]; |
|
267 | - $historicalArray[$arrayIdx]["temperature"] = $this->historicalTemp[$i]; |
|
268 | - $historicalArray[$arrayIdx]["windspeed"] = $this->historicalWind[$i]; |
|
264 | + $arrayIdx = "historical_".$i; |
|
265 | + $historicalArray[ $arrayIdx ][ "date" ] = $this->historicalDate[ $i ]; |
|
266 | + $historicalArray[ $arrayIdx ][ "description" ] = $this->historicalDesc[ $i ]; |
|
267 | + $historicalArray[ $arrayIdx ][ "temperature" ] = $this->historicalTemp[ $i ]; |
|
268 | + $historicalArray[ $arrayIdx ][ "windspeed" ] = $this->historicalWind[ $i ]; |
|
269 | 269 | } |
270 | - $returnArray[0] = $currentArray; |
|
271 | - $returnArray[1] = $dailyArray; |
|
272 | - $returnArray[2] = $historicalArray; |
|
270 | + $returnArray[ 0 ] = $currentArray; |
|
271 | + $returnArray[ 1 ] = $dailyArray; |
|
272 | + $returnArray[ 2 ] = $historicalArray; |
|
273 | 273 | return $returnArray; |
274 | 274 | } |
275 | 275 | return false; |