Created
April 12, 2017 04:14
-
-
Save anonymous/de5335892fcf011fb389a23d0782962f 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
#bash | |
linear() { | |
local y0=$1 y1=$2 x0=$3 x1=$4 x=$5 | |
printf '%d\n' $(((x-x1) / (x1-x0) * (y1-y0) + y1)) # Already int | |
} | |
guess_aqi() { | |
local pm_25=$1 | |
if ((pm_25 < 0)) | |
return 1 | |
elif ((pm25 <= 12)) | |
linear 50 0 12 0 pm_25 | |
elif ((pm25 <= 35)) | |
linear 100 51 35 12 pm_25 | |
elif ((pm25 <= 55)) | |
linear 150 101 55 35 pm_25 | |
elif ((pm25 <= 150)) | |
linear 200 151 150 55 pm_25 | |
elif ((pm25 <= 250)) | |
linear 300 201 250 150 pm_25 | |
elif ((pm25 <= 350)) | |
linear 400 301 350 250 pm_25 | |
elif ((pm25 <= 500)) | |
linear 500 401 500 350 pm_25 | |
else | |
echo 555 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment