cvs diff: Diffing release
Index: release/project_release.module
===================================================================
RCS file: /Users/wright/drupal/local_repo/contributions/modules/project/release/project_release.module,v
retrieving revision 1.155
diff -u -p -r1.155 project_release.module
--- release/project_release.module	22 Aug 2010 00:14:51 -0000	1.155
+++ release/project_release.module	16 Sep 2010 23:11:54 -0000
@@ -2177,3 +2177,14 @@ function project_release_views_default_v
   _project_release_views_default_views_alter($views);
 }
 
+/**
+ * Implementation of hook_ctools_plugin_directory().
+ */
+function project_release_ctools_plugin_directory($module, $plugin) {
+  if ($module == 'sampler') {
+    switch ($plugin) {
+      case 'metric':
+        return 'metrics';
+    }
+  }
+}
cvs diff: Diffing release/includes
cvs diff: Diffing release/metrics
Index: release/metrics/ProjectReleaseMetricReleaseCount.class.php
===================================================================
RCS file: release/metrics/ProjectReleaseMetricReleaseCount.class.php
diff -N release/metrics/ProjectReleaseMetricReleaseCount.class.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ release/metrics/ProjectReleaseMetricReleaseCount.class.php	17 Sep 2010 00:28:36 -0000
@@ -0,0 +1,63 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Class for release_count metric.
+ */
+
+class ProjectReleaseMetricReleaseCount extends SamplerMetric {
+
+  /**
+   * Method for computing results for a given sample.
+   *
+   * @return
+   *   An associative array key is nid, value is an array containing the total
+   *   number of releases on the given project.
+   */
+  public function computeSample() {
+    // Load options.
+    $options = $this->currentSample->options;
+
+    $where_pieces = array();
+    $args = array();
+
+    // Figure out the date range we're using for this sample.
+    if ($previous = $this->getPreviousSample()) {
+      $start = $previous->timestamp;
+      $end = $this->currentSample->timestamp;
+    }
+    else {
+      return FALSE;
+    }
+
+    $join_pieces[] = "prn.nid = nr.nid";
+    $join_pieces[] = "nr.created > %d";
+    $args = array_merge($args, array($start));
+    $join_pieces[] = "nr.created < %d";
+    $args = array_merge($args, array($end));
+    $left_join = "ON " . implode(' AND ', $join_pieces);
+
+    // Restrict to only the passed nids.
+    if (!empty($options['object_ids'])) {
+      $where_pieces[] = "prn.pid IN (". db_placeholders($options['object_ids']) .")";
+      $args = array_merge($args, $options['object_ids']);
+    }
+
+    if (empty($where_pieces)) {
+      $where = '';
+    }
+    else {
+      $where = ' WHERE ' . implode(' AND ', $where_pieces);
+    }
+
+    // Pull the total entries in the comment table, grouped by nid.
+    $nodes = db_query("SELECT np.nid, COUNT(nr.nid) AS count FROM {node} np LEFT JOIN {project_release_nodes} prn ON np.nid = prn.pid LEFT JOIN {node} nr $left_join$where GROUP BY np.nid", $args);
+    $values = array();
+    while ($node = db_fetch_object($nodes)) {
+      $values[$node->nid] = array($node->count);
+    }
+    $this->currentSample->values = $values;
+  }
+
+}
Index: release/metrics/release_count.inc
===================================================================
RCS file: release/metrics/release_count.inc
diff -N release/metrics/release_count.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ release/metrics/release_count.inc	16 Sep 2010 22:16:49 -0000
@@ -0,0 +1,27 @@
+<?php
+
+// $Id$
+
+/**
+ * @file
+ * Metric plugin for counting the number of releases per project.
+ *
+ * This metric accepts the following options:
+ * - startstamp:
+ *     The Unix timestamp to filter node created dates on, only pulling nodes
+ *     created after this stamp.
+ * - endstamp:
+ *     The Unix timestamp to filter node created dates on, only pulling nodes
+ *     created before this stamp.
+ * - object_ids:
+ *     An array of nids. If passed it will restrict the results to nodes in
+ *     this list.
+ */
+
+$plugin = array(
+  'title' => t('Releases per project'),
+  'description' => t("Counts how many releases were created for each node."),
+  'handler' => array(
+    'class' => 'ProjectReleaseMetricReleaseCount',
+  ),
+);
cvs diff: Diffing release/translations
cvs diff: Diffing release/views
cvs diff: Diffing release/views/default_views
Index: release/views/default_views/project_release_release_count.view.php
===================================================================
RCS file: release/views/default_views/project_release_release_count.view.php
diff -N release/views/default_views/project_release_release_count.view.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ release/views/default_views/project_release_release_count.view.php	17 Sep 2010 01:52:35 -0000
@@ -0,0 +1,152 @@
+<?php
+// $Id$
+
+if (module_exists('sampler')) {
+$view = new view;
+$view->name = 'project_release_release_count';
+$view->description = 'Sparkline showing count of releases over time for a given project';
+$view->tag = '';
+$view->view_php = '';
+$view->base_table = 'sampler_project_release_release_count';
+$view->is_cacheable = FALSE;
+$view->api_version = 2;
+$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+$handler = $view->new_display('default', 'Defaults', 'default');
+$handler->override_option('fields', array(
+  'timestamp' => array(
+    'label' => 'Timestamp',
+    'alter' => array(
+      'alter_text' => 0,
+      'text' => '',
+      'make_link' => 0,
+      'path' => '',
+      'link_class' => '',
+      'alt' => '',
+      'prefix' => '',
+      'suffix' => '',
+      'target' => '',
+      'help' => '',
+      'trim' => 0,
+      'max_length' => '',
+      'word_boundary' => 1,
+      'ellipsis' => 1,
+      'html' => 0,
+      'strip_tags' => 0,
+    ),
+    'empty' => '',
+    'hide_empty' => 0,
+    'empty_zero' => 0,
+    'date_format' => 'small',
+    'custom_date_format' => '',
+    'exclude' => 0,
+    'id' => 'timestamp',
+    'table' => 'sampler_project_release_release_count',
+    'field' => 'timestamp',
+    'relationship' => 'none',
+  ),
+  'value_0' => array(
+    'label' => 'Release count',
+    'alter' => array(
+      'alter_text' => 0,
+      'text' => '',
+      'make_link' => 0,
+      'path' => '',
+      'link_class' => '',
+      'alt' => '',
+      'prefix' => '',
+      'suffix' => '',
+      'target' => '',
+      'help' => '',
+      'trim' => 0,
+      'max_length' => '',
+      'word_boundary' => 1,
+      'ellipsis' => 1,
+      'html' => 0,
+      'strip_tags' => 0,
+    ),
+    'empty' => '',
+    'hide_empty' => 0,
+    'empty_zero' => 0,
+    'set_precision' => FALSE,
+    'precision' => 0,
+    'decimal' => '.',
+    'separator' => ',',
+    'prefix' => '',
+    'suffix' => '',
+    'exclude' => 0,
+    'id' => 'value_0',
+    'table' => 'sampler_project_release_release_count',
+    'field' => 'value_0',
+    'relationship' => 'none',
+  ),
+));
+$handler->override_option('sorts', array(
+  'timestamp' => array(
+    'order' => 'ASC',
+    'granularity' => 'second',
+    'id' => 'timestamp',
+    'table' => 'sampler_project_release_release_count',
+    'field' => 'timestamp',
+    'relationship' => 'none',
+  ),
+));
+$handler->override_option('arguments', array(
+  'object_id' => array(
+    'default_action' => 'ignore',
+    'style_plugin' => 'default_summary',
+    'style_options' => array(),
+    'wildcard' => 'all',
+    'wildcard_substitution' => 'All',
+    'title' => 'Release count for %1',
+    'breadcrumb' => '',
+    'default_argument_type' => 'node',
+    'default_argument' => '',
+    'validate_type' => 'project_nid',
+    'validate_fail' => 'not found',
+    'break_phrase' => 0,
+    'not' => 0,
+    'id' => 'object_id',
+    'table' => 'sampler_project_release_release_count',
+    'field' => 'object_id',
+    'relationship' => 'none',
+  ),
+));
+$handler->override_option('filters', array(
+  'timestamp' => array(
+    'operator' => 'between',
+    'value' => array(
+      'type' => 'offset',
+      'value' => '',
+      'min' => '-1 year',
+      'max' => 'today',
+    ),
+    'group' => '0',
+    'exposed' => FALSE,
+    'expose' => array(
+      'operator' => FALSE,
+      'label' => '',
+    ),
+    'id' => 'timestamp',
+    'table' => 'sampler_project_release_release_count',
+    'field' => 'timestamp',
+    'relationship' => 'none',
+  ),
+));
+$handler->override_option('access', array(
+  'type' => 'none',
+));
+$handler->override_option('cache', array(
+  'type' => 'none',
+));
+$handler->override_option('items_per_page', 0);
+$handler->override_option('style_plugin', 'views_sparkline');
+$handler->override_option('style_options', array(
+  'grouping' => '',
+  'x_field' => 'timestamp',
+  'y_field' => 'value_0',
+  'width' => '100',
+  'height' => '30',
+  'color' => '336699',
+  'display_last_point' => 0,
+));
+} // module_exists('sampler')
cvs diff: Diffing release/views/handlers
cvs diff: Diffing release/views/plugins
