Index: project.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/project.inc,v
retrieving revision 1.140
diff -u -r1.140 project.inc
--- project.inc	21 Feb 2009 22:24:07 -0000	1.140
+++ project.inc	8 Apr 2009 00:09:01 -0000
@@ -334,6 +334,65 @@
       );
     }
 
+    // Add a section for project CVS statistics if the sparklines module is
+    // available.
+    if (module_exists('cvs') && module_exists('sparkline')) {
+      // First, add a sparkline showing CVS message volume.
+      $weeks = 52;
+      for ($i = $weeks; $i > 0; $i--) {
+        $commits[] = db_result(db_query("SELECT COUNT(m.cid) AS count FROM {cvs_files} f INNER JOIN {cvs_messages} m ON f.cid = m.cid WHERE f.nid = %d AND m.created > %d AND m.created < %d", $node->nid, time() - 60 * 60 * 24 * 7 * ($i - 1), time() - 60 * 60 * 24 * 7 * $i));
+      }
+      $style = 'bar';
+      $tmp = sparkline_elements();
+      $sparkline = $tmp['sparkline_'. $style];
+      $sparkline['#height'] = 50;
+      $sparkline['#width'] = 150;
+      $sparkline['#min'] = 0;
+      $sparkline['#max'] = 0;
+      $sparkline['#data'] = $commits;
+      $sparkline['#do_not_flush'] = FALSE;
+      $sparkline['#filename'] = $node->nid . '-cvs-stats.png';
+      $node->content['activity']['cvs_messages'] = array(
+        '#value' => theme('sparkline', $sparkline),
+        '#weight' => 2,
+      );
+    }
+
+    // Add a sparkline showing the ratio of opened versus fixed issues in the
+    // last year.
+    if (module_exists('project_issue') && module_exists('sparkline')) {
+      $weeks = 52;
+      for ($i = $weeks; $i > 0; $i--) {
+        $start = time() - 60 * 60 * 24 * 7 * $i;
+        $end = time() - 60 * 60 * 24 * 7 * ($i -1);
+        $open = db_result(db_query('SELECT COUNT(1) FROM {project_issue_comments} comments INNER JOIN {project_issue_state} states ON comments.sid = states.sid WHERE states.default_query = 1 AND comments.pid = %d AND comments.timestamp > %d AND comments.timestamp < %d', $node->nid, $start, $end));
+        $closed = db_result(db_query('SELECT COUNT(1) FROM {project_issue_comments} comments INNER JOIN {project_issue_state} states ON comments.sid = states.sid WHERE states.default_query = 0 AND comments.pid = %d AND comments.timestamp > %d AND comments.timestamp < %d', $node->nid, $start, $end));
+        if ($open > 0 && $closed == 0) {
+          $ratio[] = 1;
+        }
+        elseif ($open == 0 && $closed > 0) {
+          $ratio[] = 0;
+        }
+        else {
+          $ratio[] = $open - $closed;
+        }
+      }
+      $style = 'line';
+      $tmp = sparkline_elements();
+      $sparkline = $tmp['sparkline_'. $style];
+      $sparkline['#height'] = 50;
+      $sparkline['#width'] = 150;
+      $sparkline['#min'] = 0;
+      $sparkline['#max'] = 0;
+      $sparkline['#data'] = $ratio;
+      $sparkline['#do_not_flush'] = FALSE;
+      $sparkline['#filename'] = $node->nid . '-issue-ratio-stats.png';
+      $node->content['activity']['issue_ratio'] = array(
+        '#value' => theme('sparkline', $sparkline),
+        '#weight' => 2,
+      );
+    }
+
     // Build a nested array of sections of links to display on project_project node pages.
     $all_links = array();
 
