about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-06-14 21:22:06 +0530
committerAndinus <andinus@nand.sh>2020-06-14 21:24:23 +0530
commitd19834d8829b50b688b16c1f7f5e979f36d6f569 (patch)
treed7b97dfe62dd72e9e994870fe26bb01706c7d07d
parent7c5d71cce3654d8cb06aec8be0f1753592b538fb (diff)
downloadara-d19834d8829b50b688b16c1f7f5e979f36d6f569.tar.gz
Format numbers with Number::Format::SouthAsian, add to cpanfile
-rwxr-xr-xara.pl42
-rw-r--r--cpanfile1
2 files changed, 27 insertions, 16 deletions
diff --git a/ara.pl b/ara.pl
index 4027c49..f73d481 100755
--- a/ara.pl
+++ b/ara.pl
@@ -6,6 +6,7 @@ use warnings;
 use Path::Tiny;
 use Time::Moment;
 use Text::ASCIITable;
+use Number::Format::SouthAsian;
 use Getopt::Long qw( GetOptions );
 use JSON::MaybeXS qw( decode_json );
 use Term::ANSIColor qw( :pushpop );
@@ -197,6 +198,11 @@ if ( $state_notes ) {
         ->plus_minutes(30); # Current time in 'Asia/Kolkata' TimeZone.
 }
 
+my $fmt = Number::Format::SouthAsian->new(
+    words => 1,
+    decimals => 2
+);
+
 my $rows_printed = 0;
 foreach my $i ( 0 ... scalar @$statewise - 1 ) {
     # $rows_printed is incremented at the end of this foreach loop.
@@ -258,63 +264,67 @@ foreach my $i ( 0 ... scalar @$statewise - 1 ) {
                 substr( $lastupdatedtime, 0, 2 );
         }
 
-        my $confirmed = "$statewise->[$i]{confirmed}";
-        my $recovered = "$statewise->[$i]{recovered}";
-        my $deaths = "$statewise->[$i]{deaths}";
+        my $confirmed = $fmt->format_number("$statewise->[$i]{confirmed}");
+        my $recovered = $fmt->format_number("$statewise->[$i]{recovered}");
+        my $deaths = $fmt->format_number("$statewise->[$i]{deaths}");
 
         # Add delta only if it was updated Today.
         if ( $update_info eq "Today"
                  and not $no_delta ) {
+            # Only delta number will get highlighted.
+            $_ .= " " for ($confirmed, $recovered, $deaths);
+
             my $delta_confirmed = $statewise->[$i]{deltaconfirmed};
             if ( $delta_confirmed > 1000 ) {
                 $confirmed .= LOCALCOLOR BLACK ON_MAGENTA
-                    sprintf " (%+d)", $statewise->[$i]{deltaconfirmed};
+                    sprintf "%+d", $delta_confirmed;
             } elsif ( $delta_confirmed > 500  ) {
                 $confirmed .= LOCALCOLOR BRIGHT_MAGENTA
-                    sprintf " (%+d)", $statewise->[$i]{deltaconfirmed};
+                    sprintf "%+d", $delta_confirmed;
             } elsif ( $delta_confirmed > 100 ) {
                 $confirmed .= LOCALCOLOR MAGENTA
-                    sprintf " (%+d)", $statewise->[$i]{deltaconfirmed};
+                    sprintf "%+d", $delta_confirmed;
             } else {
-                $confirmed .= sprintf " (%+d)", $statewise->[$i]{deltaconfirmed};
+                $confirmed .= sprintf "%+d", $delta_confirmed;
             }
 
             my $delta_recovered = $statewise->[$i]{deltarecovered};
             if ( $delta_recovered > 1000 ) {
                 $recovered .= LOCALCOLOR BLACK ON_GREEN
-                    sprintf " (%+d)", $statewise->[$i]{deltarecovered};
+                    sprintf "%+d", $delta_recovered;
             } elsif ( $delta_recovered > 500 ) {
                 $recovered .= LOCALCOLOR BRIGHT_GREEN
-                    sprintf " (%+d)", $statewise->[$i]{deltarecovered};
+                    sprintf "%+d", $delta_recovered;
             } elsif ( $delta_recovered > 100 ) {
                 $recovered .= LOCALCOLOR GREEN
-                    sprintf " (%+d)", $statewise->[$i]{deltarecovered};
+                    sprintf "%+d", $delta_recovered;
             } else {
-                $recovered .= sprintf " (%+d)", $statewise->[$i]{deltarecovered};
+                $recovered .= sprintf "%+d", $delta_recovered;
             }
 
             my $delta_deaths = $statewise->[$i]{deltadeaths};
             if ( $delta_deaths > 100 ) {
                 $state = LOCALCOLOR BLACK ON_RED $state;
                 $deaths .= LOCALCOLOR BLACK ON_RED
-                    sprintf " (%+d)", $statewise->[$i]{deltadeaths};
+                    sprintf "%+d", $delta_deaths;
             } elsif ( $delta_deaths > 50 ) {
                 $state = LOCALCOLOR BRIGHT_RED $state;
                 $deaths .= LOCALCOLOR BRIGHT_RED
-                    sprintf " (%+d)", $statewise->[$i]{deltadeaths};
+                    sprintf "%+d", $delta_deaths;
             } elsif ( $delta_deaths > 25 ) {
                 $state = LOCALCOLOR RED $state;
                 $deaths .= LOCALCOLOR RED
-                    sprintf " (%+d)", $statewise->[$i]{deltadeaths};
+                    sprintf "%+d", $delta_deaths;
             } else {
-                $deaths .= sprintf " (%+d)", $statewise->[$i]{deltadeaths};
+                $deaths .= sprintf "%+d", $delta_deaths;
             }
         }
 
         my @row;
         push @row, $state;
         push @row, $confirmed unless exists $hide{confirmed};
-        push @row, $statewise->[$i]{active} unless exists $hide{active};
+        push @row, $fmt->format_number($statewise->[$i]{active}, words => 0)
+            unless exists $hide{active};
         push @row, $recovered unless exists $hide{recovered};
         push @row, $deaths unless exists $hide{deaths};
         push @row, $update_info unless exists $hide{'last updated'};
diff --git a/cpanfile b/cpanfile
index 851ef24..1af9537 100644
--- a/cpanfile
+++ b/cpanfile
@@ -5,6 +5,7 @@ requires 'JSON::MaybeXS', '1.004002';
 requires 'Text::ASCIITable', '0.22';
 requires 'Getopt::Long', '2.5';
 requires 'Term::ANSIColor', '5.01';
+requires 'Number::Format::SouthAsian', '0.10';
 
 requires 'IO::Socket::SSL', '1.42'
     or 'Net::SSLeay', '1.49';