line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::TimeTracker::Command::Category; |
2
|
1
|
|
|
1
|
|
358
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
19
|
use 5.010; |
|
1
|
|
|
|
|
10
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: use categories when tracking time with App::TimeTracker |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "1.002"; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
476
|
use Moose::Util::TypeConstraints; |
|
1
|
|
|
|
|
194051
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
1723
|
use Moose::Role; |
|
1
|
|
|
|
|
286947
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub munge_start_attribs { |
14
|
0
|
|
|
0
|
0
|
|
my ( $class, $meta, $config ) = @_; |
15
|
0
|
|
|
|
|
|
my $cfg = $config->{category}; |
16
|
0
|
0
|
0
|
|
|
|
return unless $cfg && $cfg->{categories}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
subtype 'ATT::Category' => as enum( $cfg->{categories} ) => message { |
19
|
0
|
|
|
0
|
|
|
"$_ is not a valid category (as defined in the current config)" |
20
|
0
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$meta->add_attribute( |
23
|
|
|
|
|
|
|
'category' => { |
24
|
|
|
|
|
|
|
isa => 'ATT::Category', |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
required => $cfg->{required}, |
27
|
0
|
|
|
|
|
|
documentation => 'Category', |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
after '_load_attribs_start' => \&munge_start_attribs; |
32
|
|
|
|
|
|
|
after '_load_attribs_append' => \&munge_start_attribs; |
33
|
|
|
|
|
|
|
after '_load_attribs_continue' => \&munge_start_attribs; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
before [ 'cmd_start', 'cmd_continue', 'cmd_append' ] => sub { |
36
|
|
|
|
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ( $self->category ) { |
39
|
|
|
|
|
|
|
$self->add_tag( $self->category ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub cmd_statistic { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my @files = $self->find_task_files( |
47
|
|
|
|
|
|
|
{ from => $self->from, |
48
|
|
|
|
|
|
|
to => $self->to, |
49
|
|
|
|
|
|
|
projects => $self->fprojects, |
50
|
|
|
|
|
|
|
tags => $self->ftags, |
51
|
|
|
|
|
|
|
parent => $self->fparent, |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
); |
54
|
0
|
|
|
|
|
|
my $cats = $self->config->{category}{categories}; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $total = 0; |
57
|
0
|
|
|
|
|
|
my %stats; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
foreach my $file (@files) { |
60
|
0
|
|
|
|
|
|
my $task = App::TimeTracker::Data::Task->load( $file->stringify ); |
61
|
0
|
|
0
|
|
|
|
my $time = $task->seconds // $task->_build_seconds; |
62
|
0
|
|
|
|
|
|
$total += $time; |
63
|
0
|
|
|
|
|
|
my %tags = map { $_ => 1 } @{ $task->tags }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $got_cat = 0; |
66
|
0
|
|
|
|
|
|
foreach my $cat (@$cats) { |
67
|
0
|
0
|
|
|
|
|
if ( $tags{$cat} ) { |
68
|
0
|
|
|
|
|
|
$stats{$cat}{abs} += $time; |
69
|
0
|
|
|
|
|
|
$got_cat = 1; |
70
|
0
|
|
|
|
|
|
last; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
0
|
0
|
|
|
|
|
$stats{_no_cat}{abs} += $time unless $got_cat; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
while ( my ( $cat, $data ) = each %stats ) { |
77
|
0
|
|
|
|
|
|
$data->{percent} = sprintf( "%.1f", $data->{abs} / $total * 100 ); |
78
|
0
|
|
|
|
|
|
$data->{nice} = $self->beautify_seconds( $data->{abs} ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->_say_current_report_interval; |
82
|
0
|
|
|
|
|
|
printf( "%39s\n", $self->beautify_seconds($total) ); |
83
|
0
|
|
|
|
|
|
foreach my $cat ( sort keys %stats ) { |
84
|
0
|
|
|
|
|
|
my $data = $stats{$cat}; |
85
|
|
|
|
|
|
|
printf( "%6s%% %- 20s% 10s\n", |
86
|
0
|
|
|
|
|
|
$data->{percent}, $cat, $data->{nice} ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _load_attribs_statistic { |
91
|
0
|
|
|
0
|
|
|
my ( $class, $meta ) = @_; |
92
|
0
|
|
|
|
|
|
$class->_load_attribs_worked($meta); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
1
|
|
4392
|
no Moose::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=pod |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=encoding UTF-8 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
App::TimeTracker::Command::Category - use categories when tracking time with App::TimeTracker |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 VERSION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
version 1.002 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Define some categories, which act like 'Super-Tags', for example: |
115
|
|
|
|
|
|
|
"feature", "bug", "maint", .. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 CONFIGURATION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 plugins |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Add C<Category> to the list of plugins. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 category |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
add a hash named C<category>, containing the following keys: |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head3 required |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Set to a true value if 'category' should be a required command line option |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head3 categories |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
A list (ARRAYREF) of category names. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 NEW COMMANDS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 statistic |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Print stats on time worked per category |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
domm@t430:~/validad$ tracker statistic --last day |
142
|
|
|
|
|
|
|
From 2016-01-29T00:00:00 to 2016-01-29T23:59:59 you worked on: |
143
|
|
|
|
|
|
|
07:39:03 |
144
|
|
|
|
|
|
|
9.9% bug 00:45:23 |
145
|
|
|
|
|
|
|
33.2% feature 02:32:21 |
146
|
|
|
|
|
|
|
28.3% maint 02:09:52 |
147
|
|
|
|
|
|
|
12.9% meeting 00:59:21 |
148
|
|
|
|
|
|
|
15.7% support 01:12:06 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
You can use the same options as in C<report> to define which tasks you |
151
|
|
|
|
|
|
|
want stats on (C<--from, --until, --this, --last, --ftag, --fproject, ..>) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 CHANGES TO OTHER COMMANDS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 start, continue, append |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head3 --category |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
~/perl/Your-Project$ tracker start --category feature |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Make sure that 'feature' is a valid category and store it as a tag. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 AUTHOR |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Thomas Klausner <domm@cpan.org> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Thomas Klausner. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
172
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |