diff options
| author | Robert Günzler <r@gnzler.io> | 2022-04-15 15:35:23 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2022-04-15 15:35:23 +0200 |
| commit | 5251f51bf91cf8cecef4a553ac75bd3a0b2fc20d (patch) | |
| tree | b0d51ffbc00844ffc403c62d261216901a55fabb | |
| parent | cd36fcff9a7aba08596a88995f9e9fcba6a3d61e (diff) | |
waybar/modules/covid: update (not sure if this works)
| -rwxr-xr-x | .config/waybar/modules/covid.sh | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/.config/waybar/modules/covid.sh b/.config/waybar/modules/covid.sh index e44c108..46727d7 100755 --- a/.config/waybar/modules/covid.sh +++ b/.config/waybar/modules/covid.sh @@ -17,14 +17,18 @@ done # incidence = (sumCasesLast7Days / EWZ) * 100000 lat=${HOME_LAT:?} lon=${HOME_LON:?} -fields='GEN,RS,EWZ,EWZ_BL,BL_ID,cases,cases_per_100k,cases7_per_100k,cases7_bl_per_100k,last_update,BL,IBZ' +# fields='GEN,RS,EWZ,EWZ_BL,BL_ID,cases,cases_per_100k,cases7_per_100k,cases7_bl_per_100k,last_update,BL,IBZ' +fields='GEN,cases7_bl_per_100k' # see https://experience.arcgis.com/experience/478220a4c454480e823b17327b2bf1d4 uri="https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=${fields}&geometry=${lon}%2C${lat}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json" _data=$(curl -sSL -H 'Accept: application/json' ${curl_args} "${uri}" | jq -r '.features[0].attributes') -[ -z "${_data}" ] && printf "{}\n" +if [ "${_data}" = "null" ]; then + printf "{}\n" + exit 0 +fi -HISTFILE=${HOME}/covid-history.csv +historical_data=${HOME}/covid-history.csv loc=$(printf "%s" "${_data}" | jq -r '.GEN') last_update=$(printf "%s" "${_data}" | jq -r '.last_update') # printf "${_data}" | jq -r '.' @@ -35,15 +39,15 @@ incidence_i=$(printf "%.0f" "${incidence_f}") if [ -n "${last_update}" ] && [ -n "${incidence_f}" ]; then tmp_HISTFILE=$(mktemp -u --tmpdir waybar-module-covid.XXXXX) ( - cat "${HISTFILE}" + cat "${historical_data}" ts=$(printf "%s" "${last_update}" | cut -d',' -f1 | tr '.' '-') printf "%s,%s\n" "${ts}" "${incidence_f}" ) | uniq | tee "${tmp_HISTFILE}" >/dev/null - flock -x "${HISTFILE}" mv "${tmp_HISTFILE}" "${HISTFILE}" + flock -x "${historical_data}" mv "${tmp_HISTFILE}" "${historical_data}" fi -mxy=$(tail -n 7 "${HISTFILE}" | awk -F',' '{y=y+$2} END{print ((NR*(NR+1))/2)/NR, y/NR}') -trend=$(awk -F',' --assign="mx=$(printf "%s" "$mxy" | cut -d' ' -f1)" --assign="my=$(printf "%s" "$mxy" | cut -d' ' -f2)" '{up= up+(NR-mx)*($2-my); down= down+(NR-mx)**2} END{if(down==0){print 0}else{print up/down};}' "${HISTFILE}") +mxy=$(tail -n 7 "${historical_data}" | awk -F',' '{y=y+$2} END{print ((NR*(NR+1))/2)/NR, y/NR}') +trend=$(awk -F',' --assign="mx=$(printf "%s" "$mxy" | cut -d' ' -f1)" --assign="my=$(printf "%s" "$mxy" | cut -d' ' -f2)" '{up= up+(NR-mx)*($2-my); down= down+(NR-mx)**2} END{if(down==0){print 0}else{print up/down};}' "${historical_data}") trend_arrow="" [ "$(printf "%.0f" "${trend}")" -gt 0 ] && trend_arrow="" [ "$(printf "%.0f" "${trend}")" -lt 0 ] && trend_arrow="" @@ -71,13 +75,11 @@ if [ "${incidence_i}" -gt "250" ]; then color='darkdarkred' fi -tooltip=" -7 Tage Inzidenz für ${loc} +tooltip="7 Tage Inzidenz für ${loc} last update: ${last_update} history (${trend_arrow}): -$(awk -F, '{print $1 " " $2}' "${HISTFILE}" | tail -n10 | tac) -" +$(awk -F, '{print $1 " " $2}' "${historical_data}" | tail -n10 | tac)" jq -nr \ "{ text: \"${trend_arrow}${incidence_f}\", percentage: \"${incidence_i}\", class: \"${color}\", alt: \"${color}\", tooltip: \"${tooltip}\" } | @text" |