Mercurial > pub > buggler
annotate lib/Benzin/Bugzilla/Bug.pm @ 11:4eb9fdf4efa9
refactoring, non-working bookings
author | cin |
---|---|
date | Mon, 07 Sep 2015 19:18:21 +0300 |
parents | 14a966369278 |
children | 52b34ea50eff |
rev | line source |
---|---|
7 | 1 package Benzin::Bugzilla::Bug; |
2 use strict; | |
9 | 3 use POSIX; |
4 use Scalar::Util qw(looks_like_number); | |
5 use DateTime; | |
7 | 6 |
9 | 7 my @fields; |
7 | 8 |
9 BEGIN { | |
9 | 10 @fields = qw( |
7 | 11 id |
12 summary | |
13 creation_time | |
14 last_change_time | |
15 creator | |
16 assigned_to | |
17 qa_contact | |
18 cc | |
19 | |
9 | 20 is_open |
7 | 21 status |
22 resolution | |
23 | |
24 priority | |
25 severity | |
26 url | |
27 | |
28 blocks | |
29 depends_on | |
30 | |
31 component | |
32 product | |
33 classification | |
34 version | |
35 | |
36 actual_time | |
37 estimated_time | |
38 remaining_time | |
39 deadline | |
9 | 40 |
7 | 41 comments |
9 | 42 history |
7 | 43 ); |
44 } | |
45 | |
9 | 46 use constant { BUG_FIELDS => \@fields }; |
7 | 47 |
11 | 48 use IMPL::declare { base => [ 'IMPL::Object::Fields' => undef ] }; |
9 | 49 use fields @fields; |
50 | |
7 | 51 sub CTOR { |
52 my SELF $this = shift; | |
9 | 53 my $data = shift; |
54 $this->{$_} = $data->{$_} | |
55 foreach grep exists $data->{$_}, @{ SELF->BUG_FIELDS }; | |
7 | 56 } |
57 | |
9 | 58 # returns { |
59 # reports => [ | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
60 # { who => email:string, start => work-start-date-time:DateTime, end => report-date-time:DateTime, work_time => hours:double } |
9 | 61 # ], |
62 # actual => hours | |
63 # remaining => hours | |
64 # } | |
65 sub GetTimeReports { | |
7 | 66 my SELF $this = shift; |
9 | 67 my $resolution = shift || 0.25; |
11 | 68 my $span = $resolution * 60; |
9 | 69 |
70 my @bookings; | |
71 my $actual = 0; | |
72 | |
73 for my $history ( @{ $this->{history} || [] } ) { | |
11 | 74 my $who = $history->{who}; |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
75 my $when = $history->{when}; |
9 | 76 my $changes = $history->{changes}; |
11 | 77 |
78 my $minutes = coarsen( $when->minute(), $span ); | |
79 | |
80 if ($minutes >= 60 ) { | |
81 $when->add(hours => 1); | |
82 $minutes -= 60; | |
83 } | |
84 $when->set_second(0); | |
85 $when->set_minute($minutes); | |
86 | |
9 | 87 |
88 for my $change ( @{ $changes || [] } ) { | |
89 if ( $change->{field_name} eq 'work_time' ) { | |
90 my $prev = $change->{removed} || 0; | |
91 my $value = $change->{added} || 0; | |
92 if ( looks_like_number($prev) and looks_like_number($value) ) { | |
93 my $dt = coarsen( $value - $prev, $resolution ); | |
94 | |
95 if ($dt) { | |
96 push @bookings, | |
97 { | |
11 | 98 who => $who, |
99 end => $when, | |
9 | 100 work_time => $dt, |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
101 start => $when->clone()->subtract( hours => $dt ) |
9 | 102 }; |
103 $actual += $dt; | |
104 } | |
105 } | |
106 } | |
107 } | |
108 } | |
109 | |
11 | 110 my $remaining = coarsen( $this->{remaining_time}, $resolution ); |
9 | 111 return { |
11 | 112 report => \@bookings, |
9 | 113 actual => $actual, |
11 | 114 remaining => $remaining, |
115 estimated => $actual + $remaining | |
9 | 116 }; |
7 | 117 } |
118 | |
9 | 119 sub coarsen { |
120 my ( $value, $resolution ) = @_; | |
121 return $resolution ? ceil( $value / $resolution ) * $resolution : $value; | |
122 } | |
123 | |
10
14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
9
diff
changeset
|
124 1; |