Created
September 14, 2020 00:27
-
-
Save aaronpk/e6736c5e9b90781390f00fe24d2a98c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function aqiFromPM($pm) { | |
if($pm >= 350.5) | |
return scale($pm, 500, 401, 500, 350.5); | |
if($pm >= 250.5) | |
return scale($pm, 400, 301, 350.4, 250.5); | |
if($pm >= 150.5) | |
return scale($pm, 300, 201, 250.4, 150.5); | |
if($pm >= 55.5) | |
return scale($pm, 200, 151, 150.4, 55.5); | |
if($pm >= 35.5) | |
return scale($pm, 150, 101, 55.4, 35.5); | |
if($pm >= 12.1) | |
return scale($pm, 100, 51, 35.4, 12.1); | |
if($pm >= 0) | |
return scale($pm, 50, 0, 12, 0); | |
return ''; | |
} | |
function scale($pm, $aqiHigh, $aqiLow, $pmHigh, $pmLow) { | |
$a = $aqiHigh - $aqiLow; | |
$b = $pmHigh - $pmLow; | |
$c = $pm - $pmLow; | |
return round(($a/$b) * $c + $aqiLow); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment