Last active
April 22, 2017 09:49
-
-
Save awwaiid/ef3f0abcfa96e34977b4 to your computer and use it in GitHub Desktop.
pyplot wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
my $hashes = qqx{git log --since 2010-05-01 --merges --grep 'Merge pull request' --pretty=format:'%h %p %at\t%s' | grep 'Merge pull request '}; | |
$hashes ~~ s:g/\t.*?$$//; | |
my @triples = $hashes.split(/\n/).map: {[$_.split(/\s/)]}; | |
@triples .= grep(* == 4); | |
my %branches; | |
for @triples -> [$base, $left, $right, $date] { | |
my @commits = qqx{git log --first-parent $left..$right --pretty=format:'%h %at %ce'}\ | |
.split(/\n/).map:{[$_.split(/\s/)]}; | |
my $count = @commits.elems; | |
my $first_date = @commits[*-1][1]; | |
my $age = $date - $first_date; | |
# CSV export... | |
# say "$base, $left, $right, $date, $first_date, $count, $age" if $age < 60*60*24; | |
%branches<<$base>> = { | |
left => $left, | |
right => $right, | |
first_time => $first_date, | |
merge_time => $date, | |
commit_count => $count, | |
lifespan => $age, | |
}; | |
} | |
sub avg(@n) { ([+] @n) / @n.elems } | |
my $avg_lifetime = avg(%branches.values.map(*<lifespan>)); | |
say "Avg lifetime: {$avg_lifetime/60/60} hours"; | |
use lib $?FILE.IO.dirname; | |
use Matplotlib; | |
say "Count: {%branches.values.elems}"; | |
my $plt = Matplotlib.new; | |
$plt.plot([%branches.values.map(*<lifespan>/60/60/24).sort]); | |
$plt.ylabel('Lifespan (days)'); | |
$plt.xlabel('Commit'); | |
$plt.show; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Matplotlib { | |
use Inline::Python; | |
has $!py; | |
submethod BUILD() { | |
$!py = Inline::Python.new(); | |
$!py.run('import matplotlib.pyplot') | |
} | |
method FALLBACK($name, *@x) { $!py.call('matplotlib.pyplot', $name, @x); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the
FALLBACK
method should use aCapture
rather than a slurpy array.This ensures named arguments (kwargs) get passed correctly.