forked from schwarzwaldgeier/wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeasurements.php
More file actions
executable file
·206 lines (172 loc) · 4.96 KB
/
measurements.php
File metadata and controls
executable file
·206 lines (172 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
class Measurement
{
public $value;
public $unit;
public $trafficlight = array(
"green" => "#b0f4b0",
"yellow" => "#ffff99",
"red" => "#ff9999"
);
}
class Wind_speed extends Measurement
{
private $timmfactor = 1.3;
public $original_value;
public $color;
public function __construct($windspeed)
{
$this->value = $windspeed;
$this->unit = "km/h";
$this->original_value = $windspeed * $this->timmfactor;
$this->GetQuality();
}
private function GetQuality()
{
$val = $this->value;
if ($val <= 18) $this->color = $this->trafficlight['green'];
else if ($val <= 25) $this->color = $this->trafficlight['yellow'];
else $this->color = $this->trafficlight['red'];
}
}
class Wind_Direction extends Measurement
{
public $name_short;
public $name_long;
public $svg_arrow;
public $color;
// suitability at best takeoff
public $best_takeoff;
public function __construct($direction)
{
$this->value = $direction;
$this->unit = "°";
$this->name_long = $this->getCompassPointName("long");
$this->name_short = $this->GetCompassPointName('short');
$this->svg_arrow = $this->GetWindDirectionArrow();
}
private function GetCompassPointName($type)
{
/*
http://stackoverflow.com/a/7490772
Divide the angle by 22.5 because 360deg/16 directions = 22.5deg/direction change.
Add .5 so that when you truncate the value you can break the 'tie' between the change threshold.
Truncate the value using integer division (so there is no rounding).
Directly index into the array and print the value (mod 16).
*/
$namesShort = array(
"N",
"NNO",
"NO",
"ONO",
"O",
"OSO",
"SO",
"SSO",
"S",
"SSW",
"SW",
"WSW",
"W",
"WNW",
"NW",
"NNW"
);
$namesLong = array(
"Nord",
"Nord-Nordost",
"Nordost",
"Ost-Nordost",
"Ost",
"Ost-Südost",
"Südost",
"Süd-Südost",
"Süd",
"Süd-Südwest",
"Südwest",
"West-Südwest",
"West",
"West-Südwest",
"West",
"West-Nordwest",
"Nordwest",
"Nord-Nordwest"
);
$val = ($this->value / 22.5) + 0.5;
$val = intval($val);
if ($type = "short") return $namesShort[$val % 16];
else return $namesLong[$val % 16];
}
private function GetWindDirectionArrow()
{
$html = '<svg width="32px" height="32px" xmlns="http://www.w3.org/2000/svg">';
$html.= '<g>';
$html.= '<title>Windrichtung</title>';
$html.= '<g transform="rotate(' . round($this->value, 0) . ' , 16, 16)" >';
$html.= '<path fill="#000000" d="m21,4l-10,0l5,24"/>';
$html.= '</g>';
$html.= '</g>';
$html.= '</svg>';
return $html;
}
public function GetBestTakeoff($takeoffs)
{
foreach($takeoffs as $takeoff)
{
if (($this->value > $takeoff->winddirection_levels[1][0]) && ($this->value < $takeoff->winddirection_levels[1][1])) //return takeoff if value is within boundaries
{
$this->best_takeoff = $takeoff;
if (($this->value > $takeoff->winddirection_levels[1][0]) && ($this->value < $takeoff->winddirection_levels[1][1])) //check if we are also within the easy zone
{
$this->color = $this->trafficlight['green'];
}
else
$this->color = $this->trafficlight['yellow'];; //we're not in the green zone, but still good.
return $takeoff;
}
}
//no takeoff suitable;
$this->best_takeoff = -1;
$this->color = $this->trafficlight['red'];
return -1;
}
}
class Temperature extends Measurement
{
public function __construct($temperature)
{
$this->value = $temperature;
$this->unit = "°C";
}
}
class Pressure extends Measurement
{
public function __construct($pressure)
{
$this->value = $pressure;
$this->unit = "hPa";
}
}
class Wind_Chill extends Measurement
{
public function __construct($windchill)
{
$this->value = $windchill;
$this->unit = "°C";
}
}
class Takeoff
{
public $name;
// array
public $windspeed_levels;
// 2d array
public $winddirection_levels;
public function __construct($name, $speeds, $directions)
{
$this->name=$name;
$this->windspeed_levels = $speeds;
$this->winddirection_levels = $directions;
}
}
?>