Created
January 20, 2019 13:15
-
-
Save mmaridev/b56afe64d4518189f5e94c7104ee1398 to your computer and use it in GitHub Desktop.
WeatherWing human variables converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fileaddr = "http://localhost/meteo/clientraw.txt"; | |
$content = implode('', file ($fileaddr)); | |
$vals = explode(" ", $content); | |
//Gestione della direzione del vento (da tabella5.php) | |
function direzioneVento ($gradi) | |
{ | |
$windlabel = array("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSO", "SO", "OSO", "O", "ONO", "NO", "NNO"); | |
return $windlabel[floor((($gradi + 11) / 22.5) % 16 )]; | |
} | |
// Conversione data (da tabella5.php) | |
function conv_date ($data) | |
{ | |
list ($mese, $giorno, $anno) = explode ("/" , $data); | |
return $giorno ."/". $mese ."/". $anno ; | |
} | |
function onlyVal($value) { | |
return explode(" ", $value)[0]; | |
} | |
// convert into human variables | |
$update_time = $vals[29] . ":" . $vals[30]; | |
$update_day = conv_date($vals[74]); | |
$temperature = $vals[4] . " °C"; | |
$humidity = $vals[5] . " %"; | |
$dew_point = $vals[72] . " °C"; | |
$temp_min = $vals[47] . " °C"; | |
$temp_max = $vals[46] . " °C"; | |
$pressure = $vals[6] . " hPa"; | |
// wind is passed in knots, we need to convert it | |
$wind_act_kts = $vals[2] . " kts"; | |
$wind_act_kmh = round($vals[2] * 1.852, 1) . " km/h"; | |
$wind_med_kts = $vals[1] . " kts"; | |
$wind_med_kmh = $vals[1] * 1.852 . " km/h"; | |
$wind_orig = $vals[3]; | |
$wind_orig_name = direzioneVento($vals[3]); | |
$wind_gust_max_kts = $vals[71] . " kts"; | |
$wind_gust_max_kmh = round($vals[71] * 1.852 , 1) . " km/h"; | |
$rain_day = $vals[7] . " mm"; | |
// if $rain_intensity <= 0.01 -> no rain | |
$rain_intensity = $vals[10]*60 . " mm/h"; // measure unit: mm/h (millimiters per hour) | |
$rain_intensity_max = $vals[11]*60 . " mm/h"; // measure unit: mm/h (millimiters per hour) | |
$rain_month = $vals[8] . " mm"; | |
$rain_year = $vals[9] . " mm"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment