| 1 | package GitInsight::Util; | ||||||||||||
| 2 | 2 | ▶ | use base 'Exporter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 2 | ▶ | use GitInsight::Obj -strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use Time::Local; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use PDL::LiteF; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use PDL::Lite; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use PDL::Stats; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use PDL::Ops; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | # EVENTS LABELS: | ||||||||||||
| 11 | 2 | ▶ | use constant NO_CONTRIBUTIONS => 0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 2 | ▶ | use constant FEW_CONTRIBUTIONS => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 2 | ▶ | use constant NORMAL_CONTRIBUTIONS => 2; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 2 | ▶ | use constant MORE_CONTRIBUTIONS => 3; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 2 | ▶ | use constant HIGH_CONTRIBUTIONS => 4; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | # LABEL ARRAY: | ||||||||||||
| 18 | 2 | our @CONTRIBS = ( | |||||||||||
| 19 | NO_CONTRIBUTIONS, FEW_CONTRIBUTIONS, | ||||||||||||
| 20 | NORMAL_CONTRIBUTIONS, MORE_CONTRIBUTIONS, | ||||||||||||
| 21 | HIGH_CONTRIBUTIONS | ||||||||||||
| 22 | ); | ||||||||||||
| 23 | |||||||||||||
| 24 | 2 | 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 | 2 | ▶ | use constant LABEL_DIM => 4; # D:5 0 to 4 | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | |||||||||||||
| 36 | 2 | our @EXPORT = qw(info error warning); | |||||||||||
| 37 | 2 | 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 | 2 | our @wday = qw/Mon Tue Wed Thu Fri Sat Sun/; | |||||||||||
| 43 | |||||||||||||
| 44 | # to compute | ||||||||||||
| 45 | 2 | 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 | 0 | ▶ | print "[info] - @_ \n"; | ||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | sub error { | ||||||||||||
| 58 | 0 | ▶ | print STDERR "[error] - @_ \n"; | ||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | sub warning { | ||||||||||||
| 62 | 0 | ▶ | print "[warning] - @_ \n"; | ||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | sub wday { # 2014-03-15 -> DayName ( Dayname element of @wday ) | ||||||||||||
| 66 | 0 | ▶ | my ( $mday, $mon, $year ) = reverse( split( /-/, shift ) ); | ||||||||||
|
Subroutine
wday: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 67 | return | ||||||||||||
| 68 | 0 | $wday[ ( localtime( timelocal( 0, 0, 0, $mday, $mon - 1, $year ) ) ) | |||||||||||
| 69 | [6] - 1 ]; | ||||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | sub gen_trans_mat { | ||||||||||||
| 73 | 0 | ▶ | my $no_day_stats = shift || 0; | ||||||||||
|
Subroutine
gen_trans_mat: not called CC=4 SCAR=30.0
Pod
documented
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 74 | 0 | ▶ | return zeroes scalar(@CONTRIBS), scalar(@CONTRIBS) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | if ($no_day_stats); | ||||||||||||
| 76 | 0 | my $h = {}; | |||||||||||
| 77 | 0 | $h->{$_} = zeroes scalar(@CONTRIBS), scalar(@CONTRIBS) for @wday; | |||||||||||
| 78 | 0 | return $h; | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | sub gen_m_mat { | ||||||||||||
| 82 | 0 | ▶ | my $label = shift; | ||||||||||
|
Subroutine
gen_m_mat: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 83 | 0 | my $h = zeroes( scalar(@CONTRIBS), 1 ); | |||||||||||
| 84 | 0 | $h->slice("$label,0") .= 1; | |||||||||||
| 85 | 0 | return $h; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | sub markov { | ||||||||||||
| 89 | 0 | ▶ | my $a = shift; | ||||||||||
|
Subroutine
markov: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 90 | 0 | my $b = shift; | |||||||||||
| 91 | 0 | ▶ | my $pow = shift || 1; | ||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 92 | 0 | ▶ | return ( $pow != 1 ) ? $a x (powering($b,$pow)) : $a x $b; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | sub powering($){ | ||||||||||||
| 96 | 0 | ▶ | my $a=shift->copy; | ||||||||||
|
Subroutine
powering: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 97 | 0 | my $pow=shift; | |||||||||||
| 98 | 0 | $a=$a x $a for 1..$pow-1; | |||||||||||
| 99 | 0 | return $a; | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | sub markov_list { | ||||||||||||
| 103 | 0 | ▶ | my $a = shift; | ||||||||||
|
Subroutine
markov_list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 104 | 0 | my $b = shift; | |||||||||||
| 105 | 0 | ▶ | my $pow = shift || 1; | ||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 106 | 0 | return [ list( &markov( $a, $b, $pow ) ) ]; | |||||||||||
| 107 | |||||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | sub markov_prob { | ||||||||||||
| 111 | 0 | ▶ | my $a = shift; | ||||||||||
|
Subroutine
markov_prob: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 112 | 0 | my $b = shift; | |||||||||||
| 113 | 0 | ▶ | my $pow = shift || 1; | ||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 114 | 0 | my $markov = &markov( $a, $b, $pow ); | |||||||||||
| 115 | 0 | my $index = maximum_ind($markov)->at(0); | |||||||||||
| 116 | 0 | return ( $index, $markov->slice("$index,0")->at( 0, 0 ) ); | |||||||||||
| 117 | } | ||||||||||||
| 118 | |||||||||||||
| 119 | sub label { | ||||||||||||
| 120 | 33 | ▶ | return NO_CONTRIBUTIONS if ( $_[0] == 0 ); | ||||||||||
|
Subroutine
label: called CC=5 SCAR=16.1
Pod
documented
Branch: 1 branch
| |||||||||||||
| 121 | return FEW_CONTRIBUTIONS | ||||||||||||
| 122 | 31 | ▶ | unless ( $_[0] > $LABEL_STEPS{ +FEW_CONTRIBUTIONS() } ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 123 | return NORMAL_CONTRIBUTIONS | ||||||||||||
| 124 | 24 | ▶ | unless ( $_[0] > $LABEL_STEPS{ +NORMAL_CONTRIBUTIONS() } ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 125 | return MORE_CONTRIBUTIONS | ||||||||||||
| 126 | 16 | ▶ | unless ( $_[0] > $LABEL_STEPS{ +MORE_CONTRIBUTIONS() } ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 127 | 10 | return HIGH_CONTRIBUTIONS; | |||||||||||
| 128 | } | ||||||||||||
| 129 | |||||||||||||
| 130 | sub label_step { | ||||||||||||
| 131 | 2 | ▶ | my @commits_count = @_; | ||||||||||
|
Subroutine
label_step: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 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 | 2 | $LABEL_STEPS{ +FEW_CONTRIBUTIONS() } | |||||||||||
| 136 | = $commits_count[ int( scalar @commits_count / 4 ) ]; | ||||||||||||
| 137 | 2 | $LABEL_STEPS{ +NORMAL_CONTRIBUTIONS() } | |||||||||||
| 138 | = $commits_count[ int( scalar @commits_count / 2 )]; | ||||||||||||
| 139 | $LABEL_STEPS{ +MORE_CONTRIBUTIONS() } | ||||||||||||
| 140 | 2 | = $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 | 1 | ▶ | my $x = zeroes(100)->xlinvals( 0, 1 ); # 0 padding from 0->1 of 100 steps | ||||||||||
|
Subroutine
prob: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 150 | 1 | 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 | 2 | 1; | |||||||||||
| 159 | |||||||||||||
| 160 | __END__ | ||||||||||||