| 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.10.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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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=12 SCAR=48.9
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
| |||||||||||||||||||||
| 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 $progress = $1 ? $2 : ($2||1) + $task->{progress}; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$2 || 1
MC/DC0%0/1
$2 || 1
$2
Truth table0%0/2
A
A= $2
| |||||||||||||||||||||
| 85 | 0 | my $goal = $task->{goal}; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | my $ratio = $progress / $goal; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | print $task->{id}, ' ', '=' x ( 20 * $ratio ), '-' x ( 20 * ( 1 - $ratio ) ), ' ', $progress, '/', $goal, "\n"; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | my $id = $task->{uuid}; | |||||||||||||||||||
| 92 | 0 | $self->run_task->mod( [ $id ], { progress => $progress } ); | |||||||||||||||||||
| 93 | 0 | ▶ | $self->run_task->annotate( [ $id ], $note ) if $note; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | ▶ | if ( $progress >= $task->{goal} ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 95 | 0 | say "goal achieved!"; | |||||||||||||||||||
| 96 | 0 | $self->run_task->done( [ $id ] ); | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | elsif( $task->{due} ) { | ||||||||||||||||||||
| 99 | 0 | my ( $span ) = $self->calc( $task->{due}, '-', $task->{entry} ) =~ /(\d+)D/; | |||||||||||||||||||
| 100 | 0 | my ( $now ) = $self->calc( $task->{due}, '-', 'now' ) =~ /(\d+)D/g; | |||||||||||||||||||
| 101 | 0 | my $should_be_at = eval { $task->{goal} * ($span-$now) / $span }; | |||||||||||||||||||
| 102 | 0 | ▶ | if( $should_be_at ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | 0 | my $comp = ('on track', 'ahead', 'behind')[ $progress <=> $should_be_at ]; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | printf "%d days left, you are %s of schedule (%d vs %d)\n", | |||||||||||||||||||
| 106 | $now, $comp, $progress, $should_be_at; | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | my @stats; | |||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | if( my $so_far = eval { $progress / ($span-$now) } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 0 | push @stats, sprintf "rate so far: %s", | |||||||||||||||||||
| 112 | $self->formatted_rate($so_far); | ||||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | ▶ | if( my $needed = eval { ($task->{goal} - $progress) / $now } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | 0 | push @stats, sprintf "rate needed: %s", | |||||||||||||||||||
| 117 | $self->formatted_rate($needed); | ||||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | ▶ | say join ', ', @stats if @stats; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 2 | 1; | |||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =pod | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =encoding UTF-8 | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =head1 NAME | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | Taskwarrior::Kusarigama::Plugin::Command::Progress - Record progress on a task | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =head1 VERSION | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | version 0.10.0 | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head1 SYNOPSIS | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | $ task add read ten books goal:10 | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | ... later on ... | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | $ task 'read ten books' progress | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =head1 DESCRIPTION | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | Tasks get two new UDAs: C<goal>, which sets a | ||||||||||||||||||||
| 155 | numeric goal to reach, and C<progress>, which is | ||||||||||||||||||||
| 156 | the current state of progress. | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | Progress can be updated via the C<progress> command. | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | # add 3 units toward the goal | ||||||||||||||||||||
| 161 | $ task 123 progress 3 | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | # oops, two steps back | ||||||||||||||||||||
| 164 | $ task 123 progress -2 | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | # set progress to an absolute value | ||||||||||||||||||||
| 167 | $ task 123 progress =9 | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | # defaults to a +1 increment | ||||||||||||||||||||
| 170 | $ task 123 progress | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | # record progress and add a note | ||||||||||||||||||||
| 173 | $ task 123 progress +3 I did a little bit of the thing | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | If the task has a due date, the progress command will | ||||||||||||||||||||
| 176 | also show a short report of your actual rate of completion | ||||||||||||||||||||
| 177 | version what is required to meet the goal on time. | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | $ task 630 progress =170 | ||||||||||||||||||||
| 180 | 630 =======------------ 170/475 | ||||||||||||||||||||
| 181 | 15 days left, you are ahead of schedule (170 vs 118) | ||||||||||||||||||||
| 182 | rate so far: 34/day, rate needed: 20/day | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =head1 AUTHOR | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | Yanick Champoux <yanick@cpan.org> | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | This software is copyright (c) 2018, 2017 by Yanick Champoux. | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 193 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||