Completed
Push — master ( 99c879...bd00f6 )
by Yannick
47:00
created
weather-json.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,11 +9,11 @@  discard block
 block discarded – undo
9 9
 	header('Content-disposition: attachment; filename="weather.json"');
10 10
 }
11 11
 header('Content-Type: text/javascript');
12
-$latitude = filter_input(INPUT_GET,'latitude',FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
13
-$longitude = filter_input(INPUT_GET,'longitude',FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
12
+$latitude = filter_input(INPUT_GET, 'latitude', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
13
+$longitude = filter_input(INPUT_GET, 'longitude', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
14 14
 if ($latitude == '' || $longitude == '') return '';
15 15
 //echo 'latitude : '.$latitude.' - longitude : '.$longitude."\n";
16
-$airports = $Spotter->closestAirports($latitude,$longitude,300);
16
+$airports = $Spotter->closestAirports($latitude, $longitude, 300);
17 17
 //print_r($airports);
18 18
 $METAR = new METAR();
19 19
 $Weather = new Weather();
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 $ew = true;
22 22
 $dtf = false;
23 23
 if (empty($airports)) $ew = false;
24
-while($ew) {
24
+while ($ew) {
25 25
 	$met = $METAR->getMETAR($airports[$i]['icao']);
26 26
 	//print_r($met);
27 27
 	if (!empty($met)) {
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 		//print_r($parsed);
30 30
 		$rain = array();
31 31
 		if (isset($parsed['temperature'])) {
32
-			$rain = array_merge($rain,array('temp' => $parsed['temperature']));
32
+			$rain = array_merge($rain, array('temp' => $parsed['temperature']));
33 33
 		}
34 34
 		if (isset($parsed['rh'])) {
35
-			$rain = array_merge($rain,array('rh' => $parsed['rh']));
35
+			$rain = array_merge($rain, array('rh' => $parsed['rh']));
36 36
 		}
37 37
 		if (isset($parsed['weather']) && $parsed['weather'] == 'CAVOK') {
38
-			echo json_encode(array('clouds' => array(),'rain' => array()));
38
+			echo json_encode(array('clouds' => array(), 'rain' => array()));
39 39
 			$ew  = false;
40 40
 			$dtf = true;
41 41
 		} elseif (isset($parsed['cloud'])) {
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 			if (!empty($result)) {
44 44
 				//print_r($met);
45 45
 				//print_r($parsed);
46
-				echo json_encode(array('clouds' => $result,'rain' => $rain));
46
+				echo json_encode(array('clouds' => $result, 'rain' => $rain));
47 47
 				$ew = false;
48 48
 				$dtf = true;
49 49
 			}
@@ -52,6 +52,6 @@  discard block
 block discarded – undo
52 52
 	$i++;
53 53
 	if ($i >= count($airports)) $ew = false;
54 54
 }
55
-if ($dtf === false) echo json_encode($Weather->openweathermap($latitude,$longitude));
55
+if ($dtf === false) echo json_encode($Weather->openweathermap($latitude, $longitude));
56 56
 
57 57
 ?>
58 58
\ No newline at end of file
Please login to merge, or discard this patch.
require/class.Weather.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 	public function buildcloudlayer($metar) {
12 12
 		//print_r($metar);
13 13
 		$result = array();
14
-		foreach($metar['cloud'] as $key => $data) {
14
+		foreach ($metar['cloud'] as $key => $data) {
15 15
 			$alt_m = $metar['cloud'][$key]['level'];
16 16
 			$alt_ft = $alt_m*3.28084;
17 17
 			$pressure = $metar['QNH'];
18
-			$cumulus_base = 122.0 * ($metar['temperature'] - $metar['dew']);
19
-			$stratus_base = 100.0 * (100.0 * $metar['rh'])*0.3048;
18
+			$cumulus_base = 122.0*($metar['temperature'] - $metar['dew']);
19
+			$stratus_base = 100.0*(100.0*$metar['rh'])*0.3048;
20 20
 			$coverage_norm = 0.0;
21 21
 			if ($metar['cloud'][$key]['type'] == 'Few') {
22 22
 				$coverage_norm = 2.0/8.0;
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 					$layer_type = 'ns';
39 39
 				}
40 40
 			} else {
41
-				if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) {
41
+				if ($cumulus_base*0.80 < $alt_m && $cumulus_base*1.20 > $alt_m) {
42 42
 					$layer_type = 'cu';
43
-				} elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) {
43
+				} elseif ($stratus_base*0.80 < $alt_m && $stratus_base*1.40 > $alt_m) {
44 44
 					$layer_type = 'st';
45 45
 				} else {
46 46
 					if ($alt_ft < 2000) {
@@ -53,25 +53,25 @@  discard block
 block discarded – undo
53 53
 				}
54 54
 			}
55 55
 			//echo 'coverage norm : '.$coverage_norm.' - layer_type: '.$layer_type."\n";
56
-			$result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $metar['rh']);
56
+			$result[] = array('cov' => $coverage_norm, 'type' => $layer_type, 'alt' => $alt_m, 'rh' => $metar['rh']);
57 57
 		}
58 58
 		if (count($result) < 2 && $metar['rh'] > 60) {
59
-			$result[] = array('cov' => 0.75, 'type' => 'ci','alt' => 4000,'rh' => $metar['rh']);
59
+			$result[] = array('cov' => 0.75, 'type' => 'ci', 'alt' => 4000, 'rh' => $metar['rh']);
60 60
 		}
61 61
 		return $result;
62 62
 	}
63 63
 	
64
-	public function openweathermap($latitude,$longitude) {
64
+	public function openweathermap($latitude, $longitude) {
65 65
 		global $globalOpenWeatherMapKey;
66 66
 		if ($globalOpenWeatherMapKey == '') return array();
67 67
 		$Common = new Common();
68 68
 		$url = 'http://api.openweathermap.org/data/2.5/weather?lat='.$latitude.'&lon='.$longitude.'&units=metric&appid='.$globalOpenWeatherMapKey;
69 69
 		//echo $url."\n";
70
-		$weatherdata = json_decode($Common->getData($url),true);
71
-		if (!isset($weatherdata['main']['temp']) || !isset($weatherdata['weather'][0]['id'])) return array('clouds' => array(),'rain' => array());
72
-		$dew = $weatherdata['main']['temp'] - ((100-$weatherdata['main']['humidity'])/5);
73
-		$cumulus_base = 122.0 * ($weatherdata['main']['temp'] - $dew);
74
-		$stratus_base = 100.0 * (100.0 * $weatherdata['main']['humidity'])*0.3048;
70
+		$weatherdata = json_decode($Common->getData($url), true);
71
+		if (!isset($weatherdata['main']['temp']) || !isset($weatherdata['weather'][0]['id'])) return array('clouds' => array(), 'rain' => array());
72
+		$dew = $weatherdata['main']['temp'] - ((100 - $weatherdata['main']['humidity'])/5);
73
+		$cumulus_base = 122.0*($weatherdata['main']['temp'] - $dew);
74
+		$stratus_base = 100.0*(100.0*$weatherdata['main']['humidity'])*0.3048;
75 75
 		$coverage_norm = 0.0;
76 76
 		if ($weatherdata['weather'][0]['id'] == 801) {
77 77
 			// few clouds
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
 			$coverage_norm = 8.0/8.0;
88 88
 		}
89 89
 		$alt_m = 1000;
90
-		if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) {
90
+		if ($cumulus_base*0.80 < $alt_m && $cumulus_base*1.20 > $alt_m) {
91 91
 			$layer_type = 'cu';
92
-		} elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) {
92
+		} elseif ($stratus_base*0.80 < $alt_m && $stratus_base*1.40 > $alt_m) {
93 93
 			$layer_type = 'st';
94 94
 		} else {
95 95
 			$layer_type = 'st';
96 96
 		}
97 97
 		$result = array();
98
-		$result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $weatherdata['main']['humidity']);
98
+		$result[] = array('cov' => $coverage_norm, 'type' => $layer_type, 'alt' => $alt_m, 'rh' => $weatherdata['main']['humidity']);
99 99
 		if ($weatherdata['main']['humidity'] > 60) {
100
-			$result[] = array('cov' => 0.75, 'type' => 'ci','alt' => 4000,'rh' => $weatherdata['main']['humidity']);
100
+			$result[] = array('cov' => 0.75, 'type' => 'ci', 'alt' => 4000, 'rh' => $weatherdata['main']['humidity']);
101 101
 		}
102
-		return array('clouds' => $result,'rain' => array('tmp' => $weatherdata['main']['temp'],'rh' => $weatherdata['main']['humidity']));
102
+		return array('clouds' => $result, 'rain' => array('tmp' => $weatherdata['main']['temp'], 'rh' => $weatherdata['main']['humidity']));
103 103
 	}
104 104
 	
105 105
 	public function nomad_wind($hour = '') {
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 		
118 118
 		// http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p50.pl?file=gfs.t05z.pgrb2full.0p50.f000&lev_10_m_above_ground=on&lev_surface=on&var_TMP=on&var_UGRD=on&var_VGRD=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=/gfs.2017111717
119 119
 		$resolution = '0.5';
120
-		$baseurl = 'http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_'.($resolution === '1' ? '1p00':'0p50').'.pl';
121
-		$get = array('file' => 'gfs.t'.sprintf('%02d',(6*floor($hour/6))).($resolution === '1' ? 'z.pgrb2.1p00.f000' : 'z.pgrb2full.0p50.f000'),
120
+		$baseurl = 'http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_'.($resolution === '1' ? '1p00' : '0p50').'.pl';
121
+		$get = array('file' => 'gfs.t'.sprintf('%02d', (6*floor($hour/6))).($resolution === '1' ? 'z.pgrb2.1p00.f000' : 'z.pgrb2full.0p50.f000'),
122 122
 			'lev_10_m_above_ground' => 'on',
123 123
 			'lev_surface' => 'on',
124 124
 			'var_TMP' => 'on',
@@ -128,21 +128,21 @@  discard block
 block discarded – undo
128 128
 			'rightlon' => 360,
129 129
 			'toplat' => 90,
130 130
 			'bottomlat' => -90,
131
-			'dir' => '/gfs.'.date('Ymd').sprintf('%02d',(6*floor($hour/6)))
131
+			'dir' => '/gfs.'.date('Ymd').sprintf('%02d', (6*floor($hour/6)))
132 132
 		);
133 133
 		$url = $baseurl.'?'.http_build_query($get);
134 134
 		//echo $url;
135 135
 		$Common = new Common();
136
-		$Common->download($url,$windpathsrc);
136
+		$Common->download($url, $windpathsrc);
137 137
 		// Check if the downloaded file is in GRIB format
138
-		$file = fopen($windpathsrc,"r");
138
+		$file = fopen($windpathsrc, "r");
139 139
 		$firc = fgetc($file);
140 140
 		fclose($file);
141 141
 		if ($firc == 'G') {
142 142
 			system($grib2json.' --data --output '.$windpathdest.' --names --compact '.$windpathsrc);
143 143
 		} else {
144 144
 			// if not try previous run
145
-			if ($hour == date('G')) $this->nomad_wind(date('G')-6);
145
+			if ($hour == date('G')) $this->nomad_wind(date('G') - 6);
146 146
 		}
147 147
 	}
148 148
 
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 		$url = 'https://podaac.jpl.nasa.gov/ws/search/granule/?datasetId=PODAAC-OSCAR-03D01&itemsPerPage=1&sortBy=timeDesc&format=atom&pretty=false';
162 162
 		$Common = new Common();
163 163
 		$oscarlst = $Common->getData($url);
164
-		$oscarlst_xml = json_decode(json_encode(simplexml_load_string($oscarlst)),true);
164
+		$oscarlst_xml = json_decode(json_encode(simplexml_load_string($oscarlst)), true);
165 165
 		foreach ($oscarlst_xml['entry']['link'] as $oscarlnk) {
166 166
 			if ($oscarlnk['@attributes']['type'] == 'application/x-netcdf') {
167
-				$Common->download($oscarlnk['@attributes']['href'],$wavepathsrc.'.gz');
167
+				$Common->download($oscarlnk['@attributes']['href'], $wavepathsrc.'.gz');
168 168
 				break;
169 169
 			}
170 170
 		}
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -63,12 +63,16 @@  discard block
 block discarded – undo
63 63
 	
64 64
 	public function openweathermap($latitude,$longitude) {
65 65
 		global $globalOpenWeatherMapKey;
66
-		if ($globalOpenWeatherMapKey == '') return array();
66
+		if ($globalOpenWeatherMapKey == '') {
67
+			return array();
68
+		}
67 69
 		$Common = new Common();
68 70
 		$url = 'http://api.openweathermap.org/data/2.5/weather?lat='.$latitude.'&lon='.$longitude.'&units=metric&appid='.$globalOpenWeatherMapKey;
69 71
 		//echo $url."\n";
70 72
 		$weatherdata = json_decode($Common->getData($url),true);
71
-		if (!isset($weatherdata['main']['temp']) || !isset($weatherdata['weather'][0]['id'])) return array('clouds' => array(),'rain' => array());
73
+		if (!isset($weatherdata['main']['temp']) || !isset($weatherdata['weather'][0]['id'])) {
74
+			return array('clouds' => array(),'rain' => array());
75
+		}
72 76
 		$dew = $weatherdata['main']['temp'] - ((100-$weatherdata['main']['humidity'])/5);
73 77
 		$cumulus_base = 122.0 * ($weatherdata['main']['temp'] - $dew);
74 78
 		$stratus_base = 100.0 * (100.0 * $weatherdata['main']['humidity'])*0.3048;
@@ -104,7 +108,9 @@  discard block
 block discarded – undo
104 108
 	
105 109
 	public function nomad_wind($hour = '') {
106 110
 		global $globalWindsPath;
107
-		if ($hour == '') $hour = date('G');
111
+		if ($hour == '') {
112
+			$hour = date('G');
113
+		}
108 114
 		if (isset($globalWindsPath) && $globalWindsPath != '') {
109 115
 			$grib2json = $globalWindsPath['grib2json'];
110 116
 			$windpathsrc = $globalWindsPath['source'];
@@ -142,7 +148,9 @@  discard block
 block discarded – undo
142 148
 			system($grib2json.' --data --output '.$windpathdest.' --names --compact '.$windpathsrc);
143 149
 		} else {
144 150
 			// if not try previous run
145
-			if ($hour == date('G')) $this->nomad_wind(date('G')-6);
151
+			if ($hour == date('G')) {
152
+				$this->nomad_wind(date('G')-6);
153
+			}
146 154
 		}
147 155
 	}
148 156
 
Please login to merge, or discard this patch.