Skip to content

Instantly share code, notes, and snippets.

@awwaiid awwaiid/Matplotlib.pm6
Last active Apr 22, 2017

What would you like to do?
pyplot wrapper
#!/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'}\
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(*<lifespan>));
say "Avg lifetime: {$avg_lifetime/60/60} hours";
use lib $?FILE.IO.dirname;
use Matplotlib;
say "Count: {%branches.values.elems}";
my $plt =;
$plt.ylabel('Lifespan (days)');
class Matplotlib {
use Inline::Python;
has $!py;
submethod BUILD() {
$!py =;
$!'import matplotlib.pyplot')
method FALLBACK($name, *@x) { $!'matplotlib.pyplot', $name, @x); }

This comment has been minimized.

Copy link

0racle commented Feb 25, 2017

the FALLBACK method should use a Capture rather than a slurpy array.

    method FALLBACK($name, |c) {
        $!'matplotlib.pyplot', $name, |c);

This ensures named arguments (kwargs) get passed correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.