diff options
| author | franck cuny <franck@lumberjaph.net> | 2011-06-13 16:33:23 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2011-06-13 16:33:23 +0200 |
| commit | 871336c030209b46ae6b124a702677363487f9a8 (patch) | |
| tree | 86f234d42c68b26a7aeb9cc373667127ad661e19 /lib/GitHub/Collector/Command/edges.pm | |
| parent | use template_toolkit and add infos about colors (diff) | |
| download | stargit-871336c030209b46ae6b124a702677363487f9a8.tar.gz | |
import github::collector
Signed-off-by: franck cuny <franck@lumberjaph.net>
Diffstat (limited to '')
| -rw-r--r-- | lib/GitHub/Collector/Command/edges.pm | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/GitHub/Collector/Command/edges.pm b/lib/GitHub/Collector/Command/edges.pm new file mode 100644 index 0000000..4ffe0c8 --- /dev/null +++ b/lib/GitHub/Collector/Command/edges.pm @@ -0,0 +1,67 @@ +package GitHub::Collector::Command::edges; + +use Moose; +use boolean; + +extends qw(MooseX::App::Cmd::Command); + +with qw( + GitHub::Collector::Role::Context + GitHub::Collector::Role::Logger + GitHub::Collector::Role::MongoDB +); + +sub execute { + my $self = shift; + + $self->log("start to merge contributions"); + + my $profiles = $self->db_profiles->find({edges_done => false}); + + while ( my $profile = $profiles->next ) { + next if $self->_is_done($profile->{login}); + $self->log("merge contributions for ".$profile->{login}); + $self->_contributions($profile->{login}); + } + + $self->log("done merging contributions"); +} + +sub _is_done { + my ($self, $login) = @_; + $self->db_edges->find({source => $login})->count; +} + +sub _contributions { + my ( $self, $login ) = @_; + + my $contributions = + $self->db_contributors->find( { contributor => $login } ); + + my $profiles = {}; + + while ( my $contrib = $contributions->next ) { + my $project = $self->db_repositories->find_one( + { uniq_name => $contrib->{project} } ); + + next if $project->{size} == 0; + my $total = + int( ( $contrib->{contributions} / $project->{size} ) * 100 ); + $total ||= 1; + $profiles->{ $contrib->{owner} } += $total; + } + + foreach my $pr ( keys %$profiles ) { + $self->db_edges->insert({ + source => $login, + target => $pr, + weight => $profiles->{$pr} + }); + } + $self->db_profiles->update( + { login => $login }, + { '$set' => { edges_done => true } }, + ); +} + +1; |
