Using Ohloh’s PHP API

Imagen eliminada.I was trying to find out the total contributions to our code, by contributor, between two dates, and thought I could do that with the PHP API from Ohloh, given the fact that it already provides nice analysis about the contributions in open-source projects. Apparently, there is no way, currently, to get the total list of contributors (mostly because it is divided per page on the Ohloh website), so I built an additional function to do that (see below), but then realized that it was impossible to actually get the total commits per user between two date with the contributor idea. Added code:
/**
 * Get all project contributors
 *
 * This function queries various pages of the API, so it might take a
 * while to return results for projects with many contributors
 *
 * @return object  simpleXMLObject
 * @access public
 */
 public function getAllContributors() {
 $contributors_on_page = 10;
 $current_page = 1;
 $contributors = array();
 do {
   $url = 'http://www.ohloh.net/projects/'.$this->projectID.'/contributors.xml?page='.$current_page.'&api_key='.
          $this->apiKey.'&v='.$this->version;
   $response = $this->_process($url);
   $contributors_on_page = 0;
   foreach ($response->contributor_fact as $id => $contributor) {
     $contributors[] = $contributor;
     $contributors_on_page ++;
   }
   $current_page++;
}
while ($contributors_on_page == 10);
return $contributors;
}
In the end it was far easier directly using Mercurial or Subversion on the command line:
$ hg log -d "2008-06-13 to 2009-06-01" |grep ^user > /tmp/users.txt
and then parse the file with a small PHP script that would use an array of names and count the number of items:
<?php
$commits = 0;
$users = array();
$file = file('/tmp/users.txt');
foreach ($file as $line) {
 $line = trim(substr($line,0,14));
 if (isset($users[$line])) {
   $users[$line]++;
 } else {
   $users[$line] = 1;
 }
 $commits++;
}
foreach ($users as $user) {
  echo $user.": ".$users[$user]." (".number_format(($users[$user]/$commits)*100,2).")n";
}
Then just execute the PHP script with the php command on the command-line, and you get a beautiful list of users with the number of commits for each one of them. You would still have to order them by number of commits and possibly remove a few duplicates, but that's just a minor piece of work now...