diff options
| author | Robert Günzler <r@gnzler.io> | 2026-02-10 12:32:48 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-02-10 12:41:25 +0100 |
| commit | 63feeb9f369fc6176e85c1c2d8fcc863caad1946 (patch) | |
| tree | 41cd5d2d1ec36e74e464caab722cc9b460153f04 /.config/waybar/modules/covid.sh | |
| parent | 5bd0a4aca65ecb9818ef1285982d160b6b6ff665 (diff) | |
start new
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.config/waybar/modules/covid.sh')
| -rwxr-xr-x | .config/waybar/modules/covid.sh | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/.config/waybar/modules/covid.sh b/.config/waybar/modules/covid.sh deleted file mode 100755 index 46727d7..0000000 --- a/.config/waybar/modules/covid.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/sh - -set -e -[ -n "$DEBUG" ] && { - set -x - curl_args='-v' -} - -# check requirements -for tool in awk curl jq flock; do - if ! command -v "$tool" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 - exit 1 - fi -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,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') -if [ "${_data}" = "null" ]; then - printf "{}\n" - exit 0 -fi - -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 '.' -incidence_f=$(printf "%.1f" "$(printf "%s" "${_data}" | jq -r '.cases7_bl_per_100k')") -incidence_i=$(printf "%.0f" "${incidence_f}") - -# store -if [ -n "${last_update}" ] && [ -n "${incidence_f}" ]; then - tmp_HISTFILE=$(mktemp -u --tmpdir waybar-module-covid.XXXXX) - ( - 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 "${historical_data}" mv "${tmp_HISTFILE}" "${historical_data}" -fi - -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="" - -color='green' -if [ "${incidence_i}" -eq "0" ]; then - color='gray' -fi -if [ "${incidence_i}" -gt "1" ]; then - color='green' -fi -if [ "${incidence_i}" -gt "25" ]; then - color='yellow' -fi -if [ "${incidence_i}" -gt "35" ]; then - color='orange' -fi -if [ "${incidence_i}" -gt "50" ]; then - color='red' -fi -if [ "${incidence_i}" -gt "100" ]; then - color='darkred' -fi -if [ "${incidence_i}" -gt "250" ]; then - color='darkdarkred' -fi - -tooltip="7 Tage Inzidenz für ${loc} -last update: ${last_update} - -history (${trend_arrow}): -$(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" |