| 1 | package App::TimelogTxt::Day; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use App::TimelogTxt::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use List::Util qw/sum/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.22'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 5 | my ($class, $stamp) = @_; | |||||||||||||||||||||||||||
| 13 | 5 | ▶ | die "Missing required stamp.\n" unless $stamp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | die "Invalid stamp format.\n" unless App::TimelogTxt::Utils::is_datestamp( $stamp ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | return bless { | |||||||||||||||||||||||||||
| 17 | stamp => $stamp, | ||||||||||||||||||||||||||||
| 18 | start => undef, | ||||||||||||||||||||||||||||
| 19 | dur => 0, | ||||||||||||||||||||||||||||
| 20 | tasks => {}, | ||||||||||||||||||||||||||||
| 21 | proj_dur => {}, | ||||||||||||||||||||||||||||
| 22 | last_start => 0, | ||||||||||||||||||||||||||||
| 23 | }, $class; | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub is_empty { return !$_[0]->{dur}; } | ||||||||||||||||||||||||||
|
Subroutine
is_empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub is_complete { return !$_[0]->{last_start}; } | ||||||||||||||||||||||||||
|
Subroutine
is_complete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub date_stamp { return $_[0]->{stamp}; } | ||||||||||||||||||||||||||
|
Subroutine
date_stamp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub has_tasks { return !!keys %{$_[0]->{tasks}}; } | ||||||||||||||||||||||||||
|
Subroutine
has_tasks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub update_dur | ||||||||||||||||||||||||||||
| 32 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
update_dur: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 9 | my ($self, $last, $epoch) = @_; | |||||||||||||||||||||||||||
| 34 | 9 | ▶ | my $curr_dur = $last ? $epoch - $last->epoch : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 9 | ▶ | $self->{tasks}->{$last->task}->{dur} += $curr_dur if $last && $last->task; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$last and $last->task
MC/DC100%2/2
$last and $last->task
$last
$last->task
Truth table100%3/3
A and B
A= $lastB= $last->task
| |||||||||||||||||||||||||||||
| 37 | 9 | ▶ | $self->{proj_dur}->{$last->project} += $curr_dur if $last && $last->project; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$last and $last->project
MC/DC100%2/2
$last and $last->project
$last
$last->project
Truth table100%3/3
A and B
A= $lastB= $last->project
| |||||||||||||||||||||||||||||
| 38 | 9 | $self->{dur} += $curr_dur; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 9 | return; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub day_filtered_by_project | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
day_filtered_by_project: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 0 | my ($self, $project) = @_; | |||||||||||||||||||||||||||
| 46 | 0 | my $result = __PACKAGE__->new( $self->date_stamp ); | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | $project = qr/$project/ unless ref $project; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | my @tasks = grep { $self->{tasks}->{$_}->{proj} =~ $project } keys %{$self->{tasks}}; | |||||||||||||||||||||||||||
| 49 | 0 | @{$result->{tasks}}{@tasks} = @{$self->{tasks}}{@tasks}; | |||||||||||||||||||||||||||
| 50 | 0 | my @projs = grep { $_ =~ $project } keys %{$self->{proj_dur}}; | |||||||||||||||||||||||||||
| 51 | 0 | @{$result->{proj_dur}}{@projs} = @{$self->{proj_dur}}{@projs}; | |||||||||||||||||||||||||||
| 52 | 0 | $result->{dur} = sum( 0, values %{$result->{proj_dur}} ); | |||||||||||||||||||||||||||
| 53 | 0 | return $result; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub close_day | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
close_day: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | my ($self, $last) = @_; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | return if $self->is_complete(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | $self->update_dur( $last, $self->day_end() ); | |||||||||||||||||||||||||||
| 62 | 0 | $self->{last_start} = 0; | |||||||||||||||||||||||||||
| 63 | 0 | return; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 7 | ▶ | sub start_task { | ||||||||||||||||||||||||||
|
Subroutine
start_task: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 7 | my ($self, $event) = @_; | |||||||||||||||||||||||||||
| 68 | 7 | ▶ | if( $event->is_stop() ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||
| 70 | 1 | $self->{last_start} = 0; | |||||||||||||||||||||||||||
| 71 | 1 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 6 | my $task = $event->task; | |||||||||||||||||||||||||||
| 74 | 6 | $self->{last_start} = $event->epoch; | |||||||||||||||||||||||||||
| 75 | 6 | ▶ | return if $self->{tasks}->{$task}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 4 | $self->{tasks}->{$task} = { start => $event->epoch, proj => $event->project, dur => 0 }; | |||||||||||||||||||||||||||
| 77 | 4 | return; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | ▶ | sub print_day_detail { | ||||||||||||||||||||||||||
|
Subroutine
print_day_detail: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 3 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 82 | 3 | ▶ | $fh ||= \*STDOUT; | ||||||||||||||||||||||||||
|
Condition50%1/2
$fh ||= \*STDOUT
MC/DC0%0/1
$fh ||= \*STDOUT
$fh
Truth table50%1/2
A
A= $fh
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 3 | my ($tasks, $proj_dur) = @{$self}{ qw/tasks proj_dur/ }; | |||||||||||||||||||||||||||
| 85 | 3 | my $last_proj = ''; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | print {$fh} "\n", _format_stamp_line( $self ); | |||||||||||||||||||||||||||
| 88 | 3 | ▶ | foreach my $t ( sort { ($tasks->{$a}->{proj} cmp $tasks->{$b}->{proj}) || ($tasks->{$b}->{start} <=> $tasks->{$a}->{start}) } keys %{$tasks} ) | ||||||||||||||||||||||||||
|
Condition66%2/3
$tasks->{$a}{'proj'} cmp $tasks->{$b}{'proj'} || $tasks->{$b}{'start'} <=> $tasks->{$a}{'start'}
MC/DC0%0/2
$tasks->{$a}{'proj'} cmp $tasks->{$b}{'proj'} || $tasks->{$b}{'start'} <=> $tasks->{$a}{'start'}
$tasks->{$a}{'proj'} cmp $tasks->{$b}{'proj'}
$tasks->{$b}{'start'} <=> $tasks->{$a}{'start'}
Truth table66%2/3
A || B
A= $tasks->{$a}{'proj'} cmp $tasks->{$b}{'proj'}B= $tasks->{$b}{'start'} <=> $tasks->{$a}{'start'}
| |||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | 4 | my $curr = $tasks->{$t}; | |||||||||||||||||||||||||||
| 91 | 4 | ▶ | if( $curr->{proj} ne $last_proj ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 2 | print {$fh} _format_project_line( $curr->{proj}, $proj_dur->{$curr->{proj}} ); | |||||||||||||||||||||||||||
| 94 | 2 | $last_proj = $curr->{proj}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 4 | my $task = $t; | |||||||||||||||||||||||||||
| 97 | 4 | print {$fh} _format_task_line( $t, $curr->{dur} ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 3 | return; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 2 | ▶ | sub print_day_summary { | ||||||||||||||||||||||||||
|
Subroutine
print_day_summary: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 2 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 104 | 2 | ▶ | $fh ||= \*STDOUT; | ||||||||||||||||||||||||||
|
Condition50%1/2
$fh ||= \*STDOUT
MC/DC0%0/1
$fh ||= \*STDOUT
$fh
Truth table50%1/2
A
A= $fh
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 2 | my $proj_dur = $self->{proj_dur}; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | print {$fh} _format_stamp_line( $self ); | |||||||||||||||||||||||||||
| 109 | 2 | foreach my $p ( sort keys %{$proj_dur} ) | |||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 2 | print {$fh} _format_project_line( $p, $proj_dur->{$p} ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 2 | return; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | sub print_hours { | ||||||||||||||||||||||||||
|
Subroutine
print_hours: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 1 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 118 | 1 | ▶ | $fh ||= \*STDOUT; | ||||||||||||||||||||||||||
|
Condition50%1/2
$fh ||= \*STDOUT
MC/DC0%0/1
$fh ||= \*STDOUT
$fh
Truth table50%1/2
A
A= $fh
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | print {$fh} _format_stamp_line( $self, ':' ); | |||||||||||||||||||||||||||
| 121 | 1 | return; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub print_duration { | ||||||||||||||||||||||||||
|
Subroutine
print_duration: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 0 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 126 | 0 | ▶ | $fh ||= \*STDOUT; | ||||||||||||||||||||||||||
|
Condition0%0/2
$fh ||= \*STDOUT
MC/DC0%0/1
$fh ||= \*STDOUT
$fh
Truth table0%0/2
A
A= $fh
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | print {$fh} _format_dur( $self->{dur} ), "\n"; | |||||||||||||||||||||||||||
| 129 | 0 | return; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | sub day_end | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
day_end: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | return App::TimelogTxt::Utils::stamp_to_localtime( $self->{stamp} ); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | sub _format_dur | ||||||||||||||||||||||||||||
| 140 | 14 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_format_dur: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 141 | 14 | my ($dur) = @_; | |||||||||||||||||||||||||||
| 142 | 14 | $dur += 30; # round, don't truncate. | |||||||||||||||||||||||||||
| 143 | 14 | return sprintf( '%2d:%02d', int($dur/3600), int(($dur%3600)/60) ); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | sub _format_stamp_line | ||||||||||||||||||||||||||||
| 147 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_format_stamp_line: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 148 | 6 | my ($self, $sep) = @_; | |||||||||||||||||||||||||||
| 149 | 6 | ▶ | $sep ||= ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$sep ||= ""
MC/DC100%1/1
$sep ||= ""
$sep
Truth table100%2/2
A
A= $sep
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 6 | return "$self->{stamp}$sep " . _format_dur( $self->{dur} ) . "\n"; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | sub _format_task_line | ||||||||||||||||||||||||||||
| 155 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_format_task_line: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 156 | 4 | my ($task, $dur) = @_; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 4 | $task =~ s/\+\S+\s//; | |||||||||||||||||||||||||||
| 159 | 4 | ▶ | if ( $task =~ s/\@(\S+)\s*// ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||
| 161 | 2 | ▶ | if ( $task ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 1 | return sprintf( " %-20s%s (%s)\n", $1, _format_dur( $dur ), $task ); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||
| 165 | 1 | return sprintf( " %-20s%s\n", $1, _format_dur( $dur ) ); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | else { | ||||||||||||||||||||||||||||
| 169 | 2 | return sprintf( " %-20s%s\n", $task, _format_dur( $dur ) ); | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 0 | return; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | sub _format_project_line | ||||||||||||||||||||||||||||
| 175 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_format_project_line: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 176 | 4 | my ($proj, $dur) = @_; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 4 | return sprintf( ' %-13s%s', $proj, _format_dur( $dur ). "\n" ); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 2 | 1; | |||||||||||||||||||||||||||
| 182 | __END__ | ||||||||||||||||||||||||||||