From a55248f232fb2fb5639837b065c5f27852b37311 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Wed, 12 Aug 2020 13:47:44 +0200 Subject: [PATCH 1/5] Allow option for yesterday's stats to contain any value --- cv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cv b/cv index dcf874e..651fc9f 100755 --- a/cv +++ b/cv @@ -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) From a01fb55a86e3b1bfad887d65f7b32c9f627bbc94 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Fri, 14 Aug 2020 15:25:47 +0200 Subject: [PATCH 2/5] Refactor out function in cv --- cv | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/cv b/cv index 651fc9f..d92a9de 100755 --- a/cv +++ b/cv @@ -36,7 +36,7 @@ get(){ fi } getpct(){ - printf "║ %-${w}s ║ %${w}s ║ %-${w}s ║\n" "" "$(echo "$(bc <<< "scale = 1; $(get $1) / 10000") %")" "" + out "" "$(echo "$(bc <<< "scale = 1; $(get $1) / 10000") %")" "" } yget(){ date=$ydate @@ -47,8 +47,11 @@ 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 @@ -66,16 +69,16 @@ result(){ title "Queried at: $date" 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 + stats Total cases + stats "╰> Per 1M " casesPerOneMillion + stats Active active + stats Critical critical + stats New todayCases + stats Deaths deaths + stats "╰> Per 1M " deathsPerOneMillion + stats Recovered recovered + stats Tests tests + stats "╰> Per 1M " testsPerOneMillion getpct testsPerOneMillion if [ ! -f $data/$ydate-$country ] || [ $(get todayCases) == "0" ] then From 5bbfc4ad7768c7f493573044f496052db7c6c367 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Fri, 14 Aug 2020 15:47:49 +0200 Subject: [PATCH 3/5] Reorder the stats in cv and prioritize some --- cv | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cv b/cv index d92a9de..1f7b83b 100755 --- a/cv +++ b/cv @@ -56,8 +56,8 @@ out(){ frame(){ case "$1" in top) printf "╔═════════════════════════════════════════╗\n" ;; - table) printf "║ Statistic ║ Today ║ Yesterday ║\n" - printf "╟─────────────╫─────────────╫─────────────╢\n" ;; + title) printf "║ Statistic ║ Today ║ Yesterday ║\n" ;; + sep) printf "╟─────────────╫─────────────╫─────────────╢\n" ;; up) printf "╠═════════════╦═════════════╦═════════════╣\n" ;; down) printf "╚═════════════╩═════════════╩═════════════╝\n" ;; line) printf "╠═════════════╩═════════════╩═════════════╣\n" ;; @@ -68,12 +68,14 @@ result(){ frame top title "Queried at: $date" frame up - frame table + frame title + frame sep stats Total cases stats "╰> Per 1M " casesPerOneMillion + stats New todayCases + frame sep stats Active active stats Critical critical - stats New todayCases stats Deaths deaths stats "╰> Per 1M " deathsPerOneMillion stats Recovered recovered From 36c655cec03e4b91f50720e1cd05b3485c342fe0 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Fri, 14 Aug 2020 16:21:50 +0200 Subject: [PATCH 4/5] Merge percentage and per 1M stats --- cv | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/cv b/cv index 1f7b83b..929a21c 100755 --- a/cv +++ b/cv @@ -1,7 +1,7 @@ #!/bin/bash # Variable declarations go here. -w=11 +w=14 dfmt="+%Y-%m-%d" data="$HOME/Documents/cv" country=$1 @@ -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(){ - out "" "$(echo "$(bc <<< "scale = 1; $(get $1) / 10000") %")" "" +getpm(){ + out "╰> Per 1M " "$(get $1) ($(echo "$(bc <<< "scale = 1; $(get $1) / 10000")%"))" "" } yget(){ date=$ydate @@ -55,13 +55,13 @@ out(){ } frame(){ case "$1" in - top) printf "╔═════════════════════════════════════════╗\n" ;; - title) printf "║ Statistic ║ Today ║ Yesterday ║\n" ;; - sep) printf "╟─────────────╫─────────────╫─────────────╢\n" ;; - up) printf "╠═════════════╦═════════════╦═════════════╣\n" ;; - down) printf "╚═════════════╩═════════════╩═════════════╝\n" ;; - line) printf "╠═════════════╩═════════════╩═════════════╣\n" ;; - bot) printf "╚═════════════════════════════════════════╝\n" ;; + top) printf "╔══════════════════════════════════════════════════╗\n" ;; + title) printf "║ Statistic ║ Today ║ Yesterday ║\n" ;; + sep) printf "╟────────────────╫────────────────╫────────────────╢\n" ;; + up) printf "╠════════════════╦════════════════╦════════════════╣\n" ;; + down) printf "╚════════════════╩════════════════╩════════════════╝\n" ;; + line) printf "╠════════════════╩════════════════╩════════════════╣\n" ;; + bot) printf "╚══════════════════════════════════════════════════╝\n" ;; esac } result(){ @@ -71,17 +71,16 @@ result(){ frame title frame sep stats Total cases - stats "╰> Per 1M " casesPerOneMillion + getpm casesPerOneMillion stats New todayCases frame sep stats Active active stats Critical critical stats Deaths deaths - stats "╰> Per 1M " deathsPerOneMillion + getpm deathsPerOneMillion stats Recovered recovered stats Tests tests - stats "╰> Per 1M " testsPerOneMillion - getpct testsPerOneMillion + getpm testsPerOneMillion if [ ! -f $data/$ydate-$country ] || [ $(get todayCases) == "0" ] then frame line From fe071e82a638d9baa9dd8a539f79a5adda0b7fdc Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Fri, 14 Aug 2020 19:22:39 +0200 Subject: [PATCH 5/5] Replace frame title with out function --- cv | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cv b/cv index 929a21c..7dbfbd5 100755 --- a/cv +++ b/cv @@ -56,7 +56,6 @@ out(){ frame(){ case "$1" in top) printf "╔══════════════════════════════════════════════════╗\n" ;; - title) printf "║ Statistic ║ Today ║ Yesterday ║\n" ;; sep) printf "╟────────────────╫────────────────╫────────────────╢\n" ;; up) printf "╠════════════════╦════════════════╦════════════════╣\n" ;; down) printf "╚════════════════╩════════════════╩════════════════╝\n" ;; @@ -66,9 +65,9 @@ frame(){ } result(){ frame top - title "Queried at: $date" + title "Queried at $date for $(get country)." frame up - frame title + out Statistic Today Yesterday frame sep stats Total cases getpm casesPerOneMillion