Skip to content

Instantly share code, notes, and snippets.

Created April 12, 2017 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/de5335892fcf011fb389a23d0782962f to your computer and use it in GitHub Desktop.
Save anonymous/de5335892fcf011fb389a23d0782962f to your computer and use it in GitHub Desktop.
#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