line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Toolforge::MixNMatch::Diff; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
198489
|
use strict; |
|
3
|
|
|
|
|
23
|
|
|
3
|
|
|
|
|
72
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
71
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
1206
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
29674
|
|
|
3
|
|
|
|
|
51
|
|
7
|
3
|
|
|
3
|
|
1495
|
use Toolforge::MixNMatch::Object::Catalog; |
|
3
|
|
|
|
|
13175
|
|
|
3
|
|
|
|
|
79
|
|
8
|
3
|
|
|
3
|
|
1206
|
use Toolforge::MixNMatch::Object::User; |
|
3
|
|
|
|
|
1413
|
|
|
3
|
|
|
|
|
72
|
|
9
|
3
|
|
|
3
|
|
1212
|
use Toolforge::MixNMatch::Object::YearMonth; |
|
3
|
|
|
|
|
1451
|
|
|
3
|
|
|
|
|
1929
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.01; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub diff { |
14
|
4
|
|
|
4
|
0
|
2671
|
my ($catalog1, $catalog2, $warn) = @_; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
50
|
|
|
19
|
$warn //= 0; |
17
|
|
|
|
|
|
|
|
18
|
4
|
50
|
|
|
|
10
|
if ($catalog1->type ne $catalog2->type) { |
19
|
0
|
|
|
|
|
0
|
_warn('Different type of catalogs.', $warn); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
4
|
50
|
|
|
|
46
|
if ($catalog1->count != $catalog2->count) { |
23
|
0
|
|
|
|
|
0
|
_warn('Count values of catalogs are different.', $warn); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
37
|
my ($new_cat, $old_cat) = _which_catalog_is_new($catalog1, $catalog2, $warn); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Diff of users. |
29
|
4
|
|
|
|
|
6
|
my $users_ar = []; |
30
|
4
|
|
|
|
|
5
|
foreach my $new_cat_user (@{$new_cat->users}) { |
|
4
|
|
|
|
|
7
|
|
31
|
3
|
|
|
|
|
27
|
my $old_cat_user; |
32
|
3
|
|
|
|
|
5
|
foreach my $user_iter (@{$old_cat->users}) { |
|
3
|
|
|
|
|
6
|
|
33
|
1
|
50
|
|
|
|
7
|
if ($user_iter->username eq $new_cat_user->username) { |
34
|
|
|
|
|
|
|
|
35
|
1
|
50
|
|
|
|
11
|
if ($user_iter->uid ne $new_cat_user->uid) { |
36
|
0
|
|
|
|
|
0
|
err 'Something wrong with uids in catalogs.'; |
37
|
|
|
|
|
|
|
} |
38
|
1
|
|
|
|
|
10
|
$old_cat_user = $user_iter; |
39
|
1
|
|
|
|
|
2
|
last; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
3
|
100
|
|
|
|
19
|
my $count = defined $old_cat_user ? |
43
|
|
|
|
|
|
|
($new_cat_user->count - $old_cat_user->count) |
44
|
|
|
|
|
|
|
: $new_cat_user->count; |
45
|
3
|
50
|
|
|
|
19
|
if ($count) { |
46
|
3
|
|
|
|
|
5
|
push @{$users_ar}, Toolforge::MixNMatch::Object::User->new( |
|
3
|
|
|
|
|
5
|
|
47
|
|
|
|
|
|
|
'count' => $count, |
48
|
|
|
|
|
|
|
'uid' => $new_cat_user->uid, |
49
|
|
|
|
|
|
|
'username' => $new_cat_user->username, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Diff of dates. |
55
|
4
|
|
|
|
|
159
|
my $year_months_ar = []; |
56
|
4
|
0
|
|
|
|
6
|
foreach my $new_cat_year_month (sort { $a->year <=> $b->year || $a->month <=> $b->month } |
|
0
|
|
|
|
|
0
|
|
57
|
4
|
|
|
|
|
9
|
@{$new_cat->year_months}) { |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
my $old_cat_year_month; |
60
|
0
|
|
|
|
|
0
|
foreach my $year_month_iter (@{$old_cat->year_months}) { |
|
0
|
|
|
|
|
0
|
|
61
|
0
|
0
|
0
|
|
|
0
|
if ($year_month_iter->year eq $new_cat_year_month->year |
62
|
|
|
|
|
|
|
&& $year_month_iter->month eq $new_cat_year_month->month) { |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
$old_cat_year_month = $year_month_iter; |
65
|
0
|
|
|
|
|
0
|
last; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
0
|
0
|
|
|
|
0
|
my $count = defined $old_cat_year_month ? |
69
|
|
|
|
|
|
|
($new_cat_year_month->count - $old_cat_year_month->count) |
70
|
|
|
|
|
|
|
: $new_cat_year_month->count; |
71
|
0
|
0
|
|
|
|
0
|
if ($count) { |
72
|
0
|
|
|
|
|
0
|
push @{$year_months_ar}, Toolforge::MixNMatch::Object::YearMonth->new( |
|
0
|
|
|
|
|
0
|
|
73
|
|
|
|
|
|
|
'year' => $new_cat_year_month->year, |
74
|
|
|
|
|
|
|
'month' => $new_cat_year_month->month, |
75
|
|
|
|
|
|
|
'count' => $count, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
4
|
|
|
|
|
34
|
my $catalog_diff = Toolforge::MixNMatch::Object::Catalog->new( |
81
|
|
|
|
|
|
|
'count' => $new_cat->count, |
82
|
|
|
|
|
|
|
'type' => $new_cat->type, |
83
|
|
|
|
|
|
|
'users' => $users_ar, |
84
|
|
|
|
|
|
|
'year_months' => $year_months_ar, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
4
|
|
|
|
|
265
|
return $catalog_diff; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _compute_users_count { |
91
|
8
|
|
|
8
|
|
12
|
my $catalog = shift; |
92
|
|
|
|
|
|
|
|
93
|
8
|
|
|
|
|
10
|
my $count = 0; |
94
|
8
|
|
|
|
|
9
|
foreach my $user (@{$catalog->users}) { |
|
8
|
|
|
|
|
14
|
|
95
|
4
|
|
|
|
|
30
|
$count += $user->count; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
8
|
|
|
|
|
51
|
return $count; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _warn { |
102
|
1
|
|
|
1
|
|
12
|
my ($mess, $warn) = @_; |
103
|
|
|
|
|
|
|
|
104
|
1
|
50
|
|
|
|
3
|
if ($warn) { |
105
|
0
|
|
|
|
|
0
|
print "WARNING: $mess\n"; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
3
|
return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _which_catalog_is_new { |
112
|
4
|
|
|
4
|
|
8
|
my ($catalog1, $catalog2, $warn) = @_; |
113
|
|
|
|
|
|
|
|
114
|
4
|
|
|
|
|
6
|
my ($new_cat, $old_cat); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Different total counts. |
117
|
4
|
50
|
|
|
|
8
|
if ($catalog1->count > $catalog2->count) { |
|
|
50
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
$new_cat = $catalog1; |
119
|
0
|
|
|
|
|
0
|
$old_cat = $catalog2; |
120
|
|
|
|
|
|
|
} elsif ($catalog2->count > $catalog1->count) { |
121
|
0
|
|
|
|
|
0
|
$new_cat = $catalog2; |
122
|
0
|
|
|
|
|
0
|
$old_cat = $catalog1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Total counts are same. |
125
|
|
|
|
|
|
|
} else { |
126
|
4
|
|
|
|
|
57
|
my $users_count1 = _compute_users_count($catalog1); |
127
|
4
|
|
|
|
|
9
|
my $users_count2 = _compute_users_count($catalog2); |
128
|
4
|
100
|
|
|
|
12
|
if ($users_count1 > $users_count2) { |
|
|
100
|
|
|
|
|
|
129
|
1
|
|
|
|
|
1
|
$new_cat = $catalog1; |
130
|
1
|
|
|
|
|
2
|
$old_cat = $catalog2; |
131
|
|
|
|
|
|
|
} elsif ($users_count2 > $users_count1) { |
132
|
2
|
|
|
|
|
3
|
$new_cat = $catalog2; |
133
|
2
|
|
|
|
|
3
|
$old_cat = $catalog1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# All counts are same. |
136
|
|
|
|
|
|
|
} else { |
137
|
1
|
|
|
|
|
3
|
_warn('Catalogs are same in counts.', $warn); |
138
|
1
|
|
|
|
|
2
|
$new_cat = $catalog2; |
139
|
1
|
|
|
|
|
2
|
$old_cat = $catalog1; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
4
|
|
|
|
|
8
|
return ($new_cat, $old_cat); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |
149
|
|
|
|
|
|
|
|