fix: correct degreesToCompassDirection function

This commit is contained in:
Roscoe 2023-06-17 13:58:08 +01:00
parent 476a58fafc
commit 294a9573e4

View file

@ -1,9 +1,10 @@
@php @php
function degreesToCompassDirection($degrees) { function degreesToCompassDirection($degrees) {
$cardinalDirections = array('N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'); $cardinalDirections = [
$degreesPerDirection = 360 / count($cardinalDirections); 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
$index = round($degrees / $degreesPerDirection); 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'
return $cardinalDirections[$index]; ];
return $cardinalDirections[round($degrees*16/360)];
} }
$data = json_decode(file_get_contents('http://weather.diskfloppy.me/data/weatherData.json')); $data = json_decode(file_get_contents('http://weather.diskfloppy.me/data/weatherData.json'));