Merge branch 'dev'

This commit is contained in:
Michael De Roover 2020-08-14 19:23:25 +02:00
commit 20300c8d72
Signed by: vim
GPG Key ID: 075496E232CE04CB
1 changed files with 29 additions and 26 deletions

55
cv
View File

@ -1,7 +1,7 @@
#!/bin/bash
# Variable declarations go here.
w=11
w=14
dfmt="+%Y-%m-%d"
data="$HOME/Documents/cv"
country=$1
@ -10,7 +10,7 @@ country=$1
[ -z $ydate ] && ydate=$(date -d yesterday $dfmt)
# Get yesterday's stats for queries after midnight.
if [ "$2" == "yesterday" ]
if [ ! -z $2 ]
then
date=$(date -d yesterday $dfmt)
ydate=$(date -d "2 days ago" $dfmt)
@ -22,7 +22,7 @@ ex(){
$@
}
title(){
local w=39
local w=48
printf "║ %-${w}s ║\n" "${*}"
}
@ -35,8 +35,8 @@ get(){
jq -r ".$1" < "$data/$date-$country"
fi
}
getpct(){
printf "║ %-${w}s ║ %${w}s ║ %-${w}s ║\n" "" "$(echo "$(bc <<< "scale = 1; $(get $1) / 10000") %")" ""
getpm(){
out "╰> Per 1M " "$(get $1) ($(echo "$(bc <<< "scale = 1; $(get $1) / 10000")%"))" ""
}
yget(){
date=$ydate
@ -47,36 +47,39 @@ yget(){
echo 0
fi
}
stats(){
out "$1:" "$(get $2)" "+ $(echo "scale = 2; $(get $2) - $(yget $2)" | bc)"
}
out(){
printf "║ %-${w}s ║ %${w}s ║ %-${w}s ║\n" "$1:" "$(get $2)" "+ $(echo "scale = 2; $(get $2) - $(yget $2)" | bc)"
printf "║ %-${w}s ║ %${w}s ║ %-${w}s ║\n" "$1" "$2" "$3"
}
frame(){
case "$1" in
top) printf "╔═════════════════════════════════════════╗\n" ;;
table) printf "║ Statistic ║ Today ║ Yesterday ║\n"
printf "╟─────────────╫─────────────╫─────────────╢\n" ;;
up) printf "╠═════════════╦═════════════╦═════════════╣\n" ;;
down) printf "╚═════════════╩═════════════╩═════════════╝\n" ;;
line) printf "╠═════════════╩═════════════╩═════════════╣\n" ;;
bot) printf "╚═════════════════════════════════════════╝\n" ;;
top) printf "╔══════════════════════════════════════════════════╗\n" ;;
sep) printf "╟────────────────╫────────────────╫────────────────╢\n" ;;
up) printf "╠════════════════╦════════════════╦════════════════╣\n" ;;
down) printf "╚════════════════╩════════════════╩════════════════╝\n" ;;
line) printf "╠════════════════╩════════════════╩════════════════╣\n" ;;
bot) printf "╚══════════════════════════════════════════════════╝\n" ;;
esac
}
result(){
frame top
title "Queried at: $date"
title "Queried at $date for $(get country)."
frame up
frame table
out Total cases
out "╰> Per 1M " casesPerOneMillion
out Active active
out Critical critical
out New todayCases
out Deaths deaths
out "╰> Per 1M " deathsPerOneMillion
out Recovered recovered
out Tests tests
out "╰> Per 1M " testsPerOneMillion
getpct testsPerOneMillion
out Statistic Today Yesterday
frame sep
stats Total cases
getpm casesPerOneMillion
stats New todayCases
frame sep
stats Active active
stats Critical critical
stats Deaths deaths
getpm deathsPerOneMillion
stats Recovered recovered
stats Tests tests
getpm testsPerOneMillion
if [ ! -f $data/$ydate-$country ] || [ $(get todayCases) == "0" ]
then
frame line