[ckan-changes] commit/ckanext-stats: dread: [all]: Moved things into ckanext/stats so they can be packaged. Added MANIFEST.in for packaging. Improved README.txt.

Bitbucket commits-noreply at bitbucket.org
Tue May 17 17:33:15 UTC 2011


1 new changeset in ckanext-stats:

http://bitbucket.org/okfn/ckanext-stats/changeset/551800e572df/
changeset:   r12:551800e572df
user:        dread
date:        2011-05-17 19:33:00
summary:     [all]: Moved things into ckanext/stats so they can be packaged. Added MANIFEST.in for packaging. Improved README.txt.
affected #:  16 files (9.9 KB)

--- a/README.txt	Tue May 17 15:27:13 2011 +0100
+++ b/README.txt	Tue May 17 18:33:00 2011 +0100
@@ -1,6 +1,23 @@
-A CKAN extension - http://ckan.org/wiki/Extensions.
+ckanext-stats
++++++++++++++
+
+Provides CKAN with web pages showing statistics about its use and metadata stored.
+
+This is a CKAN extension - http://ckan.org/wiki/Extensions.
+
+
+Enabling
+========
 
 Enable by adding to your ckan.plugins line in CKAN config::
 
   ckan.plugins = stats
 
+
+Tests
+=====
+
+To run tests written for this extension::
+
+  pip -E pyenv install nose
+  nosetests --ckan ckanext/stats/tests/
\ No newline at end of file


--- a/ckanext/stats/plugin.py	Tue May 17 15:27:13 2011 +0100
+++ b/ckanext/stats/plugin.py	Tue May 17 18:33:00 2011 +0100
@@ -22,9 +22,9 @@
 
     def update_config(self, config):
         here = os.path.dirname(__file__)
-        rootdir = os.path.dirname(os.path.dirname(here))
-        our_public_dir = os.path.join(rootdir, 'public')
-        template_dir = os.path.join(rootdir, 'templates')
+        our_public_dir = os.path.join(here, 'public')
+        print 'DIR', our_public_dir
+        template_dir = os.path.join(here, 'templates')
         config['extra_public_paths'] = ','.join([our_public_dir,
                 config.get('extra_public_paths', '')])
         config['extra_template_paths'] = ','.join([template_dir,


--- a/public/ckanext/stats/app.js	Tue May 17 15:27:13 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-jQuery(document).ready(function($) {
-	$('form').submit(function(e) {
-		e.preventDefault();
-		attribute = $('#form-attribute').val();
-		loadSolr(attribute);
-	})
-	// default! (also in html)
-	loadSolr('tags');
-
-	function loadSolr(attribute) {
-		var url = solrCoreUrl + '/select?indent=on&wt=json&facet=true&rows=0&indent=true&facet.mincount=1&facet.limit=30&q=*:*&facet.field=' + attribute;
-		function handleSolr(data) {
-			var results = [];
-			ourdata = data.facet_counts.facet_fields[attribute];
-			var newrow = {};
-			for (ii in ourdata) {
-				if (ii % 2 == 0) {
-					newrow.name = ourdata[ii];
-					if (!newrow.name) {
-						newrow.name = '[Not Specified]';
-					}
-				} else {
-					newrow.count = ourdata[ii];
-					results.push(newrow);
-					newrow = {};
-				}
-			}
-			display(results);
-		}
-
-		$.ajax({
-			url: url,
-			success: handleSolr,
-			dataType: 'jsonp',
-			jsonp: 'json.wrf'
-		});
-	}
-
-	function display(results) {
-		var list = $('#category-counts');
-		list.html('');
-		if (results.length == 0) {
-			return
-		}
-		var maximum = results[0]['count'];
-		for(ii in results) {
-			maximum = Math.max(maximum, results[ii]['count']);
-		}
-
-		$.each(results, function(idx, row) {
-			var newentry = $('<li></li>');
-			newentry.append($('<a href="#">' + row['name'] + '</a>'));
-			newentry.append($('<span class="count">' + row['count'] + '</a>'));
-			var percent = 100 * row['count'] / maximum;
-			newentry.append($('<span class="index" style="width: ' + percent + '%"></span>'));
-			list.append(newentry);
-		});
-	}
-});


--- a/public/ckanext/stats/demo.html	Tue May 17 15:27:13 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-<html>
-  <head>
-    <script type="text/javascript">
-      var solrCoreUrl = 'http://solr.okfn.org/solr/ckan';
-    </script>
-    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
-    <script type="text/javascript" src="app.js"></script>
-
-    <link type="text/css" rel="stylesheet" media="all" href="style.css" />
-  </head>
-  <body>
-    <h1>CKAN Dataset Leaderboard</h1>
-    <p>Choose a dataset attribute and find out which categories in that area have the most datasets. E.g. tags, groups, license, res_format, country.</p>
-    <form>
-      <label for="category">Choose area</label>
-      <input type="text" value="tags" name="attribute" id="form-attribute" />
-      <input type="submit" value="Dataset Counts »" name="submit" />
-    </form>
-
-    <div class="category-counts">
-      <ul class="chartlist" id="category-counts">
-      </ul>
-    </div>
-  </body>
-</html>


--- a/public/ckanext/stats/style.css	Tue May 17 15:27:13 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-div.category-counts {
-}
-
-div.category-counts-over-time {
-  clear: both;
-}
-
-/***************************
-  * CHART LISTS
-  **************************/
-
-.chartlist { 
-  float: left; 
-  border-top: 1px solid #EEE; 
-  width: 90%;
-  padding-left: 0;
-  margin-left: 0;
-}
-
-.chartlist li { 
-  position: relative;
-  display: block;  
-  border-bottom: 1px solid #EEE; 
-  _zoom: 1;
-}
-.chartlist li a { 
-  display: block; 
-  padding: 0.4em 4.5em 0.4em 0.5em;
-  position: relative; 
-  z-index: 2; 
-}
-.chartlist .count { 
-  display: block; 
-  position: absolute; 
-  top: 0; 
-  right: 0; 
-  margin: 0 0.3em; 
-  text-align: right; 
-  color: #999; 
-  font-weight: bold; 
-  font-size: 0.875em; 
-  line-height: 2em; 
-  z-index: 999;
-}
-.chartlist .index { 
-  display: block; 
-  position: absolute; 
-  top: 0; 
-  left: 0; 
-  height: 100%; 
-  background: #B8E4F5; 
-  text-indent: -9999px; 
-  overflow: hidden; 
-  line-height: 2em;
-}
-.chartlist li:hover { 
-  background: #EFEFEF; 
-}
-


--- a/templates/ckanext/stats/index.html	Tue May 17 15:27:13 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-<html xmlns:py="http://genshi.edgewall.org/"
-  xmlns:i18n="http://genshi.edgewall.org/i18n"
-  xmlns:xi="http://www.w3.org/2001/XInclude"
-  py:strip="">
-
-  <py:def function="page_title">Statistics</py:def>
-
-  <py:def function="optional_head">
-    <!--[if IE]><script language="javascript" type="text/javascript" src="http://assets.okfn.org/ext/flot/0.6/excanvas.min.js"></script><![endif]-->
-    <script type="text/javascript" src="http://assets.okfn.org/ext/flot/0.6/jquery.flot.min.js">//pointless jscript comment</script>
-  </py:def>
-
-  <div py:match="content">
-    <h1>Statistics</h1>
-  
-    <h3>Total number of packages</h3>
-    <div id="new_packages_graph" style="width:800px;height:300px"></div>
-    <script type="text/javascript">
-      var options = {
-          xaxis: {
-          mode: "time",
-          timeformat: "%y-%b"
-          }
-      };
-      var data = [
-        [ 
-        <py:for each="week_date, pkgs, num_packages, cumulative_num_packages in c.new_packages_by_week">
-          [ new Date(${week_date.replace('-', ',')}), ${cumulative_num_packages} ],
-        </py:for>
-        ]
-      ];
-      $.plot($("#new_packages_graph"), data, options);
-    </script>
-    
-    <h3>Revisions to packages per week</h3>
-    <div id="package_revisions_graph" style="width:800px;height:300px"></div>
-    <script type="text/javascript">
-      var options = {
-          xaxis: {
-          mode: "time",
-          timeformat: "%y-%b"
-          },
-          legend: {
-          position: "nw",
-          },
-          colors: ["#ffcc33", "#ff8844"]
-      };
-      var data = [
-        {label: "All package revisions",
-          lines: {
-            fill: 1,
-            },
-        data: [ 
-        <py:for each="week_date, revs, num_revisions, cumulative_num_revisions in c.package_revisions_by_week">
-          [ new Date(${week_date.replace('-', ',')}), ${num_revisions} ],
-        </py:for>
-        ]},
-        {label: "New packages",
-          lines: {
-            fill: 1,
-            },
-        data: [ 
-        <py:for each="week_date, pkgs, num_packages, cumulative_num_packages in c.new_packages_by_week">
-          [ new Date(${week_date.replace('-', ',')}), ${num_packages} ],
-        </py:for>
-        ]},
-      ];
-      $.plot($("#package_revisions_graph"), data, options);
-    </script>
-        
-    <h3>Top Rated Packages</h3>
-    <table>
-      <tr><th>Package</th><th>Average rating</th><th>Number of ratings</th></tr>
-      <tr py:for="package, rating, num_ratings in c.top_rated_packages">
-        <td>${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))}</td><td>${rating}</td><td>${num_ratings}</td>
-      </tr>
-    </table>
-
-    <h3>Most Edited Packages</h3>
-    <table>
-      <tr><th>Package</th><th>Number of edits</th></tr>
-      <tr py:for="package, edits in c.most_edited_packages">
-        <td>${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))}</td><td>${edits}</td>
-      </tr>
-    </table>
-
-    <h3>Largest Groups</h3>
-    <table>
-      <tr><th>Group</th><th>Number of packages</th></tr>
-      <tr py:for="group, num_packages in c.largest_groups">
-        <td>${h.link_to(group.title or group.name, h.url_for(controller='group', action='read', id=group.name))}</td><td>${num_packages}</td>
-      </tr>
-    </table>
-
-    <h3>Top Tags</h3>
-    <table>
-      <tr py:for="tag, num_packages in c.top_tags">
-        <td>${h.link_to(tag.name, h.url_for(controller='tag', action='read', id=tag.name))}</td><td>${num_packages}</td>
-      </tr>
-    </table>
-  
-    <h3>Users owning most packages</h3>
-    <table>
-      <tr py:for="user, num_packages in c.top_package_owners">
-        <td>${user.name}</td><td>${num_packages}</td>
-      </tr>
-    </table>
-
-    <p>
-      Page last updated:
-       <?python 
-          import datetime
-       ?>
-      ${datetime.datetime.now().strftime('%c')}
-    </p>
-  </div>
-
-  <xi:include href="../../layout.html" />
-</html>


--- a/templates/ckanext/stats/leaderboard.html	Tue May 17 15:27:13 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-<html xmlns:py="http://genshi.edgewall.org/"
-  xmlns:i18n="http://genshi.edgewall.org/i18n"
-  xmlns:xi="http://www.w3.org/2001/XInclude"
-  py:strip="">
-
-  <py:def function="page_title">Leaderboard - Stats</py:def>
-
-  <py:def function="optional_head">
-  <script type="text/javascript">
-    var solrCoreUrl = '${c.solr_core_url}';
-  </script>
-  <script type="text/javascript" src="${g.site_url}/ckanext/stats/app.js"></script>
-  <link type="text/css" rel="stylesheet" media="all" href="${g.site_url}/ckanext/stats/style.css" />
-  </py:def>
-
-  <div py:match="content">
-    <h2>Dataset Leaderboard</h2>
-    <p>Choose a dataset attribute and find out which categories in that area have the most datasets. E.g. tags, groups, license, res_format, country.</p>
-    <form>
-      <label for="category">Choose area</label>
-      <input type="text" value="tags" name="attribute" id="form-attribute" />
-      <input type="submit" value="Dataset Counts »" name="submit" />
-    </form>
-
-    <div class="category-counts">
-      <ul class="chartlist" id="category-counts">
-      </ul>
-    </div>
-  </div>
-
-  <xi:include href="../../layout.html" />
-</html>
-


--- a/tests/test_stats_plugin.py	Tue May 17 15:27:13 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-import os
-from paste.deploy import appconfig
-import paste.fixture
-from ckan.config.middleware import make_app
-from ckan.tests import conf_dir, url_for
-
-class TestStatsPlugin:
-
-    @classmethod
-    def setup_class(cls):
-        config = appconfig('config:test.ini', relative_to=conf_dir)
-        config.local_conf['ckan.plugins'] = 'stats'
-        wsgiapp = make_app(config.global_conf, **config.local_conf)
-        cls.app = paste.fixture.TestApp(wsgiapp)
-
-    def test_01_config(self):
-        from pylons import config
-        paths = config['extra_public_paths']
-        publicdir = os.path.join(os.path.dirname(os.path.dirname(__file__)),
-            'public')
-        assert paths.startswith(publicdir), (publicdir, paths)
-
-    def test_02_index(self):
-        url = url_for('stats')
-        out = self.app.get(url)
-        assert 'Total number of packages' in out, out
-        assert 'Most Edited Packages' in out, out
-
-    def test_03_leaderboard(self):
-        url = url_for('stats_action', action='leaderboard')
-        out = self.app.get(url)
-        assert 'Leaderboard' in out, out
-

Repository URL: https://bitbucket.org/okfn/ckanext-stats/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list