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