Skip to content

Instantly share code, notes, and snippets.

@BryantD
Last active February 19, 2022 19:59
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 BryantD/c49f5016c51d90475710b4999a205d9e to your computer and use it in GitHub Desktop.
Save BryantD/c49f5016c51d90475710b4999a205d9e to your computer and use it in GitHub Desktop.
#!/bin/zsh
zmodload zsh/mathfunc
VERBOSE=1
STATE=washington
STATE_CENSUS=53
COUNTY=king
COUNTY_CENSUS=033
START=$( date -v-9d '+%-m/%-d/%y' )
END=$( date -v-1d '+%-m/%-d/%y' )
## Case numbers
JSON=$( curl --silent "https://disease.sh/v3/covid-19/historical/usacounties/${STATE}?lastdays=10" -H "accept: application/json" )
JQ_START_QUERY=".[] | select(.county == \"${COUNTY}\") | .timeline.cases.\"$START\""
JQ_END_QUERY=".[] | select(.county == \"${COUNTY}\") | .timeline.cases.\"$END\""
JQ_START_VALUE=$( echo $JSON | jq "$JQ_START_QUERY" )
JQ_END_VALUE=$( echo $JSON | jq "$JQ_END_QUERY" )
C_DELTA=$(( $JQ_END_VALUE - $JQ_START_VALUE ))
if [[ $VERBOSE ]]; then
printf "Case Delta: %'d\n" ${C_DELTA}
fi
## Population
# Seems to work without an API key, despite the docs
# State and county parameters are hardcoded, see following URL to find others
# https://www.census.gov/data/developers/guidance/api-user-guide/example-api-queries.html
POP_JSON=$( curl --silent "https://api.census.gov/data/2019/pep/charagegroups?get=POP&for=county%3A${COUNTY_CENSUS}&in=state%3A${STATE_CENSUS}" )
POP=$( echo $POP_JSON | jq '.[1][0] | tonumber' )
POP_100K=$(( $POP / 100000.0 ))
if [[ $VERBOSE ]]; then
printf "Population: %'d\n" ${POP}
fi
## Math
TPR=$(( $C_DELTA / $POP_100K ))
if [[ $VERBOSE ]]; then
printf "\n"
fi
printf "Weekly Cases/100K: %.2f\n\n" ${TPR}
if [[ TPR -ge 100 ]]; then
printf "Red (>=100): mask indoors, avoid dining\n"
elif [[ TPR -ge 50 ]]; then
printf "Orange (>=50): mask indoors, dining OK\n"
elif [[ TPR -ge 10 ]]; then
printf "Yellow (>=10): no masking\n"
else
printf "Blue (<10): no precautions\n"
fi
if [[ $VERBOSE ]]; then
printf "Data: https://disease.sh & https://api.census.gov/\n"
printf "Thresholds: https://yourlocalepidemiologist.substack.com/p/riding-the-waves-a-framework-for\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment