From e472da737b53e742d02e5db96fdd260577542d74 Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 1 Sep 2021 16:49:42 +0530 Subject: Print yearly records for each user --- lib/Taurus/CLI.rakumod | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'lib/Taurus/CLI.rakumod') diff --git a/lib/Taurus/CLI.rakumod b/lib/Taurus/CLI.rakumod index ba98381..ecd245c 100644 --- a/lib/Taurus/CLI.rakumod +++ b/lib/Taurus/CLI.rakumod @@ -15,8 +15,6 @@ multi sub MAIN ( ) is export { my @logs; my Str %contacts{Str}; - my Str @month-name = ; my Instant $timed = now; my Promise $initial = start { @@ -86,16 +84,7 @@ multi sub MAIN ( print-basic-stats($p1, @logs) with %meta; with %meta -> $year { - $p1.put: "Year: " ~ $year; - $p1.put: ""; - with @logs.grep(*.[3].year eqv $year) { - print-basic-stats($p1, $_); - $p1.put: ""; - for .map(*.[3].month).unique.sort -> $month { - $p1.put: "%-*s %s".sprintf($fmt, @month-name[$month] ~ ":", - seconds-to-str(.grep(*.[3].month eqv $month).map(*.[4]).sum)); - } - } + print-yearly-record($p1, @logs, $year); } with %meta -> $num { @@ -103,6 +92,10 @@ multi sub MAIN ( $p1.put: "Number: " ~ $num; $p1.put: ""; print-basic-stats($p1, @logs.grep(*.[1] eqv $num)); + + for @logs.map(*.[3].year).unique -> $year { + print-yearly-record($p1, @logs, $year); + } } $p1.select-first; } @@ -111,6 +104,20 @@ multi sub MAIN ( ui.shutdown; } +sub print-yearly-record($p1, @logs, $year) { + constant $fmt = 16; + my Str @month-name = ; + $p1.put: ""; + $p1.put: "Year: " ~ $year; + with @logs.grep(*.[3].year eqv $year).cache { + for .map(*.[3].month).unique.sort -> $month { + $p1.put: " %-*s %s".sprintf($fmt, @month-name[$month] ~ ":", + seconds-to-str(.grep(*.[3].month eqv $month).map(*.[4]).sum)); + } + } +} + sub print-basic-stats($p1, @logs) { constant $fmt = 16; with @logs { -- cgit 1.4.1-2-gfad0