Skip to content

Instantly share code, notes, and snippets.

/aqiguess.sh
Created Apr 12, 2017

Embed
What would you like to do?
#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
You can’t perform that action at this time.