Mercurial > pub > buggler
comparison lib/Benzin/Bugzilla/Bug.pm @ 10:14a966369278
working version of exporting bugs from bugzilla in tj3 format (without bookings)
author | cin |
---|---|
date | Mon, 07 Sep 2015 01:37:11 +0300 |
parents | cc7244ab1b9f |
children | 4eb9fdf4efa9 |
comparison
equal
deleted
inserted
replaced
9:cc7244ab1b9f | 10:14a966369278 |
---|---|
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 { |
49 require => { | 49 base => [ 'IMPL::Object::Fields' => undef ] |
50 Strptime => 'DateTime::Format::Strptime' | |
51 }, | |
52 base => [ | |
53 'IMPL::Object::Fields' => undef | |
54 ] | |
55 }; | 50 }; |
56 | |
57 use fields @fields; | 51 use fields @fields; |
58 | |
59 my $dtparser = Strptime->new( | |
60 pattern => '%Y%m%dT%H:%M:%S', | |
61 time_zone => 'UTC', | |
62 on_error => 'croak' | |
63 ); | |
64 | 52 |
65 sub CTOR { | 53 sub CTOR { |
66 my SELF $this = shift; | 54 my SELF $this = shift; |
67 my $data = shift; | 55 my $data = shift; |
68 $this->{$_} = $data->{$_} | 56 $this->{$_} = $data->{$_} |
69 foreach grep exists $data->{$_}, @{ SELF->BUG_FIELDS }; | 57 foreach grep exists $data->{$_}, @{ SELF->BUG_FIELDS }; |
70 } | 58 } |
71 | 59 |
72 # returns { | 60 # returns { |
73 # reports => [ | 61 # reports => [ |
74 # { who => email:string, when => report-date-time:DateTime, work_time => hours:double } | 62 # { who => email:string, start => work-start-date-time:DateTime, end => report-date-time:DateTime, work_time => hours:double } |
75 # ], | 63 # ], |
76 # actual => hours | 64 # actual => hours |
77 # remaining => hours | 65 # remaining => hours |
78 # } | 66 # } |
79 sub GetTimeReports { | 67 sub GetTimeReports { |
80 my SELF $this = shift; | 68 my SELF $this = shift; |
81 my $resolution = shift || 0.25; | 69 my $resolution = shift || 0.25; |
82 | |
83 warn "Processing: $this->{id}"; | |
84 | 70 |
85 my @bookings; | 71 my @bookings; |
86 my $actual = 0; | 72 my $actual = 0; |
87 | 73 |
88 for my $history ( @{ $this->{history} || [] } ) { | 74 for my $history ( @{ $this->{history} || [] } ) { |
89 my $who = $history->{who}; | 75 my $who = $history->{who}; |
90 warn $history->{when}; | 76 my $when = $history->{when}; |
91 my $when = $dtparser->parse_datetime( $history->{when} ); | |
92 my $changes = $history->{changes}; | 77 my $changes = $history->{changes}; |
93 | 78 |
94 for my $change ( @{ $changes || [] } ) { | 79 for my $change ( @{ $changes || [] } ) { |
95 if ( $change->{field_name} eq 'work_time' ) { | 80 if ( $change->{field_name} eq 'work_time' ) { |
96 my $prev = $change->{removed} || 0; | 81 my $prev = $change->{removed} || 0; |
99 my $dt = coarsen( $value - $prev, $resolution ); | 84 my $dt = coarsen( $value - $prev, $resolution ); |
100 | 85 |
101 if ($dt) { | 86 if ($dt) { |
102 push @bookings, | 87 push @bookings, |
103 { | 88 { |
104 who => $who, | 89 end => $who, |
105 when => $when->iso8601(), | 90 when => $when->iso8601(), |
106 work_time => $dt, | 91 work_time => $dt, |
107 start => $when->clone()->subtract( hours => $dt )->iso8601() | 92 start => $when->clone()->subtract( hours => $dt ) |
93 ->iso8601() | |
108 }; | 94 }; |
109 $actual += $dt; | 95 $actual += $dt; |
110 } | 96 } |
111 } | 97 } |
112 } | 98 } |