Skip to content

Instantly share code, notes, and snippets.

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

Embed
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'}\
.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;
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); }
}
@0racle

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) {
        $!py.call('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.