summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-01-30 16:35:44 +0100
committerfranck cuny <franck@lumberjaph.net>2010-01-30 16:35:44 +0100
commit1774a184943070ba9c892a30bc563d073209c97d (patch)
treec4d5582abf0839c242d40f92c63f73285a908088
parentdon't fetch info if profile exists (diff)
downloadgithub-explorer-1774a184943070ba9c892a30bc563d073209c97d.tar.gz
start to gen. gexf
-rw-r--r--crawl.pl7
-rw-r--r--lib/githubexplorer.pm10
-rw-r--r--lib/githubexplorer/Gexf.pm40
3 files changed, 52 insertions, 5 deletions
diff --git a/crawl.pl b/crawl.pl
index fa7ae4e..cbcfe6c 100644
--- a/crawl.pl
+++ b/crawl.pl
@@ -8,7 +8,8 @@ use Getopt::Long;
 GetOptions(
     'deploy'   => \my $deploy,
     'profiles' => \my $profiles,
-    'repo'     => \my $repo
+    'repo'     => \my $repo,
+    'graph' => \my $graph,
 );
 
 my $gh = githubexplorer->new(
@@ -21,5 +22,5 @@ my $gh = githubexplorer->new(
 );
 
 $gh->deploy if $deploy;
-$gh->harvest_profiles;
-
+$gh->harvest_profiles if $profiles;
+$gh->gen_graph if $graph;
diff --git a/lib/githubexplorer.pm b/lib/githubexplorer.pm
index fdd609a..321d6b1 100644
--- a/lib/githubexplorer.pm
+++ b/lib/githubexplorer.pm
@@ -4,6 +4,7 @@ use lib ('/home/franck/code/git/net-github/lib');
 use YAML::Syck;
 use Moose;
 use githubexplorer::Schema;
+use githubexplorer::Gexf;
 
 with qw/githubexplorer::Profile githubexplorer::Repositorie/;
 
@@ -40,7 +41,7 @@ sub harvest_profiles {
 }
 
 sub harvest_repo {
-    my ($self) = @_;
+    my $self = shift;
     $self->_connect unless $self->has_schema;
     my $profiles = $self->schema->resultset('Profiles')->search();
     while (my $p = $profiles->next) {
@@ -48,4 +49,11 @@ sub harvest_repo {
     }
 }
 
+sub gen_graph {
+    my $self = shift;
+    $self->_connect unless $self->has_schema;
+    my $graph = githubexplorer::Gexf->new(schema => $self->schema);
+    $graph->profiles;
+}
+
 1;
diff --git a/lib/githubexplorer/Gexf.pm b/lib/githubexplorer/Gexf.pm
index a82a741..0d814f0 100644
--- a/lib/githubexplorer/Gexf.pm
+++ b/lib/githubexplorer/Gexf.pm
@@ -3,6 +3,8 @@ package githubexplorer::Gexf;
 use Moose;
 use XML::Simple;
 
+has schema => (is => 'ro', isa => 'Object', required => 1);
+
 has graph => (
     is      => 'rw',
     isa     => 'HashRef',
@@ -16,7 +18,23 @@ has graph => (
                     attributes => {
                         class     => 'node',
                         type      => 'static',
-                        attribute => [ { id => 0, type => 'string' } ]
+                        attribute => [
+                            {
+                                id    => 0,
+                                type  => 'string',
+                                title => 'totalrepo'
+                            },
+                            {
+                                id    => 1,
+                                type  => 'string',
+                                title => 'accountlogin'
+                            },
+                            {
+                                id    => 2,
+                                type  => 'string',
+                                title => 'forkedrepo'
+                            },
+                        ]
                     }
                 }
             }
@@ -24,4 +42,24 @@ has graph => (
     }
 );
 
+sub profiles {
+    my $self     = shift;
+    my $profiles = $self->schema->resultset('Profiles')->search();
+
+    while ( my $profile = $profiles->next ) {
+        my $node = {
+            id        => $profile->name,
+            label     => $profile->name,
+            attvalues => [
+                { id => 0, value => 'total' },
+                { id => 1, $profile->name },
+                { id => 2, 'forked' }
+            ]
+        };
+        push @{ $self->graph->{gexf}->{graph}->{nodes}->{node} }, $node;
+    }
+    use YAML::Syck;
+    warn Dump $self->graph;
+}
+
 1;