line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::bif::wlog; |
2
|
1
|
|
|
1
|
|
1597
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
26
|
use Bif::Mo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
736
|
use DBIx::ThinSQL qw/case coalesce sq qv/; |
|
1
|
|
|
|
|
27014
|
|
|
1
|
|
|
|
|
8
|
|
7
|
1
|
|
|
1
|
|
822
|
use Text::FormatTable; |
|
1
|
|
|
|
|
2968
|
|
|
1
|
|
|
|
|
1055
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.1.5_7'; |
10
|
|
|
|
|
|
|
extends 'App::bif'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub run { |
13
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
1
|
my $id; |
16
|
1
|
50
|
|
|
|
5
|
if ( my $str = $self->opts->{identity} ) { |
17
|
0
|
0
|
|
|
|
0
|
unless ( $str eq '-' ) { |
18
|
0
|
|
|
|
|
0
|
my $iinfo = $self->get_node( $str, 'identity' ); |
19
|
0
|
|
|
|
|
0
|
$id = $iinfo->{id}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
1
|
|
|
|
|
8
|
$id = $self->db->xval( |
24
|
|
|
|
|
|
|
select => 'b.identity_id', |
25
|
|
|
|
|
|
|
from => 'bifkv b', |
26
|
|
|
|
|
|
|
where => { key => 'self' }, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
return $self->work_log_long($id) if $self->opts->{long}; |
31
|
0
|
|
|
|
|
|
return $self->work_log_short($id); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub work_log_long { |
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
36
|
0
|
|
|
|
|
|
my $identity_id = shift; |
37
|
0
|
|
|
|
|
|
my $db = $self->db; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $sth = $db->xprepare( |
40
|
|
|
|
|
|
|
with => 'src', |
41
|
|
|
|
|
|
|
as => sq( |
42
|
|
|
|
|
|
|
select => [ 'wd.id AS id', 'wd.stop - wd.start AS delta', ], |
43
|
|
|
|
|
|
|
from => 'work_deltas wd', |
44
|
|
|
|
|
|
|
), |
45
|
|
|
|
|
|
|
select => [ |
46
|
|
|
|
|
|
|
'c.action AS action', |
47
|
|
|
|
|
|
|
'wd.node_id', |
48
|
|
|
|
|
|
|
q{strftime('%Y-%m-%d %H:%M:%S', } |
49
|
|
|
|
|
|
|
. q{ wd.gtime_start, 'unixepoch') AS start}, |
50
|
|
|
|
|
|
|
q{wd.comment AS comment}, |
51
|
|
|
|
|
|
|
q{strftime('%Y-%m-%d %H:%M:%S', } |
52
|
|
|
|
|
|
|
. q{ wd.gtime_stop, 'unixepoch') AS stop}, |
53
|
|
|
|
|
|
|
q{ printf('%+0.2d:%0.2d:%0.2d', } |
54
|
|
|
|
|
|
|
. q{ src.delta / 3600, } |
55
|
|
|
|
|
|
|
. q{ (src.delta - 3600 * (src.delta / 3600)) / 60, } |
56
|
|
|
|
|
|
|
. q{ src.delta % 60 ) AS delta}, |
57
|
|
|
|
|
|
|
q{COALESCE(printf('%s %s [%s]', n.kind, n.id, n.path),'') AS path}, |
58
|
|
|
|
|
|
|
], |
59
|
|
|
|
|
|
|
from => 'src', |
60
|
|
|
|
|
|
|
inner_join => 'work_deltas wd', |
61
|
|
|
|
|
|
|
on => 'wd.id = src.id', |
62
|
|
|
|
|
|
|
inner_join => 'changes c', |
63
|
|
|
|
|
|
|
on => 'c.id = wd.change_id', |
64
|
|
|
|
|
|
|
left_join => 'nodes n', |
65
|
|
|
|
|
|
|
on => 'n.id = wd.node_id', |
66
|
|
|
|
|
|
|
order_by => 'wd.id DESC', |
67
|
|
|
|
|
|
|
); |
68
|
0
|
|
|
|
|
|
$sth->execute; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my ( $yellow, $bold, $reset ) = $self->colours( 'yellow', 'bold', 'reset' ); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->start_pager; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
while ( my $ref = $sth->hashref ) { |
75
|
0
|
|
|
|
|
|
my $table = Text::FormatTable->new(' l l'); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$table->row( $yellow . 'Action:', $ref->{action} . $reset ); |
78
|
0
|
|
|
|
|
|
$table->row( 'Start:', $ref->{start} ); |
79
|
0
|
|
|
|
|
|
$table->row( 'Stop:', $ref->{stop} ); |
80
|
0
|
|
|
|
|
|
$table->row( 'Delta:', $ref->{delta} ); |
81
|
|
|
|
|
|
|
$table->row( 'Comment:', $ref->{comment} ) |
82
|
0
|
0
|
|
|
|
|
if $ref->{comment}; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
print $table->render, "\n"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $self->ok('WorkLogLong'); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub work_log_short { |
91
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
92
|
0
|
|
|
|
|
|
my $identity_id = shift; |
93
|
0
|
|
|
|
|
|
my $db = $self->db; |
94
|
0
|
|
|
|
|
|
my ( $yellow, $bold, $reset ) = $self->colours( 'yellow', 'bold', 'reset' ); |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
my $sth = $db->xprepare( |
|
|
0
|
|
|
|
|
|
97
|
|
|
|
|
|
|
with => 'worked', |
98
|
|
|
|
|
|
|
as => sq( |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Grab stuff from the work_buffers table |
101
|
|
|
|
|
|
|
select => [ |
102
|
|
|
|
|
|
|
'wb.start + wb.offset AS start', |
103
|
|
|
|
|
|
|
q{strftime('%Y-%m-%d', } |
104
|
|
|
|
|
|
|
. q{ wb.start+wb.offset, 'unixepoch') AS start_ymd}, |
105
|
|
|
|
|
|
|
"strftime('%s','now') AS stop", |
106
|
|
|
|
|
|
|
"strftime('%s','now') - wb.start AS delta", |
107
|
|
|
|
|
|
|
'n.id AS id', |
108
|
|
|
|
|
|
|
'i.shortname AS shortname', |
109
|
|
|
|
|
|
|
"'work ' || n.kind || ' ' || n.path " |
110
|
|
|
|
|
|
|
. "|| COALESCE(' -- '|| wb.comment, '') AS action", |
111
|
|
|
|
|
|
|
'wb.bill AS bill', |
112
|
|
|
|
|
|
|
"'-' AS change_id", |
113
|
|
|
|
|
|
|
], |
114
|
|
|
|
|
|
|
from => 'work_buffers wb', |
115
|
|
|
|
|
|
|
inner_join => 'nodes n', |
116
|
|
|
|
|
|
|
on => 'n.id = wb.node_id', |
117
|
|
|
|
|
|
|
$identity_id |
118
|
|
|
|
|
|
|
? ( |
119
|
|
|
|
|
|
|
inner_join => 'identities i', |
120
|
|
|
|
|
|
|
on => { 'i.id' => $identity_id }, |
121
|
|
|
|
|
|
|
) |
122
|
|
|
|
|
|
|
: ( |
123
|
|
|
|
|
|
|
inner_join => 'bifkv b', |
124
|
|
|
|
|
|
|
on => { 'b.key' => 'self', }, |
125
|
|
|
|
|
|
|
inner_join => 'identities i', |
126
|
|
|
|
|
|
|
on => 'i.id = b.identity_id', |
127
|
|
|
|
|
|
|
), |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Grab stuff from the work_deltas table |
130
|
|
|
|
|
|
|
union_all_select => [ |
131
|
|
|
|
|
|
|
'wd.gtime_start AS start', |
132
|
|
|
|
|
|
|
q{strftime('%Y-%m-%d', } |
133
|
|
|
|
|
|
|
. q{ wd.gtime_start, 'unixepoch') AS start_ymd}, |
134
|
|
|
|
|
|
|
'wd.gtime_stop AS stop', |
135
|
|
|
|
|
|
|
'wd.stop - wd.start AS delta', |
136
|
|
|
|
|
|
|
'n.id AS id', |
137
|
|
|
|
|
|
|
'i.shortname AS shortname', |
138
|
|
|
|
|
|
|
"c.action || COALESCE(' -- '|| wd.comment, '') AS action", |
139
|
|
|
|
|
|
|
'0 AS bill', |
140
|
|
|
|
|
|
|
'wd.change_id AS change_id', |
141
|
|
|
|
|
|
|
], |
142
|
|
|
|
|
|
|
from => 'work_deltas wd', |
143
|
|
|
|
|
|
|
inner_join => 'nodes n', |
144
|
|
|
|
|
|
|
on => 'n.id = wd.node_id', |
145
|
|
|
|
|
|
|
inner_join => 'changes c', |
146
|
|
|
|
|
|
|
on => { |
147
|
|
|
|
|
|
|
'c.id' => \'wd.change_id', |
148
|
|
|
|
|
|
|
$identity_id ? ( 'c.identity_id' => $identity_id, ) : (), |
149
|
|
|
|
|
|
|
}, |
150
|
|
|
|
|
|
|
inner_join => 'identities i', |
151
|
|
|
|
|
|
|
on => 'i.id = c.identity_id', |
152
|
|
|
|
|
|
|
), |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Sum the above grouped by day |
155
|
|
|
|
|
|
|
',' => 'worked_summary', |
156
|
|
|
|
|
|
|
as => sq( |
157
|
|
|
|
|
|
|
select => [ |
158
|
|
|
|
|
|
|
'w.start_ymd AS start_ymd', |
159
|
|
|
|
|
|
|
'MAX(w.start) AS max_start', |
160
|
|
|
|
|
|
|
'SUM(w.delta) AS delta', |
161
|
|
|
|
|
|
|
"julianday(date('now','localtime'))" |
162
|
|
|
|
|
|
|
. " - julianday(w.start_ymd) AS day" |
163
|
|
|
|
|
|
|
], |
164
|
|
|
|
|
|
|
from => 'worked w', |
165
|
|
|
|
|
|
|
group_by => [ 'start_ymd', 'day' ], |
166
|
|
|
|
|
|
|
), |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Now format all of that nicely |
169
|
|
|
|
|
|
|
select => [ |
170
|
|
|
|
|
|
|
'w.start_ymd AS start_ymd', |
171
|
|
|
|
|
|
|
'w.start AS start', |
172
|
|
|
|
|
|
|
"strftime('%H:%M', w.start, 'unixepoch') AS start_hm", |
173
|
|
|
|
|
|
|
'w.stop AS stop', |
174
|
|
|
|
|
|
|
"COALESCE(strftime('%H:%M', w.stop, 'unixepoch')," |
175
|
|
|
|
|
|
|
. "'') AS stop_hm", |
176
|
|
|
|
|
|
|
q{ printf('%+0.2d:%0.2d', } |
177
|
|
|
|
|
|
|
. q{ round(w.delta / 3600), } |
178
|
|
|
|
|
|
|
. q{ (w.delta - 3600 * round(w.delta / 3600)) / 60) |
179
|
|
|
|
|
|
|
AS delta_hm }, |
180
|
|
|
|
|
|
|
'w.shortname AS shortname', |
181
|
|
|
|
|
|
|
'w.id AS id', |
182
|
|
|
|
|
|
|
'w.action AS action', |
183
|
|
|
|
|
|
|
'w.bill AS bill', |
184
|
|
|
|
|
|
|
'w.change_id AS change_id', |
185
|
|
|
|
|
|
|
], |
186
|
|
|
|
|
|
|
from => 'worked w', |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# total/summary row |
189
|
|
|
|
|
|
|
union_all_select => [ |
190
|
|
|
|
|
|
|
'ws.start_ymd AS start_ymd', |
191
|
|
|
|
|
|
|
'ws.max_start + 1 AS start', |
192
|
|
|
|
|
|
|
'-1 AS start_hm', |
193
|
|
|
|
|
|
|
'-1 AS stop', |
194
|
|
|
|
|
|
|
'-1 AS stop_hm', |
195
|
|
|
|
|
|
|
q{ printf('%+0.2d:%0.2d', } |
196
|
|
|
|
|
|
|
. q{ round(ws.delta / 3600), } |
197
|
|
|
|
|
|
|
. q{ (ws.delta -} |
198
|
|
|
|
|
|
|
. q{ 3600 * round(ws.delta / 3600)) / 60) AS delta_hm}, |
199
|
|
|
|
|
|
|
'-1 AS shortname', |
200
|
|
|
|
|
|
|
'NULL AS id', |
201
|
|
|
|
|
|
|
'ws.day AS action', |
202
|
|
|
|
|
|
|
'NULL AS bill', |
203
|
|
|
|
|
|
|
'NULL AS change_id', |
204
|
|
|
|
|
|
|
], |
205
|
|
|
|
|
|
|
from => 'worked_summary ws', |
206
|
|
|
|
|
|
|
order_by => [ 'start_ymd DESC', 'start DESC', 'stop DESC' ] |
207
|
|
|
|
|
|
|
); |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
$sth->execute; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# $sth->dump_results; |
212
|
0
|
|
|
|
|
|
$self->start_pager; |
213
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
|
my $i = 0; |
215
|
0
|
|
|
|
|
|
my $format = ' l l l r '; |
216
|
0
|
|
|
|
|
|
my @empty = ( '-', '', '', '' ); |
217
|
0
|
|
|
|
|
|
my $table = Text::FormatTable->new($format); |
218
|
0
|
|
|
|
|
|
my $first = 1; |
219
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
while ( my $ref = $sth->hashref ) { |
221
|
|
|
|
|
|
|
|
222
|
0
|
0
|
|
|
|
|
if ( $ref->{start_hm} eq '-1' ) { |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# Every 200 rows or so spit out the table and start again. |
225
|
0
|
0
|
|
|
|
|
if ( $i > 200 ) { |
|
|
0
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
print $table->render( $self->term_width ), "\n"; |
227
|
0
|
|
|
|
|
|
$table = Text::FormatTable->new($format); |
228
|
0
|
|
|
|
|
|
$i = 1; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
elsif ($i) { |
231
|
0
|
|
|
|
|
|
$table->row(@empty); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
$table->head( |
235
|
|
|
|
|
|
|
$yellow . $ref->{start_ymd}, |
236
|
|
|
|
|
|
|
0 == $ref->{action} ? 'Activity [today]' |
237
|
|
|
|
|
|
|
: 1 == $ref->{action} ? 'Activity [yesterday]' |
238
|
|
|
|
|
|
|
: "Activity [$ref->{action} days ago]", |
239
|
|
|
|
|
|
|
'CID', |
240
|
0
|
0
|
|
|
|
|
$ref->{delta_hm} . $reset |
|
|
0
|
|
|
|
|
|
241
|
|
|
|
|
|
|
); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
else { |
245
|
|
|
|
|
|
|
$table->row( |
246
|
|
|
|
|
|
|
( $ref->{change_id} eq '-' ? $bold : '' ) |
247
|
|
|
|
|
|
|
. "$ref->{start_hm} - $ref->{stop_hm}", |
248
|
|
|
|
|
|
|
$ref->{action}, |
249
|
|
|
|
|
|
|
$ref->{change_id}, |
250
|
0
|
0
|
|
|
|
|
$ref->{delta_hm} . $reset, |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
|
$i++; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
0
|
|
|
|
|
|
print $table->render( $self->term_width ), "\n"; |
259
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
return $self->ok('WorkLogShort'); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
1; |
264
|
|
|
|
|
|
|
__END__ |