Completed
Push — master ( a1da1d...8368ca )
by Yannick
29:52
created

Weather::nomad_wind()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 34
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 29
nc 8
nop 0
dl 0
loc 34
rs 8.439
c 0
b 0
f 0
1
<?php
2
require_once(dirname(__FILE__).'/class.Common.php');
3
class Weather {
4
	public function buildcloudlayer($metar) {
5
		//print_r($metar);
6
		$result = array();
7
		foreach($metar['cloud'] as $key => $data) {
8
			$alt_m = $metar['cloud'][$key]['level'];
9
			$alt_ft = $alt_m*3.28084;
10
			$pressure = $metar['QNH'];
11
			$cumulus_base = 122.0 * ($metar['temperature'] - $metar['dew']);
12
			$stratus_base = 100.0 * (100.0 * $metar['rh'])*0.3048;
13
			$coverage_norm = 0.0;
14
			if ($metar['cloud'][$key]['type'] == 'Few') {
15
				$coverage_norm = 2.0/8.0;
16
			} elseif ($metar['cloud'][$key]['type'] == 'Scattered') {
17
				$coverage_norm = 4.0/8.0;
18
			} elseif ($metar['cloud'][$key]['type'] == 'Broken') {
19
				$coverage_norm = 6.0/8.0;
20
			} elseif ($metar['cloud'][$key]['type'] == 'Overcast/Full cloud coverage') {
21
				$coverage_norm = 8.0/8.0;
22
			}
23
			$layer_type = 'nn';
0 ignored issues
show
Unused Code introduced by
$layer_type is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
			if ($metar['cloud'][$key]['significant'] == 'cirrus') {
25
				$layer_type = 'ci';
26
			} elseif ($alt_ft > 16500) {
27
				$layer_type = 'ci';
28
			} elseif ($alt_ft > 6500) {
29
				$layer_type = 'ac';
30
				if ($pressure < 1005.0 && $coverage_norm >= 0.5) {
31
					$layer_type = 'ns';
32
				}
33
			} else {
34
				if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) {
35
					$layer_type = 'cu';
36
				} elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) {
37
					$layer_type = 'st';
38
				} else {
39
					if ($alt_ft < 2000) {
40
						$layer_type = 'st';
41
					} elseif ($alt_ft < 4500) {
42
						$layer_type = 'cu';
43
					} else {
44
						$layer_type = 'sc';
45
					}
46
				}
47
			}
48
			//echo 'coverage norm : '.$coverage_norm.' - layer_type: '.$layer_type."\n";
49
			$result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $metar['rh']);
50
		}
51
		if (count($result) < 2 && $metar['rh'] > 60) {
52
			$result[] = array('cov' => 0.75, 'type' => 'ci','alt' => 4000,'rh' => $metar['rh']);
53
		}
54
		return $result;
55
	}
56
	
57
	public function nomad_wind() {
58
		global $globalWindsPath;
59
		if (isset($globalWindsPath) && $globalWindsPath != '') {
60
			$grib2json = $globalWindsPath['grib2json'];
0 ignored issues
show
Unused Code introduced by
$grib2json is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
			$windpathsrc = $globalWindsPath['source'];
62
			$windpathdest = $globalWindsPath['destination'];
63
		} else {
64
			$grib2json = dirname(__FILE__).'/libs/grib2json/bin/grib2json';
0 ignored issues
show
Unused Code introduced by
$grib2json is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
65
			$windpathsrc = dirname(__FILE__).'/../data/winds.gb2';
66
			$windpathdest = dirname(__FILE__).'/../data/winds.json';
67
		}
68
		
69
		// 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
70
		$resolution = '0.5';
71
		$baseurl = 'http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_'.($resolution === '1' ? '1p00':'0p50').'.pl';
72
		$get = array('file' => 'gfs.t'.sprintf('%02d',(6*floor(date('G')/6))).($resolution === '1' ? 'z.pgrb2.1p00.f000' : 'z.pgrb2full.0p50.f000'),
73
			'lev_10_m_above_ground' => 'on',
74
			'lev_surface' => 'on',
75
			'var_TMP' => 'on',
76
			'var_UGRD' => 'on',
77
			'var_VGRD' => 'on',
78
			'leftlon' => 0,
79
			'rightlon' => 360,
80
			'toplat' => 90,
81
			'bottomlat' => -90,
82
			'dir' => '/gfs.'.date('Ymd').sprintf('%02d',(6*floor(date('G')/6)))
83
		);
84
		$url = $baseurl.'?'.http_build_query($get);
85
		echo $url;
86
		$Common = new Common();
87
		$Common->download($url,$windpathsrc);
88
		$grib2json = dirname(__FILE__).'/libs/grib2json/bin/grib2json';
89
		system($grib2json.' --data --output '.$windpathdest.' --names --compact '.$windpathsrc);
90
	}
91
}
92
/*
93
require_once('class.METAR.php');
94
$METAR = new METAR();
95
*/
96
/*
97
$themetar = $METAR->getMETAR('LFLL');
98
print_r($themetar);
99
$result = $METAR->parse($themetar[0]['metar']);
100
*/
101
/*
102
$result = $METAR->parse('LFLL 081330Z 01006KT 340V050 9999 FEW020 BKN080 07/01 Q1018 NOSIG');
103
print_r($result);
104
$Weather = new Weather();
105
//print_r($Weather->buildcloudlayer($result));
106
//print_r($Weather->buildcloud('46.3870','5.2941','2000','0.25'));
107
print_r($Weather->generateRandomPoint('46.3870','5.2941','2000'));
108
*/
109
/*
110
$Weather = new Weather();
111
$Weather->nomad_wind();
112
*/
113
?>