line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GitInsight::Util; |
2
|
2
|
|
|
2
|
|
41853
|
use base 'Exporter'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
246
|
|
3
|
2
|
|
|
2
|
|
898
|
use GitInsight::Obj -strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
1348
|
use Time::Local; |
|
2
|
|
|
|
|
3714
|
|
|
2
|
|
|
|
|
140
|
|
5
|
2
|
|
|
2
|
|
2535
|
use PDL::LiteF; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use PDL::Lite; |
7
|
|
|
|
|
|
|
use PDL::Stats; |
8
|
|
|
|
|
|
|
use PDL::Ops; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# EVENTS LABELS: |
11
|
|
|
|
|
|
|
use constant NO_CONTRIBUTIONS => 0; |
12
|
|
|
|
|
|
|
use constant FEW_CONTRIBUTIONS => 1; |
13
|
|
|
|
|
|
|
use constant NORMAL_CONTRIBUTIONS => 2; |
14
|
|
|
|
|
|
|
use constant MORE_CONTRIBUTIONS => 3; |
15
|
|
|
|
|
|
|
use constant HIGH_CONTRIBUTIONS => 4; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# LABEL ARRAY: |
18
|
|
|
|
|
|
|
our @CONTRIBS = ( |
19
|
|
|
|
|
|
|
NO_CONTRIBUTIONS, FEW_CONTRIBUTIONS, |
20
|
|
|
|
|
|
|
NORMAL_CONTRIBUTIONS, MORE_CONTRIBUTIONS, |
21
|
|
|
|
|
|
|
HIGH_CONTRIBUTIONS |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our %CA_COLOURS = ( |
25
|
|
|
|
|
|
|
+NO_CONTRIBUTIONS() => [ 238, 238, 238 ], |
26
|
|
|
|
|
|
|
+FEW_CONTRIBUTIONS() => [ 214, 230, 133 ], |
27
|
|
|
|
|
|
|
+NORMAL_CONTRIBUTIONS() => [ 140, 198, 101 ], |
28
|
|
|
|
|
|
|
+MORE_CONTRIBUTIONS() => [ 68, 163, 64 ], |
29
|
|
|
|
|
|
|
+HIGH_CONTRIBUTIONS() => [ 30, 104, 35 ] |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# LABEL DIMENSION, STARTING TO 0 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use constant LABEL_DIM => 4; # D:5 0 to 4 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our @EXPORT = qw(info error warning); |
37
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
38
|
|
|
|
|
|
|
qw(markov_prob markov gen_m_mat dim gen_trans_mat markov_list LABEL_DIM wday label prob label_step |
39
|
|
|
|
|
|
|
), |
40
|
|
|
|
|
|
|
@EXPORT |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
our @wday = qw/Mon Tue Wed Thu Fri Sat Sun/; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# to compute |
45
|
|
|
|
|
|
|
our %LABEL_STEPS = ( |
46
|
|
|
|
|
|
|
+NO_CONTRIBUTIONS() => 0, |
47
|
|
|
|
|
|
|
+FEW_CONTRIBUTIONS() => 0, |
48
|
|
|
|
|
|
|
+NORMAL_CONTRIBUTIONS() => 0, |
49
|
|
|
|
|
|
|
+MORE_CONTRIBUTIONS() => 0, |
50
|
|
|
|
|
|
|
+HIGH_CONTRIBUTIONS() => 0, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub info { |
54
|
|
|
|
|
|
|
print "[info] - @_ \n"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub error { |
58
|
|
|
|
|
|
|
print STDERR "[error] - @_ \n"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub warning { |
62
|
|
|
|
|
|
|
print "[warning] - @_ \n"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub wday { # 2014-03-15 -> DayName ( Dayname element of @wday ) |
66
|
|
|
|
|
|
|
my ( $mday, $mon, $year ) = reverse( split( /-/, shift ) ); |
67
|
|
|
|
|
|
|
return |
68
|
|
|
|
|
|
|
$wday[ ( localtime( timelocal( 0, 0, 0, $mday, $mon - 1, $year ) ) ) |
69
|
|
|
|
|
|
|
[6] - 1 ]; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub gen_trans_mat { |
73
|
|
|
|
|
|
|
my $no_day_stats = shift || 0; |
74
|
|
|
|
|
|
|
return zeroes scalar(@CONTRIBS), scalar(@CONTRIBS) |
75
|
|
|
|
|
|
|
if ($no_day_stats); |
76
|
|
|
|
|
|
|
my $h = {}; |
77
|
|
|
|
|
|
|
$h->{$_} = zeroes scalar(@CONTRIBS), scalar(@CONTRIBS) for @wday; |
78
|
|
|
|
|
|
|
return $h; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub gen_m_mat { |
82
|
|
|
|
|
|
|
my $label = shift; |
83
|
|
|
|
|
|
|
my $h = zeroes( scalar(@CONTRIBS), 1 ); |
84
|
|
|
|
|
|
|
$h->slice("$label,0") .= 1; |
85
|
|
|
|
|
|
|
return $h; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub markov { |
89
|
|
|
|
|
|
|
my $a = shift; |
90
|
|
|
|
|
|
|
my $b = shift; |
91
|
|
|
|
|
|
|
my $pow = shift || 1; |
92
|
|
|
|
|
|
|
return ( $pow != 1 ) ? $a x (powering($b,$pow)) : $a x $b; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub powering($){ |
96
|
|
|
|
|
|
|
my $a=shift->copy; |
97
|
|
|
|
|
|
|
my $pow=shift; |
98
|
|
|
|
|
|
|
$a=$a x $a for 1..$pow-1; |
99
|
|
|
|
|
|
|
return $a; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub markov_list { |
103
|
|
|
|
|
|
|
my $a = shift; |
104
|
|
|
|
|
|
|
my $b = shift; |
105
|
|
|
|
|
|
|
my $pow = shift || 1; |
106
|
|
|
|
|
|
|
return [ list( &markov( $a, $b, $pow ) ) ]; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub markov_prob { |
111
|
|
|
|
|
|
|
my $a = shift; |
112
|
|
|
|
|
|
|
my $b = shift; |
113
|
|
|
|
|
|
|
my $pow = shift || 1; |
114
|
|
|
|
|
|
|
my $markov = &markov( $a, $b, $pow ); |
115
|
|
|
|
|
|
|
my $index = maximum_ind($markov)->at(0); |
116
|
|
|
|
|
|
|
return ( $index, $markov->slice("$index,0")->at( 0, 0 ) ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub label { |
120
|
|
|
|
|
|
|
return NO_CONTRIBUTIONS if ( $_[0] == 0 ); |
121
|
|
|
|
|
|
|
return FEW_CONTRIBUTIONS |
122
|
|
|
|
|
|
|
unless ( $_[0] > $LABEL_STEPS{ +FEW_CONTRIBUTIONS() } ); |
123
|
|
|
|
|
|
|
return NORMAL_CONTRIBUTIONS |
124
|
|
|
|
|
|
|
unless ( $_[0] > $LABEL_STEPS{ +NORMAL_CONTRIBUTIONS() } ); |
125
|
|
|
|
|
|
|
return MORE_CONTRIBUTIONS |
126
|
|
|
|
|
|
|
unless ( $_[0] > $LABEL_STEPS{ +MORE_CONTRIBUTIONS() } ); |
127
|
|
|
|
|
|
|
return HIGH_CONTRIBUTIONS; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub label_step { |
131
|
|
|
|
|
|
|
my @commits_count = @_; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
#Each cell in the graph is shaded with one of 5 possible colors. These colors correspond to the quartiles of the normal distribution over the range [0, max(v)] where v is the sum of issues opened, pull requests proposed and commits authored per day. |
134
|
|
|
|
|
|
|
#XXX: next i would implement that in pdl |
135
|
|
|
|
|
|
|
$LABEL_STEPS{ +FEW_CONTRIBUTIONS() } |
136
|
|
|
|
|
|
|
= $commits_count[ int( scalar @commits_count / 4 ) ]; |
137
|
|
|
|
|
|
|
$LABEL_STEPS{ +NORMAL_CONTRIBUTIONS() } |
138
|
|
|
|
|
|
|
= $commits_count[ int( scalar @commits_count / 2 )]; |
139
|
|
|
|
|
|
|
$LABEL_STEPS{ +MORE_CONTRIBUTIONS() } |
140
|
|
|
|
|
|
|
= $LABEL_STEPS{ +HIGH_CONTRIBUTIONS() } |
141
|
|
|
|
|
|
|
= $commits_count[ 3 * int( scalar @commits_count / 4 ) ]; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# &info("FEW_CONTRIBUTIONS: ".$LABEL_STEPS{ +FEW_CONTRIBUTIONS() }); |
144
|
|
|
|
|
|
|
# &info("NORMAL_CONTRIBUTIONS: ".$LABEL_STEPS{ +NORMAL_CONTRIBUTIONS() }); |
145
|
|
|
|
|
|
|
# &info("MORE_CONTRIBUTIONS: ".$LABEL_STEPS{ +MORE_CONTRIBUTIONS() }); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub prob { |
149
|
|
|
|
|
|
|
my $x = zeroes(100)->xlinvals( 0, 1 ); # 0 padding from 0->1 of 100 steps |
150
|
|
|
|
|
|
|
return $x->index( #find the index within the matrix probs |
151
|
|
|
|
|
|
|
maximum_ind( #takes the maximum index of the funct |
152
|
|
|
|
|
|
|
pdf_beta( $x, ( 1 + $_[1] ), |
153
|
|
|
|
|
|
|
( 1 + $_[0] - $_[1] ) ) #y: happens vs not happens |
154
|
|
|
|
|
|
|
) |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
__END__ |