annotate lib/Benzin/Bugzilla/Bug.pm @ 12:52b34ea50eff default tip

sync: work time projection doesn't seem to be working anyway
author cin
date Sun, 13 Sep 2015 19:37:16 +0300
parents 4eb9fdf4efa9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
1 package Benzin::Bugzilla::Bug;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
2 use strict;
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
3 use POSIX;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
4 use Scalar::Util qw(looks_like_number);
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
5 use DateTime;
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
6
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
7 my @fields;
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
8
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
9 BEGIN {
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
10 @fields = qw(
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
11 id
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
12 summary
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
13 creation_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
14 last_change_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
15 creator
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
16 assigned_to
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
17 qa_contact
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
18 cc
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
19
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
20 is_open
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
21 status
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
22 resolution
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
23
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
24 priority
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
25 severity
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
26 url
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
27
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
28 blocks
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
29 depends_on
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
30
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
31 component
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
32 product
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
33 classification
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
34 version
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
35
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
36 actual_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
37 estimated_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
38 remaining_time
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
39 deadline
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
40
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
41 comments
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
42 history
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
43 );
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
44 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
45
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
46 use constant { BUG_FIELDS => \@fields };
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
47
12
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
48 use IMPL::lang qw(coarsen coarsen_dt);
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
49 use IMPL::declare { base => [ 'IMPL::Object::Fields' => undef ] };
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
50 use fields @fields;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
51
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
52 sub CTOR {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
53 my SELF $this = shift;
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
54 my $data = shift;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
55 $this->{$_} = $data->{$_}
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
56 foreach grep exists $data->{$_}, @{ SELF->BUG_FIELDS };
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
57 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
58
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
59 # returns {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
60 # reports => [
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
61 # { who => email:string, start => work-start-date-time:DateTime, end => report-date-time:DateTime, work_time => hours:double }
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
62 # ],
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
63 # actual => hours
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
64 # remaining => hours
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
65 # }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
66 sub GetTimeReports {
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
67 my SELF $this = shift;
12
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
68 my $resolution =
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
69 DateTime::Duration->new( %{ shift() || { minutes => 15 } } );
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
70
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
71 my @bookings;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
72 my $actual = 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
73
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
74 for my $history ( @{ $this->{history} || [] } ) {
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
75 my $who = $history->{who};
12
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
76 my $when = coarsen_dt( $history->{when}, $resolution );
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
77 my $changes = $history->{changes};
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
78
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
79 for my $change ( @{ $changes || [] } ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
80 if ( $change->{field_name} eq 'work_time' ) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
81 my $prev = $change->{removed} || 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
82 my $value = $change->{added} || 0;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
83 if ( looks_like_number($prev) and looks_like_number($value) ) {
12
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
84 my $dt =
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
85 coarsen( $value - $prev, $resolution->in_units('hours') );
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
86
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
87 if ($dt) {
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
88 push @bookings,
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
89 {
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
90 who => $who,
12
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
91 when => $when,
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
92 work_time => $dt
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
93 };
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
94 $actual += $dt;
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
95 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
96 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
97 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
98 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
99 }
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
100
12
52b34ea50eff sync: work time projection doesn't seem to be working anyway
cin
parents: 11
diff changeset
101 my $remaining = coarsen( $this->{remaining_time}, $resolution->in_units('hours') );
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
102 return {
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
103 report => \@bookings,
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
104 actual => $actual,
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
105 remaining => $remaining,
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
106 estimated => $actual + $remaining
9
cc7244ab1b9f implemented time reports on bugs
cin
parents: 7
diff changeset
107 };
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
108 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
109
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents: 9
diff changeset
110 1;