diff options
Diffstat (limited to 'lib/Taurus')
-rw-r--r-- | lib/Taurus/CLI.rakumod | 76 |
1 files changed, 47 insertions, 29 deletions
diff --git a/lib/Taurus/CLI.rakumod b/lib/Taurus/CLI.rakumod index 7d80f51..8aacc7a 100644 --- a/lib/Taurus/CLI.rakumod +++ b/lib/Taurus/CLI.rakumod @@ -1,4 +1,5 @@ use Taurus::Seconds; +use Taurus::Timestamp; use CSV::Parser; use Terminal::UI 'ui'; @@ -14,6 +15,8 @@ multi sub MAIN ( ) is export { my @logs; my Str %contacts{Str}; + my Str @month-name = <Month January February March April May June + July August September October November December>; my Instant $timed = now; my Promise $initial = start { @@ -38,6 +41,9 @@ multi sub MAIN ( # Store Duration in seconds. .[4] = (.[4].split(":")[0] * 60) + .[4].split(":")[1]; + + # Store DateTime. + .[3] = timestamp-to-date .[3]; } }; @@ -45,7 +51,7 @@ multi sub MAIN ( my $p0 = ui.panes[0]; my $p1 = ui.panes[1]; - $p0.put: t.bold ~ t.bg-cyan ~ t.black ~t.underline~ "Taurus v" ~ $?DISTRIBUTION.meta<version>; + $p0.put: t.bold ~ t.bg-cyan ~ t.black ~ t.underline ~ "Taurus v" ~ $?DISTRIBUTION.meta<version>; $p0.put: ""; with ui.screen.add-frame(:4height, :40width, :center) -> $f { @@ -68,6 +74,9 @@ multi sub MAIN ( $p0.put: "- Show Records", :meta(:all); $p0.put: ""; + $p0.put: "Yearly Records"; + $p0.put: " - $_ Records", :meta(:year($_)) for @logs.map(*.[3].year).unique; + $p0.put: ""; # First list Contacts, then sorted phone numbers. for @logs.race.map(*.[1]).unique.sort({%contacts{$_} // "Z", $_}) { $p0.put: "- " ~ $_ ~ " {%contacts{$_} // ''}", :meta(:number($_)); @@ -78,49 +87,58 @@ multi sub MAIN ( $p0.select(2); $p0.on: select => -> :%meta { my Int $fmt = 16; - if %meta<all> { + if %meta.keys.elems > 0 { ui.focus(:pane(1)); $p1.clear; - with @logs { - my $outgoing = .grep(*.[2] eqv "Outgoing Call").map(*.[4]).sum; - my $incoming = .grep(*.[2] eqv "Incoming Call").map(*.[4]).sum; + } + + print-basic-stats($p1, @logs) with %meta<all>; - $p1.put: "%-*s %s".sprintf($fmt, "Outgoing:", seconds-to-str($outgoing)); - $p1.put: "%-*s %s".sprintf($fmt, "Incoming:", seconds-to-str($incoming)); - $p1.put: "%-*s %s".sprintf($fmt, "Total:", seconds-to-str($outgoing + $incoming)); + with %meta<year> -> $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 -> $month { + $p1.put: "%-*s %s".sprintf($fmt, @month-name[$month] ~ ":", + seconds-to-str(.grep(*.[3].month eqv $month).map(*.[4]).sum)); + } } - $p1.select-first; - } elsif %meta<number> -> $num { - ui.focus(:pane(1)); - $p1.clear; + } + + with %meta<number> -> $num { $p1.put: "Name: " ~ $_ with %contacts{$num}; $p1.put: "Number: " ~ $num; $p1.put: ""; - with @logs.grep(*.[1] eqv $num).cache { - my $outgoing = .grep(*.[2] eqv "Outgoing Call").map(*.[4]).sum; - my $incoming = .grep(*.[2] eqv "Incoming Call").map(*.[4]).sum; - - $p1.put: "%-*s %s".sprintf($fmt, "Outgoing:", seconds-to-str($outgoing)); - $p1.put: "%-*s %s".sprintf($fmt, "Incoming:", seconds-to-str($incoming)); - $p1.put: "%-*s %s".sprintf($fmt, "Total:", seconds-to-str($outgoing + $incoming)); - $p1.put: ""; - - $p1.put: "%-*s %d".sprintf($fmt, "Declined:", - .grep({$_.[2] eqv "Incoming Call" and $_.[4] == 0}).elems); - $p1.put: "%-*s %d".sprintf($fmt, "Declined (they):", - .grep({$_.[2] eqv "Outgoing Call" and $_.[4] == 0}).elems); - $p1.put: "%-*s %d".sprintf($fmt, "Missed Calls:", - .grep(*.[2] eqv "Missed Call").elems); - } - $p1.select-first; + print-basic-stats($p1, @logs.grep(*.[1] eqv $num)); } + $p1.select-first; } ui.interact; ui.shutdown; } +sub print-basic-stats($p1, @logs) { + constant $fmt = 16; + with @logs { + my $outgoing = .grep(*.[2] eqv "Outgoing Call").map(*.[4]).sum; + my $incoming = .grep(*.[2] eqv "Incoming Call").map(*.[4]).sum; + + $p1.put: "%-*s %s".sprintf($fmt, "Outgoing:", seconds-to-str($outgoing)); + $p1.put: "%-*s %s".sprintf($fmt, "Incoming:", seconds-to-str($incoming)); + $p1.put: "%-*s %s".sprintf($fmt, "Total:", seconds-to-str($outgoing + $incoming)); + $p1.put: ""; + + $p1.put: "%-*s %d".sprintf($fmt, "You Rejected:", + .grep({$_.[2] eqv "Rejected Call" and $_.[4] == 0}).elems); + $p1.put: "%-*s %d".sprintf($fmt, "Missed Calls:", + .grep(*.[2] eqv "Missed Call").elems); + $p1.put: "%-*s %d".sprintf($fmt, "Missed (they):", # Covers Not in network, Rejected. + .grep({$_.[2] eqv "Outgoing Call" and $_.[4] == 0}).elems); + } +} multi sub MAIN( Bool :$version #= print version |