Kusarigama/Plugin/Command/Progress.pm

filter: Statementstmt 47.3% 36 / 76 Branchbran 15.6% 5 / 32 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 4 totaltotal 37.8% 50 / 132 CC 20 SCAR 48.2
CC
20
Cov
36%
on_command
237.1
formatted_rate
4.1
on_modify
3.5
CRAP 123.5
↑ Summary Kusarigama/Plugin/Command/Open.pm »
1 package Taskwarrior::Kusarigama::Plugin::Command::Progress;
2 2 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: Record progress on a task
4 2 $Taskwarrior::Kusarigama::Plugin::Command::Progress::VERSION = '0.11.0';
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 extends 'Taskwarrior::Kusarigama::Plugin';
14  
15 2 with 'Taskwarrior::Kusarigama::Hook::OnCommand',
16 'Taskwarrior::Kusarigama::Hook::OnAdd',
17 'Taskwarrior::Kusarigama::Hook::OnModify';
18  
19 2 ▶use experimental 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 has custom_uda => (
22 is => 'ro',
23 default => sub{ +{
24 1 ▶ goal => 'quantifiable goal',
Subroutine __ANON__: called CC=1 SCAR=0.0
25 progress => "where we're at",
26 }},
27 2 );
28  
29 sub on_add {
30 0 ▶ goto &on_modify;
Subroutine on_add: not called CC=1 SCAR=6.9
Pod undocumented
31 }
32  
33 sub on_modify {
34 0 ▶ my( $self, $task ) = @_;
Subroutine on_modify: not called CC=2 SCAR=12.6
Pod undocumented
35  
36 2 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 0 ▶ my $goal = $task->{goal} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $goal = $task->{"goal"} or return 0 0 0
39  
40 0 my $progress = $task->{progress};
41  
42 0 $task->{description} =~ s#\(\d+\/\d+\)(.*?)$#$1#;
43 0 $task->{description} .= sprintf ' (%d/%d)', $progress, $goal;
44  
45 0 return $task;
46 }
47  
48 sub formatted_rate {
49 3 ▶ my ( $self, $rate ) = @_;
Subroutine formatted_rate: called CC=4 SCAR=14.1
Pod undocumented
50  
51 3 my $unit;
52  
53 3 ▶ if( $rate > 1 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($rate > 1) { } 1 2 3
elsif ($rate > 0.14285714285714284921) { } 1 1 2
elsif ($rate > 0.033333333333333332871) { } 1 0 1
54 1 $unit = 'day';
55 }
56 elsif( $rate > 1/7 ) {
57 1 $rate *= 7;
58 1 $unit = 'week';
59 }
60 elsif( $rate > 1/30 ) {
61 1 $rate *= 30;
62 1 $unit = 'month';
63 }
64 else {
65 0 $rate *= 365;
66 0 $unit = 'year';
67 }
68  
69 3 return sprintf "%d/%s", $rate, $unit;
70 }
71  
72 sub on_command {
73 0 ▶ my $self = shift;
Subroutine on_command: not called CC=16 SCAR=54.7
Pod undocumented
74  
75 # only grab goal'ed tasks
76 0 my @tasks = $self->run_task->export( $self->pre_command_args, { 'goal.any' => '' } );
77  
78 0 ▶ die "no tasks found\n" unless @tasks;
Branch: 1 branch
BranchTrueFalseTotal
unless @tasks 0 0 0
79  
80 0 my $note = $self->post_command_args =~ s/\s*(\??)(=?)(-?\d*)\s*//r;
81  
82 2 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
83 0 for my $task ( @tasks ) {
84 0 my $save = !$1;
85  
86 my $progress = !$save ? $task->{progress}
87 : $2 ? $3
88 0 ▶ : ($3||1) + $task->{progress};
Branch: 2 branches
BranchTrueFalseTotal
!$save ? : 0 0 0
$2 ? : 0 0 0
Condition0%0/2
$3 || 1
l!l
00
MC/DC0%0/1
$3 || 1
$3
Truth table0%0/2
A
A= $3
Aresult
11
00
89  
90 0 my $goal = $task->{goal};
91  
92 0 my $ratio = $progress / $goal;
93  
94 0 print $task->{id}, ' ', '=' x ( 20 * $ratio ), '-' x ( 20 * ( 1 - $ratio ) ), ' ', $progress, '/', $goal, sprintf(" (%.1f%%)\n", $ratio*100), "\n";
95  
96 0 my $id = $task->{uuid};
97 0 ▶ $self->run_task->mod( [ $id ], { progress => $progress } ) if $save;
Branch: 1 branch
BranchTrueFalseTotal
if $save 0 0 0
98 0 ▶ $self->run_task->annotate( [ $id ], $note ) if $note and $save;
Branch: 1 branch
BranchTrueFalseTotal
if $note and $save 0 0 0
Condition0%0/3
$note and $save
!ll&&!rl&&r
000
MC/DC0%0/2
$note and $save
$note $save
Truth table0%0/3
A and B
A= $noteB= $save
ABresult
0X0
100
111
99 0 ▶ if ( $progress >= $task->{goal} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($progress >= $task->{'goal'}) { } 0 0 0
elsif ($task->{'due'}) { } 0 0 0
100 0 say "goal achieved!";
101 0 ▶ $self->run_task->done( [ $id ] ) if $save;
Branch: 1 branch
BranchTrueFalseTotal
if $save 0 0 0
102 }
103 elsif( $task->{due} ) {
104 0 my ( $span ) = $self->calc( $task->{due}, '-', $task->{entry} ) =~ /(\d+)D/;
105 0 my ( $now ) = $self->calc( $task->{due}, '-', 'now' ) =~ /(\d+)D/g;
106 0 my $should_be_at = eval { $task->{goal} * ($span-$now) / $span };
107 0 ▶ if( $should_be_at ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($should_be_at) 0 0 0
108 0 my $comp = ('on track', 'ahead', 'behind')[ $progress <=> $should_be_at ];
109  
110 0 printf "%d days left, you are %s of schedule (%d vs %d)\n",
111 $now, $comp, $progress, $should_be_at;
112  
113 0 my @stats;
114  
115 0 ▶ if( my $so_far = eval { $progress / ($span-$now) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $so_far = eval { do { $progress / ($span - $now) } }) 0 0 0
116 0 push @stats, sprintf "rate so far: %s",
117 $self->formatted_rate($so_far);
118 }
119  
120 0 ▶ if( my $needed = eval { ($task->{goal} - $progress) / $now } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $needed = eval { do { ($task->{"goal"} - $progress) / $now } }) 0 0 0
121 0 push @stats, sprintf "rate needed: %s",
122 $self->formatted_rate($needed);
123 }
124  
125 0 ▶ say join ', ', @stats if @stats;
Branch: 1 branch
BranchTrueFalseTotal
if @stats 0 0 0
126  
127 }
128 }
129 }
130  
131 };
132  
133 2 1;
134  
135 __END__
136  
137 =pod
138  
139 =encoding UTF-8
140  
141 =head1 NAME
142  
143 Taskwarrior::Kusarigama::Plugin::Command::Progress - Record progress on a task
144  
145 =head1 VERSION
146  
147 version 0.11.0
148  
149 =head1 SYNOPSIS
150  
151 $ task add read ten books goal:10
152  
153 ... later on ...
154  
155 $ task 'read ten books' progress
156  
157 =head1 DESCRIPTION
158  
159 Tasks get two new UDAs: C<goal>, which sets a
160 numeric goal to reach, and C<progress>, which is
161 the current state of progress.
162  
163 Progress can be updated or asked via the C<progress> command.
164  
165 # add 3 units toward the goal
166 $ task 123 progress 3
167  
168 # oops, two steps back
169 $ task 123 progress -2
170  
171 # set progress to an absolute value
172 $ task 123 progress =9
173  
174 # defaults to a +1 increment
175 $ task 123 progress
176  
177 # record progress and add a note
178 $ task 123 progress +3 I did a little bit of the thing
179  
180 # ask about current task progress
181 $ task 123 progress ?
182  
183 # ask about current task progress on three step forward
184 # real progress don't modified
185 $ task 123 progress ?3
186  
187 If the task has a due date, the progress command will
188 also show a short report of your actual rate of completion
189 version what is required to meet the goal on time.
190  
191 $ task 630 progress =170
192 630 =======------------ 170/475 (35.8%)
193 15 days left, you are ahead of schedule (170 vs 118)
194 rate so far: 34/day, rate needed: 20/day
195  
196 =head1 AUTHOR
197  
198 Yanick Champoux <yanick@cpan.org>
199  
200 =head1 COPYRIGHT AND LICENSE
201  
202 This software is copyright (c) 2018, 2017 by Yanick Champoux.
203  
204 This is free software; you can redistribute it and/or modify it under
205 the same terms as the Perl 5 programming language system itself.
206  
207 =cut
↑ Summary Kusarigama/Plugin/Command/Open.pm »