Mercurial > pub > buggler
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 11:4eb9fdf4efa9 | 12:52b34ea50eff | 
|---|---|
| 43 ); | 43 ); | 
| 44 } | 44 } | 
| 45 | 45 | 
| 46 use constant { BUG_FIELDS => \@fields }; | 46 use constant { BUG_FIELDS => \@fields }; | 
| 47 | 47 | 
| 48 use IMPL::lang qw(coarsen coarsen_dt); | |
| 48 use IMPL::declare { base => [ 'IMPL::Object::Fields' => undef ] }; | 49 use IMPL::declare { base => [ 'IMPL::Object::Fields' => undef ] }; | 
| 49 use fields @fields; | 50 use fields @fields; | 
| 50 | 51 | 
| 51 sub CTOR { | 52 sub CTOR { | 
| 52 my SELF $this = shift; | 53 my SELF $this = shift; | 
| 62 # actual => hours | 63 # actual => hours | 
| 63 # remaining => hours | 64 # remaining => hours | 
| 64 # } | 65 # } | 
| 65 sub GetTimeReports { | 66 sub GetTimeReports { | 
| 66 my SELF $this = shift; | 67 my SELF $this = shift; | 
| 67 my $resolution = shift || 0.25; | 68 my $resolution = | 
| 68 my $span = $resolution * 60; | 69 DateTime::Duration->new( %{ shift() || { minutes => 15 } } ); | 
| 69 | 70 | 
| 70 my @bookings; | 71 my @bookings; | 
| 71 my $actual = 0; | 72 my $actual = 0; | 
| 72 | 73 | 
| 73 for my $history ( @{ $this->{history} || [] } ) { | 74 for my $history ( @{ $this->{history} || [] } ) { | 
| 74 my $who = $history->{who}; | 75 my $who = $history->{who}; | 
| 75 my $when = $history->{when}; | 76 my $when = coarsen_dt( $history->{when}, $resolution ); | 
| 76 my $changes = $history->{changes}; | 77 my $changes = $history->{changes}; | 
| 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 | |
| 87 | 78 | 
| 88 for my $change ( @{ $changes || [] } ) { | 79 for my $change ( @{ $changes || [] } ) { | 
| 89 if ( $change->{field_name} eq 'work_time' ) { | 80 if ( $change->{field_name} eq 'work_time' ) { | 
| 90 my $prev = $change->{removed} || 0; | 81 my $prev = $change->{removed} || 0; | 
| 91 my $value = $change->{added} || 0; | 82 my $value = $change->{added} || 0; | 
| 92 if ( looks_like_number($prev) and looks_like_number($value) ) { | 83 if ( looks_like_number($prev) and looks_like_number($value) ) { | 
| 93 my $dt = coarsen( $value - $prev, $resolution ); | 84 my $dt = | 
| 85 coarsen( $value - $prev, $resolution->in_units('hours') ); | |
| 94 | 86 | 
| 95 if ($dt) { | 87 if ($dt) { | 
| 96 push @bookings, | 88 push @bookings, | 
| 97 { | 89 { | 
| 98 who => $who, | 90 who => $who, | 
| 99 end => $when, | 91 when => $when, | 
| 100 work_time => $dt, | 92 work_time => $dt | 
| 101 start => $when->clone()->subtract( hours => $dt ) | |
| 102 }; | 93 }; | 
| 103 $actual += $dt; | 94 $actual += $dt; | 
| 104 } | 95 } | 
| 105 } | 96 } | 
| 106 } | 97 } | 
| 107 } | 98 } | 
| 108 } | 99 } | 
| 109 | 100 | 
| 110 my $remaining = coarsen( $this->{remaining_time}, $resolution ); | 101 my $remaining = coarsen( $this->{remaining_time}, $resolution->in_units('hours') ); | 
| 111 return { | 102 return { | 
| 112 report => \@bookings, | 103 report => \@bookings, | 
| 113 actual => $actual, | 104 actual => $actual, | 
| 114 remaining => $remaining, | 105 remaining => $remaining, | 
| 115 estimated => $actual + $remaining | 106 estimated => $actual + $remaining | 
| 116 }; | 107 }; | 
| 117 } | 108 } | 
| 118 | 109 | 
| 119 sub coarsen { | |
| 120 my ( $value, $resolution ) = @_; | |
| 121 return $resolution ? ceil( $value / $resolution ) * $resolution : $value; | |
| 122 } | |
| 123 | |
| 124 1; | 110 1; | 
