-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather34-airquality.php
100 lines (92 loc) · 4.79 KB
/
weather34-airquality.php
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
<?php include('livedata.php');
date_default_timezone_set($TZ);
####################################################################################################
# CREATED FOR HOMEWEATHERSTATION MB SMART TEMPLATE #
# https://weather34.com/homeweatherstation/index.html #
# #
# Revised: April 2020 #
# #
# https://www.weather34.com #
####################################################################################################
// PURPLE AIR additional conversion script included by Andrew Billits 24 April 2018
function pm25_to_aqi($pm25)
{
if ($pm25 > 500.5) {
$aqi = 500;
} elseif ($pm25 > 350.5 && $pm25 <= 500.5) {
$aqi = map($pm25, 350.5, 500.5, 400, 500);
} elseif ($pm25 > 250.5 && $pm25 <= 350.5) {
$aqi = map($pm25, 250.5, 350.5, 300, 400);
} elseif ($pm25 > 150.5 && $pm25 <= 250.5) {
$aqi = map($pm25, 150.5, 250.5, 200, 300);
} elseif ($pm25 > 55.5 && $pm25 <= 150.5) {
$aqi = map($pm25, 55.5, 150.5, 150, 200);
} elseif ($pm25 > 35.5 && $pm25 <= 55.5) {
$aqi = map($pm25, 35.5, 55.5, 100, 150);
} elseif ($pm25 > 12 && $pm25 <= 35.5) {
$aqi = map($pm25, 12, 35.5, 50, 100);
} elseif ($pm25 > 0 && $pm25 <= 12) {
$aqi = map($pm25, 0, 12, 0, 50);
}
return $aqi;
}
function map($value, $fromLow, $fromHigh, $toLow, $toHigh)
{
$fromRange = $fromHigh - $fromLow;
$toRange = $toHigh - $toLow;
$scaleFactor = $toRange / $fromRange;
// Re-zero the value within the from range
$tmpValue = $value - $fromLow;
// Rescale the value to the to range
$tmpValue *= $scaleFactor;
// Re-zero back to the to range
return $tmpValue + $toLow;
}
$json_string = file_get_contents("jsondata/purpleair.txt");
$parsed_json = json_decode($json_string);
$aqiweather["aqi"] = number_format(pm25_to_aqi(($parsed_json->{'results'}[0]->{'PM2_5Value'} + $parsed_json->{'results'}[1]->{'PM2_5Value'}) / 2), 1);
$aqiweather["aqiozone"] = 'N/A';
$aqiweather["time2"] = $parsed_json->{'results'}[0]->{'LastSeen'};
$aqiweather["time"] = date($timeFormat, $aqiweather["time2"]);
$aqiweather["city"] = $parsed_json->{'results'}[0]->{'ID'};
$aqiweather["label"] = $parsed_json->{'results'}[0]->{'Label'};
$a=""; if ($aqiweather["aqi"]==$a) {
$aqiweather["aqi"] = "0" ;
}
?>
<?php
echo '<div class="sunblock">';
echo '<div class="wudesc">'.$lang[ 'Air Quality'].'</div>
<div class="aqicon">';
//aq icon
if ($aqiweather["aqi"]>=300){echo "<purple><img src='aqi/hazair.svg?ver=1.4' width='110px' height='100px'>";}
else if ($aqiweather["aqi"]>=250){echo "<darkred><img src='aqi/vhair.svg?ver=1.4' width='110px' height='100px'>";}
else if ($aqiweather["aqi"]>=200){echo "<red><img src='aqi/vhair.svg?ver=1.4' width='110px' height='100px'>";}
else if ($aqiweather["aqi"]>=150){echo "<red><img src='aqi/uhair.svg?ver=1.4' width='110px' height='100px'>";}
else if ($aqiweather["aqi"]>=100){echo "<orange><img src='aqi/uhfsair.svg?ver=1.4' width='110px' height='100px'>";}
else if ($aqiweather["aqi"]>=50){echo "<yellow><img src='aqi/modair.svg?ver=1.4' width='110px' height='100px'>";}
else if ($aqiweather["aqi"]>=0){echo "<purple><img src='aqi/goodair.svg?ver=1.4' width='110px' height='100px'>";}
// icon description
echo '</div>
<div class="wuicondesc">';
//aq value
if ($aqiweather["aqi"]>=300){echo $lang[ 'Hazordous']." ".$aqalert;}
else if ($aqiweather["aqi"]>=250){echo $lang[ 'VeryUnhealthy']." ".$aqalert;}
else if ($aqiweather["aqi"]>=200){echo $lang[ 'VeryUnhealthy']." ".$aqalert;}
else if ($aqiweather["aqi"]>=150){echo $lang[ 'Unhealthy']." ".$aqalert;}
else if ($aqiweather["aqi"]>=100){echo $lang[ 'UnhealthyFS'];}
else if ($aqiweather["aqi"]>=50){echo $lang[ 'Moderate'];}
else if ($aqiweather["aqi"]>=0){echo $lang[ 'Good'];}
echo'</div><br>
<div class="wutemp">';
//aq value
if ($aqiweather["aqi"]>=300){echo "<purple>".$aqiweather["aqi"]."</purple>";}
else if ($aqiweather["aqi"]>=250){echo "<darkred>".$aqiweather["aqi"]."</darkred>";}
else if ($aqiweather["aqi"]>=200){echo "<red>".$aqiweather["aqi"]."</red>";}
else if ($aqiweather["aqi"]>=150){echo "<red>".$aqiweather["aqi"]."</red>";}
else if ($aqiweather["aqi"]>=100){echo "<orange>".$aqiweather["aqi"]."</orange";}
else if ($aqiweather["aqi"]>=50){echo "<yellow>".$aqiweather["aqi"]."</yellow>";}
else if ($aqiweather["aqi"]>=0){echo "<green>".$aqiweather["aqi"]."</green>";}
echo '<br>';
//aq description
echo '<div class=wuahead>PM 2.5';?></div></div></div></div>