<?php
########################################################
#	CREATED FOR Meteobridge AURORA MKII TEMPLATE  		              						                
# 							Luftdaten				                        
# 	                                                                                               
# 	Release: 2024 January  	                                           
########################################################
include('livedata.php');
header('Content-type: text/html; charset=utf-8');
//luftdaten air quality	SCRIPT 
$url = 'jsondata/luftdaten.txt'; // luftdaten JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$weather34luftdaten = json_decode($data, true); // decode the JSON feed
foreach ($weather34luftdaten as $weather34luftdatenaqi) {
}
$aqiweather["aqi10"]     = $weather34luftdatenaqi['sensordatavalues'][0]['value'];
$aqiweather["aqi25"] = $weather34luftdatenaqi['sensordatavalues'][1]['value'];
$aqiweather["aqi-type"] = $weather34luftdatenaqi['sensordatavalues'][0]['value_type'];
$aqiweather["aqi-type-1"] = $weather34luftdatenaqi['sensordatavalues'][1]['value_type'];
if ($aqiweather["aqi-type"] == "P1") {
	$aqiweather["aqi-type"] = "PM 10"; 
}
if ($aqiweather["aqi-type"] == "P2") {
	$aqiweather["aqi-type"] = "PM 2.5";
}
if ($aqiweather["aqi-type-1"] == "P2") {
	$aqiweather["aqi-type-1"] = "PM 2.5";
}
if ($aqiweather["aqi-type-1"] == "P1") {
	$aqiweather["aqi-type-1"] = "PM 10";
}
$aqiweather["laqi"] = number_format(pm25_to_aqi($aqiweather["aqi25"]), 0);
$aqiweather["laqi10"] = number_format(pm25_to_aqi($aqiweather["aqi10"]), 0);


 //wood smoke for luftdateN luftdaten using actual current PM 2.5 EPA 
 $aqiweather["aqiwoodsmoke"]=number_format(($aqiweather["laqi"]), 1);//EPA
 $woodsmoke= number_format(0.55*$aqiweather["aqiwoodsmoke"]+0.53,1);
  $a=""; 
 //last hour trend
 $aqitrend =  $aqiweather["laqi"]  - $aqiweather["aqi1h"];


//AQ description caution

if ($aqiweather["laqi"]  >= 400) { $aqicautionlaq='Hazordous Air Quality';} 
else if ($aqiweather["laqi"] >= 300) {$aqicautionlaq='Very Unhealthy Air Quality';} 
else if ($aqiweather["laqi"] >= 200) {$aqicautionlaq='Unhealthy Air Quality';} 
else if ($aqiweather["laqi"] >= 150) {$aqicautionlaq='Poor Air Quality';} 
else if ($aqiweather["laqi"] >= 100) {$aqicautionlaq='Air Quality Caution';} 
else if ($aqiweather["laqi"] >= 50) {$aqicautionlaq='Moderate Air Quality';} 
else if ($aqiweather["laqi"] >= 0) {$aqicautionlaq='Good Air Quality';} 

//AQ ICON COLOR

if ($aqiweather["laqi"]>=300 ){$airlaqqualitycolor= " var(--purple)";}
else if ($aqiweather["laqi"]>=150 ){$airlaqqualitycolor= " var(--red)";}
else if ($aqiweather["laqi"]>=100 ){$airlaqqualitycolor= " var(--orange)";}
else if ($aqiweather["laqi"]>=50 ){$airlaqqualitycolor= " var(--yellow)";}
else if ($aqiweather["laqi"]>=0 ){$airlaqqualitycolor= " var(--green)";}
;

//AQ ICON
$laqairqualityicon="

<svg version='1.0' xmlns='http://www.w3.org/2000/svg'
width='40pt' height='40pt' viewBox='0 0 452.000000 452.000000'
preserveAspectRatio='xMidYMid meet' fill='none' stroke='#717F8C' stroke-width='25'>

<g transform='translate(0.000000,452.000000) scale(0.100000,-0.100000)'
 fill='none' stroke='#717F8C' stroke-width='25'>

<path fill='$airlaqqualitycolor' stroke='$airlaqqualitycolor' d='M920 4421 c-76 -23 -140 -79 -174 -151 -20 -44 -21 -58 -24 -598 -3
-518 -4 -553 -20 -547 -113 43 -479 125 -561 125 l-51 0 0 -90 0 -90 41 0 c61
0 264 -43 434 -93 l150 -44 3 -268 c2 -252 1 -267 -15 -262 -240 70 -423 112
-541 123 l-72 7 0 -92 0 -91 28 0 c77 0 304 -51 532 -121 l70 -21 0 -269 0
-268 -42 15 c-128 45 -490 124 -572 124 -14 0 -16 -14 -16 -89 l0 -90 48 -6
c114 -14 238 -41 382 -83 85 -24 165 -47 177 -49 l22 -5 3 -597 c3 -584 3
-597 24 -641 26 -54 74 -104 128 -133 l41 -22 1345 0 1345 0 40 22 c54 28 119
100 136 149 11 31 14 132 14 493 l0 454 -79 23 c-44 13 -84 24 -88 24 -4 0 -8
-203 -8 -450 0 -491 -2 -510 -55 -530 -36 -14 -2574 -14 -2610 0 -58 22 -55
-91 -55 1980 0 2071 -3 1958 55 1980 36 14 2574 14 2610 0 54 -21 55 -31 55
-615 0 -294 -2 -535 -5 -535 -2 0 -80 23 -172 51 -297 90 -367 103 -543 103
-194 1 -225 -7 -685 -179 -181 -67 -370 -133 -420 -146 -158 -40 -281 -29
-578 55 -70 20 -129 36 -132 36 -3 0 -5 -42 -5 -94 l0 -95 53 -15 c120 -35
298 -74 386 -86 195 -25 338 9 801 190 372 146 453 166 618 157 119 -7 262
-39 497 -112 506 -158 748 -221 933 -240 l62 -7 0 90 0 90 -31 6 c-17 3 -43 6
-58 6 -37 0 -220 42 -393 91 l-147 41 -3 597 c-3 584 -3 597 -24 641 -26 54
-74 104 -128 133 l-41 22 -1330 2 c-731 1 -1341 -2 -1355 -6z'/>

<path fill='$airlaqqualitycolor' stroke='$airlaqqualitycolor' d='M2720 2510 c-123 -27 -190 -49 -525 -175 -464 -173 -529 -186 -745
-141 -69 14 -178 41 -243 60 -87 25 -120 31 -123 22 -3 -7 -4 -50 -2 -96 l3
-83 80 -23 c193 -57 314 -77 455 -78 182 -1 263 21 680 184 464 181 562 197
830 136 106 -25 151 -38 555 -160 348 -106 604 -166 706 -166 l39 0 0 90 0 90
-32 0 c-91 0 -444 90 -873 223 -432 134 -609 160 -805 117z'/>

<path fill='$airlaqqualitycolor' stroke='$airlaqqualitycolor'  d='M2765 1795 c-124 -22 -224 -54 -520 -165 -322 -120 -424 -155 -504
-170 -124 -23 -258 -6 -511 65 -69 19 -131 35 -137 35 -10 0 -13 -25 -13 -90
0 -106 -13 -94 160 -139 238 -62 406 -76 552 -46 102 21 260 74 483 162 377
149 480 177 635 176 134 -1 260 -29 571 -127 470 -149 713 -212 862 -223 l87
-6 0 92 0 91 -38 0 c-102 0 -420 81 -847 215 -299 94 -538 146 -660 144 -27 0
-81 -7 -120 -14z'/>
</g>
</svg>
";
?>



<style>
.module {display: grid; 
position: absolute;
font-size:14px;
font-family:verb;
color: var(--body-text-dark);
}

.laqairqualitycaution{position:absolute;
font-size:10px;
font-family:verb;
color: var(--body-text-dark);
display: inline;
margin-left:-110px;
margin-top:-40px;
background:var(--hilomodule);
width: max-content;
max-width:150px; 
padding:4px;
border-radius: 5px;opacity:.8


}
 

.laqairqualityvalue{
	position: absolute;
    font-size:38px;
    font-family:verb;
    background:var(--hilomodule);
    width:max-content;
    height:max-content;
 margin-left:-100px;
border-radius: 5px;
 margin-top:-80px;
 display: block;
 padding-right:3px;
 padding-left:5px;
 padding-bottom:5px;
 color:var(--body-text-dark);opacity:.8

}
.laqairqualityvalue span{
font-size:7px;
vertical-align: super;
text-align: center;


}

.laqairqualityvalue span2{
font-size:10px;
display: block;


}


.laqairqualitydescription{
position: absolute;
font-size:10px;
font-family:verb;
background:var(--hilomodule);
width:180px;
margin-left:-110px;
border-radius: 5px;
margin-top:-10px;
display: block;
padding:3px;
color:var(--body-text-dark);opacity:.9

}

.laqairqualityicon{position: absolute;
margin-left:60px;
margin-top:-80px}


.charticonlaq { position: absolute;
font-size:11px;
font-family:verb;
background:none;
width:auto;
margin-left:90px;
border-radius: 5px;
margin-top:20px;
display: block;
padding-right:3px;
color:var(--body-text-dark);
z-index:10;}
.sensorLAQcaption{position: absolute;
 margin-left:30px;
 margin-top:-92px;
 font-size:9px;
 color:var(--body-text-dark);
 opacity: 0.64;
 width:max-content;
 font-family:verb;
 }

</style>

<div class=module>
<div class=sensorLAQcaption>Air Quality</div>
<div class="laqairqualityvalue"><?php 
//forecast temperature
echo " ".number_format($aqiweather["laqi"] ,0)." <span>PM 2.5</span> ";
?>
<span2>
<?php echo $aqicautionlaq;?>
</span2>

</div>


<div class=laqairqualityicon>
<?php //icon forecast
echo $laqairqualityicon
;?>
</div>


<div class="laqairqualitydescription"> 
<?php 
echo "Luftdaten<br>";
echo "PM1O: ". $aqiweather["laqi10"] ."<br>";
if ($aqiweather["voc"]==0) {echo "CO2: No Data<br>";}
else echo "CO2: ". $laqiweather["voc"] ."<br>";
echo "Woodsmoke: ". $woodsmoke ;?>
</div>

<div class=charticonlaq> 
<a href="luftdaten-air-quality-almanac2.php" data-lity data-chartdata="Chart Data">
<?php echo $weather34chartzoomtabletfull;?></a>
</div></div>